Skip to content

Latest commit

 

History

History
72 lines (56 loc) · 2.02 KB

File metadata and controls

72 lines (56 loc) · 2.02 KB

CodeAct

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.

Components

  • 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

Quick Start

  1. Set your Anthropic API key:

    export ANTHROPIC_API_KEY="your-api-key"
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the interactive agent:

    python -m codeact.main

Architecture

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
Loading

Project Structure

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