# flyte.ai.agents.codemode

CodeModeAgent — LLM + Monty sandbox orchestration with automatic retry.

The agent auto-generates its system prompt from the tool registry so that
adding a new tool is the only step required. Tools can be flyte tasks,
``@flyte.trace`` functions, or plain Python callables.

Skills (additional context injected into the system prompt) can be literal
strings or ``pathlib.Path`` objects pointing to local files.
## Directory

### Classes

| Class | Description |
|-|-|
| [`CodeModeAgent`](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte.ai.agents.codemode/codemodeagent/page.md) | Generates code via an LLM, executes it in a Monty sandbox, and. |

### Methods

| Method | Description |
|-|-|
| [`generate_code()`](#generate_code) | Call the LLM to generate analysis code and extract it. |

### Variables

| Property | Type | Description |
|-|-|-|
| `codemode_progress_cb` | `ContextVar` |  |

## Methods

#### generate_code()

```python
def generate_code(
    call_llm: Callable[..., Any],
    model: str,
    system: str,
    messages: list[dict[str, str]],
) -> str
```
Call the LLM to generate analysis code and extract it.

| Parameter | Type | Description |
|-|-|-|
| `call_llm` | `Callable[..., Any]` | |
| `model` | `str` | |
| `system` | `str` | |
| `messages` | `list[dict[str, str]]` | |

## Subpages

- [CodeModeAgent](https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte.ai.agents.codemode/codemodeagent/page.md)
  - Parameters
  - Methods
  - run()
  - tool_descriptions()
  - uses_flyte_tools()

---
**Source**: https://github.com/unionai/unionai-docs/blob/main/content/api-reference/flyte-sdk/packages/flyte.ai.agents.codemode/_index.md
**HTML**: https://www.union.ai/docs/v2/union/api-reference/flyte-sdk/packages/flyte.ai.agents.codemode/
