Skip to content

keba4ok/agent-attempt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Generation Agent

Autonomous code generation agent for DPAIA tasks using Claude AI and MCP tools.

Prerequisites

  • Python 3.8+
  • Anthropic API key
  • Generated LIB.py file (must be created separately)
  • MCP server URL

Setup

  1. Install dependencies:
pip install -r requirements.txt
  1. Create .env file:
cp .env.example .env
# Edit .env and add your ANTHROPIC_API_KEY

Running the Agent

python codegen_dpaia_agent.py \
  --lib-path /path/to/LIB.py \
  --mcp-url http://your-mcp-server-url

Options

  • --lib-path: Path to generated LIB.py file (required)
  • --mcp-url: MCP server URL (required)
  • --config: Path to JSON configuration file
  • --repo: Repository in format owner/repo
  • --issue-url: GitHub issue URL
  • --issue-title: Issue title
  • --issue-body: Issue description
  • --model: Claude model to use (default: claude-sonnet-4-20250514)
  • --max-tokens: Max tokens per request (default: 8000)
  • --execute: Execute generated code and iteratively improve based on errors
  • --max-iterations: Maximum number of iterations when using --execute (default: 12)
  • --output: Output file path for generated code (see Output Behavior below)
  • --instance-id: Custom instance ID (default: timestamp)
  • --log-level: Logging level: DEBUG, INFO, WARNING, ERROR (default: INFO)

Example

python codegen_dpaia_agent.py \
  --lib-path ./LIB.py \
  --mcp-url http://localhost:8080 \
  --repo owner/repo \
  --issue-title "Fix N+1 query problem" \
  --issue-body "Detect and resolve N+1 SELECT queries" \
  --execute \
  --max-iterations 10 \
  --output generated_code.py

Pipeline Description

The agent follows a simple iterative pipeline:

  1. Repository Setup: Clones the target repository into an isolated instance

  2. LIB Loading: Loads the generated LIB.py file containing MCP tool functions

  3. Code Generation (two modes):

    • Without execution: Generates thinking → generates code → saves results
    • With execution (--execute flag): Iteratively:
      • Generates thinking about the task
      • Generates code based on thinking and previous context
      • Executes the code
      • Analyzes execution results and errors
      • Uses error feedback to improve in the next iteration
      • Repeats until success or max iterations reached
  4. Output: Saves generated code, execution logs, and iteration history:

    • results_codegen/ - execution logs
    • generated_code_iterations/<instance_id>/iteration_01.py, iteration_02.py, etc. - individual iteration code files
    • --output file (if specified):
      • Without --execute: Saves the single iteration's code
      • With --execute: Saves all iterations concatenated into one file with headers (# === ITERATION 1 ===, # === ITERATION 2 ===, etc.)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors