CodeAct combines language models with code execution capabilities. CodeAct allows users to interact conversationally with an AI agent that can write and execute Python code to solve problems.
- Interactive Chat Interface - Natural language conversation with the agent
- Code Generation & Execution - Agent writes and runs Python code automatically
- Safe Sandbox Environment - Secure code execution with restricted builtins
- Tool Integration - Tools/function you want to provide to your agent
- Conversation Memory - Maintains context across multiple interactions
-
Set your Anthropic API key:
export ANTHROPIC_API_KEY="your-api-key"
-
Install dependencies:
pip install -r requirements.txt
-
Run the interactive agent:
python -m codeact.main
graph TD
A["π€ User Input"] --> B["π₯οΈ Main Interface<br/>(CLI Loop)"]
B --> C["π€ Agent<br/>(Conversation Manager)"]
C --> D["π§ Language Model<br/>(Claude API)"]
D --> E["π Generated Response"]
E --> F{"π Contains<br/>Python Code?"}
F -->|No| G["π¬ Return Response"]
F -->|Yes| H["βοΈ Code Extraction"]
H --> I["π Sandbox Execution"]
I --> J["π οΈ Tools<br/>(Calculator, etc.)"]
I --> K["π Execution Result"]
K --> C
G --> B
L["π System Prompt"] --> C
M["πΎ Conversation History"] --> C
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#fff3e0
style D fill:#e8f5e8
style I fill:#ffebee
style J fill:#fafafa
codeact/
βββ agent.py # Core agent with conversation logic
βββ main.py # Interactive CLI interface
βββ prompt.py # System prompts and instructions
βββ tools/ # Available tools for the agent
β βββ calculator.py # Math calculation functions
βββ utils/
βββ sandbox.py # Safe code execution environment