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

# Import from code

> Translate your existing Python agent code into Maitai Agents: any framework, or none at all

If you already have agents written in Python (using a framework like the OpenAI Agents SDK, LangChain/LangGraph, CrewAI, AutoGen, Pydantic AI, or LlamaIndex, or hand-written on top of a raw provider SDK) you don't need to redefine them in the Portal. Point the Maitai CLI at your source and it will translate the code into Maitai [Agents](/build/agents/create_agent), [capabilities](/build/agents/capabilities/llm_action), and [sub-agent](/build/agents/capabilities/subagent) links.

The CLI ships your code to Maitai, which uses Mojo (the same translator that powers Maitai's natural-language tooling) to read the code and produce a canonical agent manifest. The manifest is then applied to your account.

## Quickstart

```bash theme={null}
maitai agents import path/to/your_agent.py \
  --application-name "My App" --create-application
```

That single invocation:

1. Reads your source file (or every `.py` file in a directory).
2. Sends it to Maitai for translation.
3. Creates the agents, attaches their tools as capabilities, and wires sub-agent handoffs.
4. Prints a summary including the agent IDs you can open in the Portal.

## Single file vs. directory

You can point `agents import` at either a single `.py` file or a directory:

* **Single file**: best for small agents that live in one module. The entire file is shipped as the source.
* **Directory**: best for real projects (CrewAI crews, LangGraph subgraphs, custom agent packages). Every `.py` file in the directory tree is concatenated and shipped as one project, with file separators preserved so the translator knows which code came from which file.

For directory imports, everything in the directory is treated as part of the same agent project. If your repo has unrelated code mixed in, point at a smaller subdirectory containing just the agent files.

```bash theme={null}
maitai agents import path/to/your_crewai_project/ \
  --application-name "Marketing Crew" --create-application
```

The total concatenated source is capped at 1 MB. If you hit that, prune non-agent code (tests, generated fixtures, vendored deps) or point at a smaller subdirectory.

## What gets imported

Maitai's translator looks for any unit of code that combines (1) a system prompt or instruction string conditioning an LLM with (2) an LLM call. Tools and handoffs are optional. That means:

* **Framework agents** (`Agent(name=..., instructions=..., tools=[...])` and similar) are recognized directly.
* **Hand-written loops** that build a messages array with a system prompt and call `client.chat.completions.create(...)` are also recognized.
* **Tools / functions** that the agent invokes become [API Actions](/build/agents/capabilities/api_action) or [LLM Actions](/build/agents/capabilities/llm_action) depending on what they do.
* **Handoffs** between agents, whether explicit (`handoff()`), task-pipeline (CrewAI), or implicit (one agent invoking another as a tool), are translated into [sub-agent](/build/agents/capabilities/subagent) links.

When the translator recognizes a known framework (CrewAI, LangGraph, Pydantic AI, etc.) it tags the import with `Source recognized as: <framework>`. When it doesn't recognize anything, it still imports based on the code's structure, the translator errs on the side of importing rather than silently skipping.

## Flags

| Flag                       | Effect                                                                                                                                                                                                                        |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--application-name "..."` | Target application by name. Required unless `--application-id` is set.                                                                                                                                                        |
| `--application-id <id>`    | Target an existing application by ID.                                                                                                                                                                                         |
| `--create-application`     | Create the application if it doesn't exist (paired with `--application-name`).                                                                                                                                                |
| `--update`                 | If an agent with the same name already exists, update it in place instead of failing.                                                                                                                                         |
| `--prune`                  | With `--update`, also remove actions and handoffs that exist in Maitai but are absent from the source.                                                                                                                        |
| `--dry-run`                | Translate only, print the manifest, don't create anything.                                                                                                                                                                    |
| `--print-manifest`         | Print the translated manifest alongside the apply summary.                                                                                                                                                                    |
| `--diff`                   | Show what would change against the current Maitai state before applying.                                                                                                                                                      |
| `--diff-only`              | Like `--diff`, but stop before applying.                                                                                                                                                                                      |
| `--exclude '<glob>'`       | When importing a directory, skip `.py` files matching this glob (relative to the target dir). Repeatable. Well-known noise dirs (`.venv`, `__pycache__`, `node_modules`, `build`/`dist`, `*.egg-info`, …) are always skipped. |

## How long does it take?

The import runs asynchronously: when you press enter, the CLI submits a translation job and polls its status until completion. A typical single-file agent finishes in 20-60 seconds; large multi-file projects can take 1-3 minutes. The CLI shows a live status indicator that moves through `Queued…`, `Translating source…`, and `Applying manifest…` so you can see what's happening.

If the job fails (e.g. the translator couldn't find any agents in the source), the CLI surfaces a clear error message describing what went wrong.

## After import

Each imported agent shows up under your target application in the Portal. From there you can:

* Edit prompts and capabilities like any other Maitai agent.
* Publish a version and pin requests to it from your SDK calls.
* Wire additional [sub-agents](/build/agents/capabilities/subagent) or [supplied actions](/build/agents/capabilities/supplied_actions) that aren't in the original source.
* Configure routing and execution mode per agent.

Re-running `agents import` with `--update` is the easiest way to keep imported agents in sync with code changes; add `--prune` to also delete capabilities/handoffs that were removed from the source.

## Examples

The Maitai repo includes a small fixture suite covering different frameworks and project layouts. Each is suitable as a starting template:

* `examples/agent_import/raw_openai_loop.py`, hand-written agent on the raw OpenAI SDK
* `examples/agent_import/crewai_marketing_crew/`, multi-file CrewAI project (agents, tools, tasks, crew)
* `examples/agent_import/langgraph_support_pipeline/`, LangGraph with subgraphs in nested directories
* `examples/agent_import/pydantic_ai_support_bot.py`, Pydantic AI with typed `Agent[Deps, Output]`
* `examples/agent_import/custom_devops_assistant/`, no framework, hand-written base class across multiple files

## Next

* Inspect and edit your imported agents: [Create Agent](/build/agents/create_agent)
* Call them from your application: [Agent Call](/sdk/agent_call)
* Add Maitai-native capabilities: [LLM Action](/build/agents/capabilities/llm_action) · [API Action](/build/agents/capabilities/api_action)
