Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cookbook/copilot-sdk/nodejs/recipe/ralph-loop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile } from "fs/promises";
import { CopilotClient, approveAll } from "@github/copilot-sdk";
import { CopilotClient } from "@github/copilot-sdk";

/**
* Ralph loop: autonomous AI task loop with fresh context per iteration.
Expand Down Expand Up @@ -43,8 +43,8 @@ async function ralphLoop(mode: Mode, maxIterations: number) {
model: "gpt-5.1-codex-mini",
// Pin the agent to the project directory
workingDirectory: process.cwd(),
// Auto-approve tool calls for unattended operation
onPermissionRequest: approveAll,
// Auto-approve all tool calls (including file writes) for unattended operation
onPermissionRequest: async () => ({ allow: true }),
});

// Log tool usage for visibility
Expand All @@ -57,7 +57,7 @@ async function ralphLoop(mode: Mode, maxIterations: number) {
try {
await session.sendAndWait({ prompt }, 600_000);
} finally {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recipe now uses session.disconnect() for cleanup, but the accompanying Ralph loop docs still show session.destroy() (e.g. cookbook/copilot-sdk/nodejs/ralph-loop.md) and most other Node.js recipes still call destroy(). To avoid confusing readers and keep examples consistent, either update the docs/examples to use disconnect() (and explain the deprecation) or stick with the recommended cleanup method across the cookbook.

Suggested change
} finally {
} finally {
// Prefer `disconnect()` for session cleanup; older examples may show
// `destroy()`, but `disconnect()` is the current recommended API.

Copilot uses AI. Check for mistakes.
await session.destroy();
await session.disconnect();
}

console.log(`\nIteration ${i} complete.`);
Expand Down
8 changes: 4 additions & 4 deletions cookbook/copilot-sdk/python/recipe/ralph_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import sys
from pathlib import Path

from copilot import CopilotClient, MessageOptions, SessionConfig, PermissionHandler
from copilot import CopilotClient, MessageOptions, SessionConfig


async def ralph_loop(mode: str = "build", max_iterations: int = 50):
Expand All @@ -47,8 +47,8 @@ async def ralph_loop(mode: str = "build", max_iterations: int = 50):
model="gpt-5.1-codex-mini",
# Pin the agent to the project directory
working_directory=str(Path.cwd()),
# Auto-approve tool calls for unattended operation
on_permission_request=PermissionHandler.approve_all,
# Auto-approve all tool calls (including file writes) for unattended operation
on_permission_request=lambda _req, _ctx: {"kind": "approved", "rules": []},
))

# Log tool usage for visibility
Expand All @@ -62,7 +62,7 @@ def log_tool_event(event):
MessageOptions(prompt=prompt), timeout=600
)
finally:
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recipe now uses await session.disconnect() for cleanup, but the cookbook Ralph loop doc and other Python recipes still show await session.destroy() as the standard cleanup. Please align the documentation/examples with the deprecation guidance (or clarify the difference between disconnect() and destroy()) so users don’t copy/paste a deprecated call or end up with inconsistent lifecycle behavior.

Suggested change
finally:
finally:
# Prefer `disconnect()` for session cleanup in examples/recipes.
# This keeps the lifecycle guidance aligned and avoids encouraging
# copy/paste use of the older `destroy()` cleanup pattern.

Copilot uses AI. Check for mistakes.
await session.destroy()
await session.disconnect()

print(f"\nIteration {i} complete.")

Expand Down
Loading