Skip to content

Conversation

@tonybaloney
Copy link
Contributor

@tonybaloney tonybaloney commented Feb 11, 2026

Adds a new RALPH-loop recipe to the Copilot SDK cookbook with implementations in all four supported languages.

All examples use the gpt-5.1-codex-mini model.

Add iterative RALPH-loop (Read, Act, Log, Persist, Halt) pattern
implementations for all four supported languages:

- C#/.NET: ralph-loop.cs with documentation
- Node.js/TypeScript: ralph-loop.ts with documentation
- Python: ralph_loop.py with documentation (async API)
- Go: ralph-loop.go with documentation

Each recipe demonstrates:
- Self-referential iteration where AI reviews its own output
- Completion promise detection to halt the loop
- Max iteration safety limits
- File persistence between iterations

Verified against real Copilot SDK APIs:
- Python: fully verified end-to-end with github-copilot-sdk
- Node.js: fully verified end-to-end with @github/copilot-sdk
- C#: compiles and runs successfully with GitHub.Copilot.SDK
- Go: compiles against github.com/github/copilot-sdk/go v0.1.23
Copilot AI review requested due to automatic review settings February 11, 2026 13:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new “RALPH-loop” (Read, Act, Log, Persist, Halt) recipe to the Copilot SDK cookbook, providing documentation and runnable examples across .NET, Node.js/TypeScript, Python, and Go.

Changes:

  • Added new RALPH-loop runnable recipes for .NET, Node.js/TypeScript, Python, and Go.
  • Added new RALPH-loop documentation pages for each language.
  • Updated the cookbook index README to link the new recipe and updated the status text.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 23 comments.

Show a summary per file
File Description
cookbook/copilot-sdk/python/recipe/ralph_loop.py Adds a Python runnable RALPH-loop implementation (async-based).
cookbook/copilot-sdk/python/ralph-loop.md Adds Python documentation for the RALPH-loop recipe.
cookbook/copilot-sdk/nodejs/recipe/ralph-loop.ts Adds a Node.js/TS runnable RALPH-loop implementation.
cookbook/copilot-sdk/nodejs/ralph-loop.md Adds Node.js/TS documentation for the RALPH-loop recipe.
cookbook/copilot-sdk/go/recipe/ralph-loop.go Adds a Go runnable RALPH-loop implementation (context-based API).
cookbook/copilot-sdk/go/ralph-loop.md Adds Go documentation for the RALPH-loop recipe.
cookbook/copilot-sdk/dotnet/recipe/ralph-loop.cs Adds a .NET runnable RALPH-loop implementation.
cookbook/copilot-sdk/dotnet/ralph-loop.md Adds .NET documentation for the RALPH-loop recipe.
cookbook/copilot-sdk/README.md Adds RALPH-loop links under each language and updates cookbook status text.
Comments suppressed due to low confidence (1)

cookbook/copilot-sdk/dotnet/ralph-loop.md:72

  • The doc snippet repeats the same pattern of calling session.On(...) inside the loop. That will accumulate handlers across iterations and can cause TaskCompletionSource.SetResult to be invoked multiple times. Update the snippet to register the handler once (or unsubscribe per-iteration) and use TrySetResult to avoid exceptions from duplicate assistant message events.
                var done = new TaskCompletionSource<string>();
                session.On(evt =>
                {
                    if (evt is AssistantMessageEvent msg)
                    {
                        _lastResponse = msg.Data.Content;
                        done.SetResult(msg.Data.Content);
                    }
                });

@tonybaloney tonybaloney changed the title Add RALPH-loop recipe to Copilot SDK cookbook Add RALPH-loop recipes to Copilot SDK cookbook Feb 11, 2026
tonybaloney and others added 3 commits February 11, 2026 05:48
Removed mention of the RALPH-loop recipe from the README.
…l alignment

- Move session.On handler outside loop to prevent handler accumulation (C#)
- Use TrySetResult instead of SetResult to avoid duplicate-set exceptions (C#)
- Wrap CreateSessionAsync in broader try/finally so client always stops (C#)
- Fix PersistentRalphLoop to use maxIterations parameter instead of hardcoded 10
- Align model name to gpt-5.1-codex-mini across all doc snippets
- Fix completion promise DONE -> COMPLETE in usage snippet
- Replace Claude references with generic model terminology
@tonybaloney
Copy link
Contributor Author

@aaronpowell I Choo-choo-choose you to review my PR please.

Align all 4 language recipes (Node.js, Python, .NET, Go) with the
Ralph Playbook architecture:

- Simple version: minimal outer loop with fresh session per iteration
- Ideal version: planning/building modes, backpressure, git integration
- Fresh context isolation instead of in-session context accumulation
- Disk-based shared state via IMPLEMENTATION_PLAN.md
- Example prompt templates (PROMPT_plan.md, PROMPT_build.md, AGENTS.md)
- Updated cookbook README descriptions
Git operations (commit, push) belong in the prompt instructions, not
hardcoded in the loop orchestrator. The SDK recipes should focus purely
on the SDK API: create client, create session, send prompt, destroy.
- Add WorkingDirectory/working_directory to pin sessions to project root
- Add OnPermissionRequest/on_permission_request for unattended operation
- Add tool execution event logging for visibility
- Add See Also cross-links to error-handling and persisting-sessions
- Add best practices for WorkingDirectory and permission auto-approval
- Consistent across all 4 languages (Node.js, Python, .NET, Go)
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 9 comments.

Files not reviewed (1)
  • cookbook/copilot-sdk/nodejs/recipe/package-lock.json: Language not supported

Copy link
Contributor

@aaronpowell aaronpowell left a comment

Choose a reason for hiding this comment

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

There's a spelling error - either expand te as taskExecution (which I think it is) or add it to the ignore list

@aaronpowell aaronpowell merged commit ef3c1e5 into github:main Feb 11, 2026
2 checks passed
@tonybaloney tonybaloney deleted the cookbook/ralph-loop-recipe branch February 11, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants