> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Agent • AI Agent SDK

> CodeAgent: Agent for code generation, execution, review, and refactoring.

# CodeAgent

> Defined in the [**Code Agent**](../modules/code_agent) module.

<Badge color="blue">AI Agent</Badge>

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

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8B0000', 'primaryTextColor': '#fff', 'primaryBorderColor': '#710101', 'lineColor': '#189AB4', 'secondaryColor': '#189AB4', 'tertiaryColor': '#fff' }}}%%

graph LR
    input["Input Data"] --> agent["Agent: CodeAgent"]
    agent --> output["Output Result"]
    style agent fill:#8B0000,color:#fff
    style input fill:#8B0000,color:#fff
    style output fill:#8B0000,color:#fff
```

## Constructor

<ParamField query="name" type="str" required={false} default="'CodeAgent'">
  No description available.
</ParamField>

<ParamField query="llm" type="Optional" required={false}>
  No description available.
</ParamField>

<ParamField query="code" type="Optional" required={false}>
  No description available.
</ParamField>

<ParamField query="instructions" type="Optional" required={false}>
  No description available.
</ParamField>

<ParamField query="verbose" type="bool" required={false} default="True">
  No description available.
</ParamField>

## Methods

<CardGroup cols={2}>
  <Card title="console()" icon="function" href="../functions/CodeAgent-console">
    Lazy load Rich console.
  </Card>

  <Card title="litellm()" icon="function" href="../functions/CodeAgent-litellm">
    Lazy load litellm.
  </Card>

  <Card title="generate()" icon="function" href="../functions/CodeAgent-generate">
    Generate code from natural language description.
  </Card>

  <Card title="generate_code()" icon="function" href="../functions/CodeAgent-generate_code">
    Alias for generate() method.
  </Card>

  <Card title="agenerate()" icon="function" href="../functions/CodeAgent-agenerate">
    Generate code asynchronously.
  </Card>

  <Card title="execute()" icon="function" href="../functions/CodeAgent-execute">
    Execute code in sandboxed environment.
  </Card>

  <Card title="execute_code()" icon="function" href="../functions/CodeAgent-execute_code">
    Alias for execute() method.
  </Card>

  <Card title="aexecute()" icon="function" href="../functions/CodeAgent-aexecute">
    Execute code asynchronously.
  </Card>

  <Card title="review()" icon="function" href="../functions/CodeAgent-review">
    Review code for issues, bugs, and improvements.
  </Card>

  <Card title="explain()" icon="function" href="../functions/CodeAgent-explain">
    Explain what code does in plain language.
  </Card>

  <Card title="refactor()" icon="function" href="../functions/CodeAgent-refactor">
    Refactor code to improve quality.
  </Card>

  <Card title="fix()" icon="function" href="../functions/CodeAgent-fix">
    Fix bugs in code.
  </Card>
</CardGroup>

## Usage

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/agent/code_agent.py#L33">
  `praisonaiagents/agent/code_agent.py` at line 33
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Agents Concept" icon="robot" href="/docs/concepts/agents" />

  <Card title="Single Agent Guide" icon="book-open" href="/docs/guides/single-agent" />

  <Card title="Multi-Agent Guide" icon="users" href="/docs/guides/multi-agent" />

  <Card title="Agent Configuration" icon="gear" href="/docs/configuration/agent-config" />

  <Card title="Auto Agents" icon="wand-magic-sparkles" href="/docs/features/autoagents" />
</CardGroup>
