---
title: MCPAgent
description: "MCPAgent API Documentation"
icon: "bot"
---

# MCPAgent API Reference

## astream

```python
def astream(
    query: str,
    max_steps: int | None = None,
    manage_connector: bool = True,
    external_history: list[BaseMessage] | None = None,
) -> AsyncIterator[dict]:
```

Asynchronous streaming interface for agent output. Yields incremental results, tool actions, and intermediate steps as they are generated by the agent.

**Example:**

```python
async for chunk in agent.astream("hello"):
    print(chunk["messages"], end="|", flush=True)
```

Each chunk is a dictionary containing keys such as `actions`, `steps`, `messages`, and (on the last chunk) `output`.
