-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add self-debugging loop to CodeExecutionAgent
#6306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add self-debugging loop to CodeExecutionAgent
#6306
Conversation
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py
Outdated
Show resolved
Hide resolved
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py
Outdated
Show resolved
Hide resolved
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py
Outdated
Show resolved
Hide resolved
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py
Outdated
Show resolved
Hide resolved
- Introduced `max_retries_on_error` (default: 0) to control the number of code generation and execution retries on failure. - Added `retry_attempt` field to `CodeGenerationEvent` and `CodeExecutionEvent` to track retry attempts. - Refactored `execute_code_block` to return `CodeResult`. Signed-off-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>
ekzhu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add unit tests for this, using ReplayChatCompletionClient, generate code with syntax error, and then generate code with correct syntax to simulate the debugging loop.
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py
Outdated
Show resolved
Hide resolved
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py
Outdated
Show resolved
Hide resolved
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py
Outdated
Show resolved
Hide resolved
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py
Outdated
Show resolved
Hide resolved
… `max_retries_on_error` > 0
Signed-off-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>
|
Hi @ekzhu, I’ve added a unit test for the self-debugging loop in |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6306 +/- ##
==========================================
+ Coverage 78.26% 78.31% +0.05%
==========================================
Files 217 217
Lines 15669 15684 +15
==========================================
+ Hits 12263 12283 +20
+ Misses 3406 3401 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py
Show resolved
Hide resolved
…e0424 * upstream/main: Remove `name` field from OpenAI Assistant Message (microsoft#6388) Introduce workbench (microsoft#6340) TEST/change gpt4, gpt4o serise to gpt4.1nano (microsoft#6375) update website version (microsoft#6364) Add self-debugging loop to `CodeExecutionAgent` (microsoft#6306) Fix: deserialize model_context in AssistantAgent and SocietyOfMindAgent and CodeExecutorAgent (microsoft#6337) Add azure ai agent (microsoft#6191) Avoid re-registering a message type already registered (microsoft#6354) Added support for exposing GPUs to docker code executor (microsoft#6339) fix: ollama fails when tools use optional args (microsoft#6343) Add an example using autogen-core and FastAPI to create streaming responses (microsoft#6335) FEAT: SelectorGroupChat could using stream inner select_prompt (microsoft#6286) Add experimental notice to canvas (microsoft#6349) DOC: add extentions - autogen-oaiapi and autogen-contextplus (microsoft#6338) fix: ensure serialized messages are passed to LLMStreamStartEvent (microsoft#6344) Generalize Continuous SystemMessage merging via model_info[“multiple_system_messages”] instead of `startswith("gemini-")` (microsoft#6345) Agentchat canvas (microsoft#6215) Signed-off-by: Peter Jausovec <peter.jausovec@solo.io>
Why are these changes needed?
This PR introduces a baseline self-debugging loop to the
CodeExecutionAgent.The loop automatically retries code generation and execution up to a configurable number of attempts (n) until the execution succeeds or the retry limit is reached.
This enables the agent to recover from transient failures (e.g., syntax errors, runtime errors) by using its own reasoning to iteratively improve generated code—laying the foundation for more robust autonomous behavior.
Related issue number
Closes #6207
Checks