# FlyMy.AI Agents

> FlyMy.AI Agents — the agentic cloud. Lifecycle, MCP tools, freeze a successful run into a deterministic instruction, re-run with fresh variables.

Build and deploy autonomous AI agents on FlyMy.AI. Agents execute complex multi-step tasks in the cloud -- searching the web, processing files, calling APIs -- and deliver results without human intervention.

> **Tip: Agents, Models, and MCP connectors**
>
> Agents are one of three FlyMy.AI building blocks, and they tie the other two
> together: an agent calls **MCP connectors** (1,500+ tools - Slack, Notion,
> GitHub, Sentry, ...) and the **[Models API](https://docs.flymy.ai/quickstart.md)** as tools. Every
> connector also works **standalone** - call its actions directly with
> `client.tools.call(...)`, no agent required. See [Tools & MCP](https://docs.flymy.ai/agents/concepts/tools.md).

## Two Ways to Use Agents

### Build Agents for Yourself

Create agents that automate your workflows. Define a goal, equip the agent with tools, start a run, get results.

```python
from flymyai import AgentClient

client = AgentClient(api_key="fly-***")

# Register tools first - each returns a Tool object with an integer .id
web_search = client.tools.create(mcp_tool="tavily")
browser = client.tools.create(mcp_tool="browser")

agent = client.agents.create(
    name="Competitor Monitor",
    goal="Track competitor pricing changes and alert me about significant shifts.",
    tools=[web_search.id, browser.id]
)

run = client.runs.create(agent_id=agent.id)

result = client.runs.wait(run.id)
print(result.output)
```

### Publish Agents for Others

Once an agent is frozen and the `input_schema` / `output_schema` are stable, you can publish it to the [FlyMy.AI marketplace](https://app.flymy.ai). Buyers discover the agent, fill out the auto-generated form, and pay per run.

## Agent lifecycle

```mermaid
flowchart LR
    Create([Create agent<br/>name + goal + schemas]) --> Chat[Run / Chat<br/>agent plans, calls tools]
    Chat --> Happy{Output OK?}
    Happy -- No --> Chat
    Happy -- Yes --> Freeze[Freeze]
    Freeze --> Instr[(Compilation<br/>instruction_md)]
    Instr --> Run[Run instruction<br/>with fresh variables]
    Run --> Result([Structured output<br/>matches output_schema])
    Instr -. edit by hand .-> Instr
```

| Stage | What happens |
|---|---|
| **Create** | Set name, goal (with `{{ placeholders }}`), `input_schema` / `output_schema`, attach tools. |
| **Run / Chat** | Agent executes, calls tools, streams events; iterate via follow-up messages. |
| **Freeze** | Backend distills the chat into a Markdown plan (`instruction_md`) bounded by `input_description` / `output_description`. |
| **Run instruction** | Re-execute the frozen plan with fresh `variables` — fast, deterministic, no re-exploration. |

> **Tip: Two ways to run: execute, or freeze for repeated runs**
>
> - **Execute** - create the agent and run it. The right mode for one-off or interactive work: run it, iterate with follow-up messages, get a result.
> - **Freeze** (a.k.a. compile) - once a run is good, freeze it and re-run the frozen instruction with fresh variables. The right mode for anything recurring (every day, on a schedule, "for each", "at scale"). A frozen run skips re-exploration, so it spends far fewer tokens, runs faster, and stays deterministic.
>
> "Freeze" and "compile" are the same operation - the SDK surface is `client.compilations`. Not sure which mode you need? Ask: "Will this run once, or repeatedly?" When a pipeline will clearly run more than once, freeze it.

## Next Steps

- **[Quickstart](https://docs.flymy.ai/agents/quickstart.md)** -- build and run your first agent in 5 minutes
- **[Inputs, Outputs & Variables](https://docs.flymy.ai/agents/concepts/inputs.md)** -- contracts, schemas, freeze scope
- **[Runs & Freeze](https://docs.flymy.ai/agents/concepts/runs.md)** -- lifecycle, streaming, instruction re-runs
- **[Tools & MCP](https://docs.flymy.ai/agents/concepts/tools.md)** -- add tools and external services
