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