feat: add CodeAct plugin for code-based agent interaction#2034
Closed
agent-of-mkmeral wants to merge 1 commit intostrands-agents:mainfrom
Closed
feat: add CodeAct plugin for code-based agent interaction#2034agent-of-mkmeral wants to merge 1 commit intostrands-agents:mainfrom
agent-of-mkmeral wants to merge 1 commit intostrands-agents:mainfrom
Conversation
Implements the CodeAct paradigm as a vended Plugin that replaces standard JSON tool calling with code-based orchestration. The model generates Python code that calls tools as async functions, and the plugin executes the code locally and feeds results back via AfterInvocationEvent.resume. Key features: - Plugin-based architecture using @hook decorators - BeforeInvocationEvent: injects CodeAct instructions + tool signatures - AfterInvocationEvent: parses code blocks, executes, sets resume - Persistent namespace across turns for state accumulation - Tool wrappers that route through agent.tool.X() (record_direct_tool_call=False) - final_answer() termination mechanism - AST-level code validation (blocks exec/eval/compile/dangerous dunders) - Import restrictions with configurable allowed modules - Max iteration safety limit (default: 10) - Error feedback loop for self-correction No sandbox dependency - executes locally in host process (Phase 1). Sandbox integration can be added later. 64 new tests, all passing. 1828 existing tests, 0 regressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the CodeAct paradigm as a vended Plugin (P2 from the sandbox design doc). Instead of JSON tool calling, the agent writes Python code that calls tools as async functions.
No sandbox dependency — runs locally in host process (Phase 1 per design doc). Sandbox integration can be layered on later.
What's in this PR
Source (2 new files, ~570 lines)
src/strands/vended_plugins/codeact/__init__.py— module exportssrc/strands/vended_plugins/codeact/codeact_plugin.py— full implementationTests (2 new files, ~740 lines)
tests/strands/vended_plugins/codeact/__init__.pytests/strands/vended_plugins/codeact/test_codeact_plugin.py— 64 testsHow it works
The plugin registers two hooks:
BeforeInvocationEvent— injects CodeAct system prompt + tool function signaturesAfterInvocationEvent— parses code blocks from response, executes locally, feeds results back viaevent.resumeKey features
@hookdecorators on aPluginsubclassagent.tool.X())exec(),eval(),compile(), dangerous__dunder__accessfinal_answer()— clean termination mechanismDesign decisions
vended_plugins/skills/,vended_plugins/steering/)@hookdecoratorsevent.resumefor looprecord_direct_tool_call=Falseasyncio.new_event_loop()__ns__update patternTest results
Related
cc @mkmeral