Skip to main content

CodeAgent

Defined in the Code Agent module.
AI Agent Agent for code generation, execution, review, and refactoring. This agent provides capabilities for:
  • Generating code from natural language descriptions
  • Executing code in a sandboxed environment
  • Reviewing code for issues and improvements
  • Refactoring and fixing code
  • Explaining code functionality

Constructor

name
str
default:"'CodeAgent'"
No description available.
llm
Optional
No description available.
code
Optional
No description available.
instructions
Optional
No description available.
verbose
bool
default:"True"
No description available.

Methods

console()

Lazy load Rich console.

litellm()

Lazy load litellm.

generate()

Generate code from natural language description.

generate_code()

Alias for generate() method.

agenerate()

Generate code asynchronously.

execute()

Execute code in sandboxed environment.

execute_code()

Alias for execute() method.

aexecute()

Execute code asynchronously.

review()

Review code for issues, bugs, and improvements.

explain()

Explain what code does in plain language.

refactor()

Refactor code to improve quality.

fix()

Fix bugs in code.

Usage

from praisonaiagents import CodeAgent
    
    agent = CodeAgent(name="Coder")
    
    # Generate code
    code = agent.generate("Write a function to calculate fibonacci")
    
    # Execute code
    result = agent.execute("print('Hello, World!')")
    
    # Review code
    review = agent.review(code)

Source

View on GitHub

praisonaiagents/agent/code_agent.py at line 33

Agents Concept

Single Agent Guide

Multi-Agent Guide

Agent Configuration

Auto Agents