> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc-studio-tools-doc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent API

> API and MCP server for every agent, team, and workflow in your AgentOS.

Shipping an agent needs more than a `/run` endpoint. A live agent needs an API that can:

* Run agents in streaming mode and as background jobs
* Manage the sessions, memory, and learnings your agents accumulate
* Inspect runs, traces, and metrics
* Schedule recurring work
* Gate sensitive tool calls on human approval
* Resume paused runs once that approval comes back

AgentOS generates all of this for your agents, teams, and workflows automatically. Browse the live API at `/docs` or fetch the spec from `/openapi.json` on any AgentOS instance.

<video autoPlay loop muted playsInline className="w-full rounded-lg" src="https://mintlify.s3.us-west-1.amazonaws.com/phidatainc-studio-tools-doc/videos/agentos-api-scroll.mp4" />

## Interfaces

Agents need to be reachable over more than one interface. Define an agent once and AgentOS can expose it over any interface you opt into. REST and SSE are on by default; add an MCP server, WebSocket endpoints, A2A, or a Slack interface as needed. The agent code stays the same; only the interface layer changes.

## The surface area

| Group          | What you can do                                                                                                                                                |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Runs**       | Create, list, cancel, continue paused runs, resume disconnected streams. Stream over SSE or run as background jobs.                                            |
| **Sessions**   | Create, list, rename, update, delete. Pull every run in a session. Scoped per user.                                                                            |
| **Memory**     | Create, update, delete user memories. Search content, filter by topic, view per-user stats. Run optimization to compact token usage.                           |
| **Knowledge**  | Upload files, text, URLs, or content from S3, GCS, SharePoint, GitHub. Search via vector, keyword, or hybrid. List sources, files in a source, content status. |
| **Evals**      | Run accuracy, agent-as-judge, performance, and reliability evals. List, update, delete eval runs.                                                              |
| **Traces**     | List, search with a filter DSL, view full span trees, group by session. Inspect individual LLM calls and tool invocations.                                     |
| **Metrics**    | Daily aggregated runs, sessions, users, token usage, model breakdown. Refresh on demand.                                                                       |
| **Schedules**  | CRUD, enable, disable, trigger now. List historical runs of a schedule.                                                                                        |
| **Approvals**  | List pending approvals, resolve them, count by user.                                                                                                           |
| **Components** | Version your agents, teams, and workflows. Manage drafts, publish, roll back to a previous version.                                                            |
| **Database**   | Migrate one or all database schemas to a target version.                                                                                                       |

## How a request looks

Run endpoints accept `multipart/form-data` so a single call can carry text, files, and media. The response shape is the same whether it's an agent, a team, or a workflow:

```bash theme={null}
curl -X POST http://localhost:8000/agents/my-agent/runs \
  -F "message=Hello" \
  -F "user_id=alice" \
  -F "session_id=thread-42" \
  -F "stream=false"
```

```json theme={null}
{
  "run_id": "run_abc123",
  "session_id": "thread-42",
  "user_id": "alice",
  "agent_id": "my-agent",
  "status": "completed",
  "content": "Hi Alice!",
  "created_at": "2026-04-24T20:15:00Z"
}
```

Pass `stream=true` for Server-Sent Events. Pass `background=true` to run async and poll for completion.

## Adding your own routes

AgentOS is built on FastAPI. Register additional routes for webhooks, custom dashboards, integrations:

```python theme={null}
# `agent` is the same Agent instance you registered with AgentOS above
app = agent_os.get_app()

@app.post("/webhooks/stripe")
async def handle_stripe(event: dict):
    response = await agent.arun(
        f"Process Stripe event: {event}",
        user_id="system",
    )
    return {"ok": True, "agent_response": response.content}
```

The agent is a regular Python object. Call `agent.run(...)` or `await agent.arun(...)` from anywhere.

## Auth

When `authorization=True`, every endpoint except `/health` and `/openapi.json` requires a valid JWT in the `Authorization: Bearer ...` header. AgentOS validates the token, extracts claims, and applies RBAC scopes per request before any agent code runs.

See [Security & Auth](/features/security-and-auth) for the details.
