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

# LangGraph

> Load BeeOS MCP tools into LangGraph or call durable BeeOS OpenAPI tasks from graph nodes.

Use MCP when BeeOS should be a tool available to a model-driven graph. Use
OpenAPI when the graph itself owns task creation, retries, cancellation, and
state transitions.

## MCP tool in a graph

Install the LangChain MCP adapter:

```bash theme={null}
pip install langgraph langchain-mcp-adapters
```

Load the BeeOS agent as a remote Streamable HTTP server:

```python theme={null}
import os

from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient


async def build_agent():
    agent_id = os.environ["BEEOS_AGENT_ID"]
    client = MultiServerMCPClient(
        {
            "beeos": {
                "transport": "http",
                "url": f"https://mcp.beeos.ai/{agent_id}/mcp",
                "headers": {
                    "Authorization": f"Bearer {os.environ['BEEOS_API_KEY']}"
                },
            }
        }
    )
    tools = await client.get_tools()
    return create_agent(os.environ["LLM_MODEL"], tools)
```

Invoke it with an explicit policy in the graph state or system prompt. Do not
let a generic research graph silently inherit permission to send messages,
purchase items, or modify accounts on a real phone.

## Durable OpenAPI node

For long-running work, create a BeeOS task from a regular async graph node and
store `taskId` in graph state. A later node can poll or resume from a webhook.
This makes LangGraph checkpointing and BeeOS task durability reinforce each
other instead of holding one MCP request open.

```python theme={null}
import os
import httpx


async def create_beeos_task(state: dict) -> dict:
    headers = {"Authorization": f"Bearer {os.environ['BEEOS_API_KEY']}"}
    body = {
        "message": state["phone_task"],
        "idempotency_key": state["run_id"],
    }
    async with httpx.AsyncClient(base_url="https://openapi.beeos.ai") as client:
        response = await client.post(
            f"/api/v1/agents/{state['agent_id']}/tasks",
            headers=headers,
            json=body,
        )
        response.raise_for_status()
        return {"beeos_task": response.json()}
```

Confirm the current request schema in [Calling Agents](/guides/calling-agents)
before copying this node into production; generated BeeOS SDKs can replace the
raw HTTP call.

See the official [LangChain MCP adapter documentation](https://docs.langchain.com/oss/python/langchain/mcp)
and [Choosing a Protocol](/guides/choosing-a-protocol).
