AutoGPT
AutoGPT copied to clipboard
feat(agent): Persistent execute_code session
- Add notebook libs
- Add two tests for the execute_code part
- Add a Python kernel to each agent
- Change the execute_code command part to persist the state of the codes
Background
As we talked about in Persistent Python session / Jupyter Notebook integration , we need to change the execute_code command to save the state of each executed code. We attach a Python kernel and a notebook to each agent in initializing the agent part. After that now we can use that kernel to run Python code with that kernel and this kernel will save the session until the agent gets destroyed. The error part may be a little dirty and I think maybe we can find something better instead of kernel.execute. You can check tests for execute_code to see scenarios we can support right now.
Changes 🏗️
In the execute_code command instead of creating a temp file and running that file, we run the code directly by python kernel.
PR Quality Scorecard ✨
- [x] Have you used the PR description template?
+2 pts - [x] Is your pull request atomic, focusing on a single change?
+5 pts - [x] Have you linked the GitHub issue(s) that this PR addresses?
+5 pts - [x] Have you documented your changes clearly and comprehensively?
+5 pts - [x] Have you changed or added a feature?
-4 pts- [ ] Have you added/updated corresponding documentation?
+4 pts - [x] Have you added/updated corresponding integration tests?
+5 pts
- [ ] Have you added/updated corresponding documentation?
- [ ] Have you changed the behavior of AutoGPT?
-5 pts- [ ] Have you also run
agbenchmarkto verify that these changes do not regress performance?+10 pts
- [ ] Have you also run
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.
Deploy Preview for auto-gpt-docs canceled.
| Name | Link |
|---|---|
| Latest commit | 02897f408cc050706fd7621280802c771b468ad8 |
| Latest deploy log | https://app.netlify.com/sites/auto-gpt-docs/deploys/6638e4b505296d00086db219 |
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
@CodiumAI-Agent /review
PR Review
(Review updated until commit https://github.com/Significant-Gravitas/AutoGPT/commit/60cdfd71ac689d77957906127cd490d84667d961)
| ⏱️ Estimated effort to review [1-5] |
4, due to the complexity of integrating Jupyter kernels and the need to ensure that the implementation does not introduce any security vulnerabilities or logical errors in handling kernel sessions and outputs. |
| 🧪 Relevant tests |
Yes |
| 🔍 Possible issues |
Possible Bug: The error handling in |
|
Resource Management: The kernel sessions started with | |
| 🔒 Security concerns |
No |
Code feedback:
| relevant file | autogpts/autogpt/autogpt/agents/base.py |
| suggestion |
Consider managing the lifecycle of the Python kernel to prevent resource leaks. You should ensure that kernels are properly shut down when they are no longer needed or when the agent is destroyed. This can be done by implementing a cleanup method in the |
| relevant line | self.python_kernel = start_new_kernel( |
| relevant file | autogpts/autogpt/autogpt/commands/execute_code.py |
| suggestion |
Improve the exception handling in |
| relevant line | raise CommandExecutionError(*e.args) |
| relevant file | autogpts/autogpt/autogpt/commands/execute_code.py |
| suggestion |
To enhance code readability and maintainability, consider abstracting the logic that handles the output and errors from the kernel into separate methods. This can help in isolating the functionality and making the code easier to manage and test. [medium] |
| relevant line | agent.python_kernel.execute(code) |
| relevant file | autogpts/autogpt/autogpt/agents/base.py |
| suggestion |
Add error handling for the kernel start-up process in the |
| relevant line | self.python_kernel = start_new_kernel( |
✨ Review tool usage guide:
Overview:
The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.
The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
- When commenting, to edit configurations related to the review tool (
pr_reviewersection), use the following template:
/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
- With a configuration file, use the following template:
[pr_reviewer]
some_config1=...
some_config2=...
See the review usage page for a comprehensive guide on using this tool.
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.
@CodiumAI-Agent /review
Persistent review updated to latest commit https://github.com/Significant-Gravitas/AutoGPT/commit/60cdfd71ac689d77957906127cd490d84667d961
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 44.81%. Comparing base (
9bac6f4) to head (02897f4). Report is 345 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #7078 +/- ##
==========================================
+ Coverage 44.65% 44.81% +0.16%
==========================================
Files 133 133
Lines 6306 6321 +15
Branches 822 824 +2
==========================================
+ Hits 2816 2833 +17
+ Misses 3379 3377 -2
Partials 111 111
| Flag | Coverage Δ | |
|---|---|---|
| Linux | 44.73% <100.00%> (+0.16%) |
:arrow_up: |
| Windows | 42.72% <34.78%> (-0.01%) |
:arrow_down: |
| autogpt-agent | 44.78% <100.00%> (+0.16%) |
:arrow_up: |
| macOS | 43.94% <34.78%> (-0.01%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.
This looks ok to me overall and;
- Introduces new dependencies
- I'm not sure if this is going to work properly in container and on agent protocol server (please test) and also refer to feat(agent): Implement local temporary dir #7115
OK. I'll test it with agent protocol
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
@MKdir98 Do you intend to finish this PR off or shall we close it now
@MKdir98 Do you intend to finish this PR off or shall we close it now
I'm really sorry but I can't afford time to complete this one. Sorry for getting your time and energy.
@MKdir98 another excellent contribution that sadly got missed at the time. Likewise this suffers from the same issue - things have changed so much I don't see a path for this to be merged.
We'd love for you to still help out if your interested and can let you know areas that we are actively looking for contributors