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