diff --git a/cookbook/copilot-sdk/go/recipe/ralph-loop.go b/cookbook/copilot-sdk/go/recipe/ralph-loop.go index 72685927..35d862b7 100644 --- a/cookbook/copilot-sdk/go/recipe/ralph-loop.go +++ b/cookbook/copilot-sdk/go/recipe/ralph-loop.go @@ -39,7 +39,10 @@ func ralphLoop(ctx context.Context, mode string, maxIterations int) error { } defer client.Stop() - cwd, _ := os.Getwd() + cwd, err := os.Getwd() + if err != nil { + return fmt.Errorf("failed to get working directory: %w", err) + } fmt.Println(strings.Repeat("━", 40)) fmt.Printf("Mode: %s\n", mode) @@ -76,7 +79,9 @@ func ralphLoop(ctx context.Context, mode string, maxIterations int) error { _, err = session.SendAndWait(ctx, copilot.MessageOptions{ Prompt: string(prompt), }) - session.Destroy() + if destroyErr := session.Destroy(); destroyErr != nil { + log.Printf("failed to destroy session on iteration %d: %v", i, destroyErr) + } if err != nil { return fmt.Errorf("send failed on iteration %d: %w", i, err) } diff --git a/cookbook/copilot-sdk/nodejs/ralph-loop.md b/cookbook/copilot-sdk/nodejs/ralph-loop.md index c4074a1b..1abb692c 100644 --- a/cookbook/copilot-sdk/nodejs/ralph-loop.md +++ b/cookbook/copilot-sdk/nodejs/ralph-loop.md @@ -5,8 +5,8 @@ Build autonomous coding loops where an AI agent picks tasks, implements them, va > **Runnable example:** [recipe/ralph-loop.ts](recipe/ralph-loop.ts) > > ```bash -> cd recipe && npm install -> npx tsx ralph-loop.ts +> npm install +> npx tsx recipe/ralph-loop.ts > ``` ## What is a Ralph Loop? diff --git a/cookbook/copilot-sdk/python/ralph-loop.md b/cookbook/copilot-sdk/python/ralph-loop.md index 845354bd..82bfc7f5 100644 --- a/cookbook/copilot-sdk/python/ralph-loop.md +++ b/cookbook/copilot-sdk/python/ralph-loop.md @@ -4,10 +4,14 @@ Build autonomous coding loops where an AI agent picks tasks, implements them, va > **Runnable example:** [recipe/ralph_loop.py](recipe/ralph_loop.py) > +> From the repository root, install dependencies and run: +> > ```bash -> cd recipe && pip install -r requirements.txt -> python ralph_loop.py +> pip install -r cookbook/copilot-sdk/python/recipe/requirements.txt +> python cookbook/copilot-sdk/python/recipe/ralph_loop.py > ``` +> +> Make sure `PROMPT_build.md` and `PROMPT_plan.md` exist in your current working directory before running the loop. ## What is a Ralph Loop? diff --git a/cookbook/copilot-sdk/python/recipe/ralph_loop.py b/cookbook/copilot-sdk/python/recipe/ralph_loop.py index c182e3c7..918e8c66 100644 --- a/cookbook/copilot-sdk/python/recipe/ralph_loop.py +++ b/cookbook/copilot-sdk/python/recipe/ralph_loop.py @@ -55,11 +55,11 @@ async def ralph_loop(mode: str = "build", max_iterations: int = 50): )) # Log tool usage for visibility - session.on(lambda event: - print(f" ⚙ {event.data.tool_name}") - if event.type.value == "tool.execution_start" else None - ) + def log_tool_event(event): + if event.type.value == "tool.execution_start": + print(f" ⚙ {event.data.tool_name}") + session.on(log_tool_event) try: await session.send_and_wait( MessageOptions(prompt=prompt), timeout=600