mirror of
https://github.com/github/awesome-copilot.git
synced 2026-02-23 11:55:12 +00:00
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -87,4 +87,4 @@ go run <filename>.go
|
|||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
Cookbook structure is complete with 5 recipes across all 4 supported languages. Each recipe includes both markdown documentation and runnable examples. The RALPH-loop recipe demonstrates iterative self-referential AI loops for autonomous task completion.
|
Cookbook structure is complete with 6 recipes across all 4 supported languages. Each recipe includes both markdown documentation and runnable examples. The RALPH-loop recipe demonstrates iterative self-referential AI loops for autonomous task completion.
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ Implement self-referential feedback loops where an AI agent iteratively improves
|
|||||||
> **Runnable example:** [recipe/ralph-loop.cs](recipe/ralph-loop.cs)
|
> **Runnable example:** [recipe/ralph-loop.cs](recipe/ralph-loop.cs)
|
||||||
>
|
>
|
||||||
> ```bash
|
> ```bash
|
||||||
> cd dotnet/recipe
|
> cd dotnet
|
||||||
> dotnet run ralph-loop.cs
|
> dotnet run recipe/ralph-loop.cs
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
## What is RALPH-loop?
|
## What is RALPH-loop?
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ Implement self-referential feedback loops where an AI agent iteratively improves
|
|||||||
> **Runnable example:** [recipe/ralph-loop.go](recipe/ralph-loop.go)
|
> **Runnable example:** [recipe/ralph-loop.go](recipe/ralph-loop.go)
|
||||||
>
|
>
|
||||||
> ```bash
|
> ```bash
|
||||||
> cd go/recipe
|
> cd go
|
||||||
> go run ralph-loop.go
|
> go run recipe/ralph-loop.go
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
## What is RALPH-loop?
|
## What is RALPH-loop?
|
||||||
@@ -20,13 +20,13 @@ RALPH-loop is a development methodology for iterative AI-powered task completion
|
|||||||
|
|
||||||
## Example Scenario
|
## Example Scenario
|
||||||
|
|
||||||
You need to iteratively improve code until all tests pass. Instead of asking Claude to "write perfect code," you use RALPH-loop to:
|
You need to iteratively improve code until all tests pass. Instead of asking Copilot to "write perfect code," you use RALPH-loop to:
|
||||||
|
|
||||||
1. Send the initial prompt with clear success criteria
|
1. Send the initial prompt with clear success criteria
|
||||||
2. Claude writes code and tests
|
2. Copilot writes code and tests
|
||||||
3. Claude runs tests and sees failures
|
3. Copilot runs tests and sees failures
|
||||||
4. Loop automatically re-sends the prompt
|
4. Loop automatically re-sends the prompt
|
||||||
5. Claude reads test output and previous code, fixes issues
|
5. Copilot reads test output and previous code, fixes issues
|
||||||
6. Repeat until all tests pass and completion promise is output
|
6. Repeat until all tests pass and completion promise is output
|
||||||
|
|
||||||
## Basic Implementation
|
## Basic Implementation
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ Implement self-referential feedback loops where an AI agent iteratively improves
|
|||||||
> **Runnable example:** [recipe/ralph-loop.ts](recipe/ralph-loop.ts)
|
> **Runnable example:** [recipe/ralph-loop.ts](recipe/ralph-loop.ts)
|
||||||
>
|
>
|
||||||
> ```bash
|
> ```bash
|
||||||
> cd nodejs/recipe
|
> cd recipe && npm install
|
||||||
> npm install
|
|
||||||
> npx tsx ralph-loop.ts
|
> npx tsx ralph-loop.ts
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
@@ -21,13 +20,13 @@ RALPH-loop is a development methodology for iterative AI-powered task completion
|
|||||||
|
|
||||||
## Example Scenario
|
## Example Scenario
|
||||||
|
|
||||||
You need to iteratively improve code until all tests pass. Instead of asking Claude to "write perfect code," you use RALPH-loop to:
|
You need to iteratively improve code until all tests pass. Instead of asking Copilot to "write perfect code," you use RALPH-loop to:
|
||||||
|
|
||||||
1. Send the initial prompt with clear success criteria
|
1. Send the initial prompt with clear success criteria
|
||||||
2. Claude writes code and tests
|
2. Copilot writes code and tests
|
||||||
3. Claude runs tests and sees failures
|
3. Copilot runs tests and sees failures
|
||||||
4. Loop automatically re-sends the prompt
|
4. Loop automatically re-sends the prompt
|
||||||
5. Claude reads test output and previous code, fixes issues
|
5. Copilot reads test output and previous code, fixes issues
|
||||||
6. Repeat until all tests pass and completion promise is output
|
6. Repeat until all tests pass and completion promise is output
|
||||||
|
|
||||||
## Basic Implementation
|
## Basic Implementation
|
||||||
|
|||||||
@@ -22,47 +22,54 @@ class RalphLoop {
|
|||||||
* Run the RALPH-loop until completion promise is detected or max iterations reached.
|
* Run the RALPH-loop until completion promise is detected or max iterations reached.
|
||||||
*/
|
*/
|
||||||
async run(initialPrompt: string): Promise<string> {
|
async run(initialPrompt: string): Promise<string> {
|
||||||
|
let session: Awaited<ReturnType<CopilotClient["createSession"]>> | null = null;
|
||||||
|
|
||||||
await this.client.start();
|
await this.client.start();
|
||||||
const session = await this.client.createSession({
|
|
||||||
model: "gpt-5.1-codex-mini"
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (this.iteration < this.maxIterations) {
|
session = await this.client.createSession({
|
||||||
this.iteration++;
|
model: "gpt-5.1-codex-mini"
|
||||||
console.log(`\n=== Iteration ${this.iteration}/${this.maxIterations} ===`);
|
});
|
||||||
|
|
||||||
// Build the prompt for this iteration
|
try {
|
||||||
const currentPrompt = this.buildIterationPrompt(initialPrompt);
|
while (this.iteration < this.maxIterations) {
|
||||||
console.log(`Sending prompt (length: ${currentPrompt.length})...`);
|
this.iteration++;
|
||||||
|
console.log(`\n=== Iteration ${this.iteration}/${this.maxIterations} ===`);
|
||||||
|
|
||||||
const response = await session.sendAndWait({ prompt: currentPrompt }, 300_000);
|
// Build the prompt for this iteration
|
||||||
this.lastResponse = response?.data.content || "";
|
const currentPrompt = this.buildIterationPrompt(initialPrompt);
|
||||||
|
console.log(`Sending prompt (length: ${currentPrompt.length})...`);
|
||||||
|
|
||||||
// Display response summary
|
const response = await session.sendAndWait({ prompt: currentPrompt }, 300_000);
|
||||||
const summary = this.lastResponse.length > 200
|
this.lastResponse = response?.data.content || "";
|
||||||
? this.lastResponse.substring(0, 200) + "..."
|
|
||||||
: this.lastResponse;
|
|
||||||
console.log(`Response: ${summary}`);
|
|
||||||
|
|
||||||
// Check for completion promise
|
// Display response summary
|
||||||
if (this.lastResponse.includes(this.completionPromise)) {
|
const summary = this.lastResponse.length > 200
|
||||||
console.log(`\n✓ Success! Completion promise detected: '${this.completionPromise}'`);
|
? this.lastResponse.substring(0, 200) + "..."
|
||||||
return this.lastResponse;
|
: this.lastResponse;
|
||||||
|
console.log(`Response: ${summary}`);
|
||||||
|
|
||||||
|
// Check for completion promise
|
||||||
|
if (this.lastResponse.includes(this.completionPromise)) {
|
||||||
|
console.log(`\n✓ Success! Completion promise detected: '${this.completionPromise}'`);
|
||||||
|
return this.lastResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Iteration ${this.iteration} complete. Checking for next iteration...`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Iteration ${this.iteration} complete. Checking for next iteration...`);
|
// Max iterations reached without completion
|
||||||
|
throw new Error(
|
||||||
|
`Maximum iterations (${this.maxIterations}) reached without detecting completion promise: '${this.completionPromise}'`
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`\nError during RALPH-loop: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
if (session) {
|
||||||
|
await session.destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Max iterations reached without completion
|
|
||||||
throw new Error(
|
|
||||||
`Maximum iterations (${this.maxIterations}) reached without detecting completion promise: '${this.completionPromise}'`
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`\nError during RALPH-loop: ${error instanceof Error ? error.message : String(error)}`);
|
|
||||||
throw error;
|
|
||||||
} finally {
|
} finally {
|
||||||
await session.destroy();
|
|
||||||
await this.client.stop();
|
await this.client.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ Implement self-referential feedback loops where an AI agent iteratively improves
|
|||||||
> **Runnable example:** [recipe/ralph_loop.py](recipe/ralph_loop.py)
|
> **Runnable example:** [recipe/ralph_loop.py](recipe/ralph_loop.py)
|
||||||
>
|
>
|
||||||
> ```bash
|
> ```bash
|
||||||
> cd python/recipe
|
> cd recipe && pip install -r requirements.txt
|
||||||
> pip install -r requirements.txt
|
|
||||||
> python ralph_loop.py
|
> python ralph_loop.py
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
## What is RALPH-loop?
|
## What is RALPH-loop?
|
||||||
|
|
||||||
RALPH-loop is a development methodology for iterative AI-powered task completion. Named after the Ralph Wiggum technique, it embodies the philosophy of persistent iteration:
|
RALPH-loop is a development methodology for iterative AI-powered task completion. Named after the Ralph Wiggum technique, it embodies the philosophy of persistent iteration:
|
||||||
@@ -21,13 +19,13 @@ RALPH-loop is a development methodology for iterative AI-powered task completion
|
|||||||
|
|
||||||
## Example Scenario
|
## Example Scenario
|
||||||
|
|
||||||
You need to iteratively improve code until all tests pass. Instead of asking Claude to "write perfect code," you use RALPH-loop to:
|
You need to iteratively improve code until all tests pass. Instead of asking Copilot to "write perfect code," you use RALPH-loop to:
|
||||||
|
|
||||||
1. Send the initial prompt with clear success criteria
|
1. Send the initial prompt with clear success criteria
|
||||||
2. Claude writes code and tests
|
2. Copilot writes code and tests
|
||||||
3. Claude runs tests and sees failures
|
3. Copilot runs tests and sees failures
|
||||||
4. Loop automatically re-sends the prompt
|
4. Loop automatically re-sends the prompt
|
||||||
5. Claude reads test output and previous code, fixes issues
|
5. Copilot reads test output and previous code, fixes issues
|
||||||
6. Repeat until all tests pass and completion promise is output
|
6. Repeat until all tests pass and completion promise is output
|
||||||
|
|
||||||
## Basic Implementation
|
## Basic Implementation
|
||||||
|
|||||||
@@ -25,55 +25,59 @@ class RalphLoop:
|
|||||||
"""
|
"""
|
||||||
Run the RALPH-loop until completion promise is detected or max iterations reached.
|
Run the RALPH-loop until completion promise is detected or max iterations reached.
|
||||||
"""
|
"""
|
||||||
|
session = None
|
||||||
await self.client.start()
|
await self.client.start()
|
||||||
session = await self.client.create_session(
|
|
||||||
SessionConfig(model="gpt-5.1-codex-mini")
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while self.iteration < self.max_iterations:
|
session = await self.client.create_session(
|
||||||
self.iteration += 1
|
SessionConfig(model="gpt-5.1-codex-mini")
|
||||||
print(f"\n=== Iteration {self.iteration}/{self.max_iterations} ===")
|
|
||||||
|
|
||||||
current_prompt = self._build_iteration_prompt(initial_prompt)
|
|
||||||
print(f"Sending prompt (length: {len(current_prompt)})...")
|
|
||||||
|
|
||||||
result = await session.send_and_wait(
|
|
||||||
MessageOptions(prompt=current_prompt),
|
|
||||||
timeout=300,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.last_response = result.data.content if result else ""
|
|
||||||
|
|
||||||
# Display response summary
|
|
||||||
summary = (
|
|
||||||
self.last_response[:200] + "..."
|
|
||||||
if len(self.last_response) > 200
|
|
||||||
else self.last_response
|
|
||||||
)
|
|
||||||
print(f"Response: {summary}")
|
|
||||||
|
|
||||||
# Check for completion promise
|
|
||||||
if self.completion_promise in self.last_response:
|
|
||||||
print(
|
|
||||||
f"\n✓ Success! Completion promise detected: '{self.completion_promise}'"
|
|
||||||
)
|
|
||||||
return self.last_response
|
|
||||||
|
|
||||||
print(
|
|
||||||
f"Iteration {self.iteration} complete. Checking for next iteration..."
|
|
||||||
)
|
|
||||||
|
|
||||||
raise RuntimeError(
|
|
||||||
f"Maximum iterations ({self.max_iterations}) reached without "
|
|
||||||
f"detecting completion promise: '{self.completion_promise}'"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
try:
|
||||||
print(f"\nError during RALPH-loop: {e}")
|
while self.iteration < self.max_iterations:
|
||||||
raise
|
self.iteration += 1
|
||||||
|
print(f"\n=== Iteration {self.iteration}/{self.max_iterations} ===")
|
||||||
|
|
||||||
|
current_prompt = self._build_iteration_prompt(initial_prompt)
|
||||||
|
print(f"Sending prompt (length: {len(current_prompt)})...")
|
||||||
|
|
||||||
|
result = await session.send_and_wait(
|
||||||
|
MessageOptions(prompt=current_prompt),
|
||||||
|
timeout=300,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.last_response = result.data.content if result else ""
|
||||||
|
|
||||||
|
# Display response summary
|
||||||
|
summary = (
|
||||||
|
self.last_response[:200] + "..."
|
||||||
|
if len(self.last_response) > 200
|
||||||
|
else self.last_response
|
||||||
|
)
|
||||||
|
print(f"Response: {summary}")
|
||||||
|
|
||||||
|
# Check for completion promise
|
||||||
|
if self.completion_promise in self.last_response:
|
||||||
|
print(
|
||||||
|
f"\n✓ Success! Completion promise detected: '{self.completion_promise}'"
|
||||||
|
)
|
||||||
|
return self.last_response
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"Iteration {self.iteration} complete. Checking for next iteration..."
|
||||||
|
)
|
||||||
|
|
||||||
|
raise RuntimeError(
|
||||||
|
f"Maximum iterations ({self.max_iterations}) reached without "
|
||||||
|
f"detecting completion promise: '{self.completion_promise}'"
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\nError during RALPH-loop: {e}")
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
if session is not None:
|
||||||
|
await session.destroy()
|
||||||
finally:
|
finally:
|
||||||
await session.destroy()
|
|
||||||
await self.client.stop()
|
await self.client.stop()
|
||||||
|
|
||||||
def _build_iteration_prompt(self, initial_prompt):
|
def _build_iteration_prompt(self, initial_prompt):
|
||||||
|
|||||||
Reference in New Issue
Block a user