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

# LangGraph

> Route a LangGraph agent's tool calls through Invoke over MCP: each call checked, recorded as your agent, and receipted.

Your LangGraph agent keeps its graph and its model. It gets its tools from your Invoke workspace over MCP, so every tool call goes through Invoke.

## Before you start

In the [console](https://console.invokehq.run/sign-in), open **API** and copy two things: the **MCP endpoint** and an **Agent key**. The key belongs to one agent, so every call your agent makes is recorded as that agent's, and it can't act as another.

```bash theme={null}
export INVOKE_MCP_URL=https://api.invokehq.run/v1/workspaces/ws_…/mcp
export INVOKE_API_KEY=inv_live_…
```

**1. Install**

```bash theme={null}
pip install langchain langchain-mcp-adapters langchain-openai
export OPENAI_API_KEY=sk-…
```

**2. Write the agent**

Save this as `agent.py`:

```python agent.py theme={null}
"""A LangGraph agent whose tool calls go through Invoke.

pip install langchain langchain-mcp-adapters langchain-openai
export INVOKE_API_KEY=inv_live_...      # your agent's own key
export INVOKE_MCP_URL=https://...       # from `invoke gateway url`
export OPENAI_API_KEY=sk-...
python agent.py
"""
import asyncio
import os
import sys

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

PROMPT = " ".join(sys.argv[1:]) or (
    "Remember that the staging deploy is frozen until Friday. "
    "Then recall your notes and tell me what you know."
)


async def main() -> None:
    invoke = MultiServerMCPClient({"invoke": {
        "url": os.environ["INVOKE_MCP_URL"],
        "transport": "streamable_http",
        "headers": {"Authorization": f"Bearer {os.environ['INVOKE_API_KEY']}"},
    }})
    tools = await invoke.get_tools()
    agent = create_agent(os.environ.get("MODEL", "openai:gpt-5.4-mini"), tools)

    result = await agent.ainvoke({"messages": [{"role": "user", "content": PROMPT}]})
    for message in result["messages"]:
        for call in getattr(message, "tool_calls", None) or []:
            print("→", call["name"], call["args"])
    print(result["messages"][-1].text)


asyncio.run(main())
```

`create_agent` from `langchain` builds a LangGraph agent. `langchain-mcp-adapters` turns your workspace's tools into LangChain tools.

**3. Run it**

```bash theme={null}
python agent.py
```

The agent uses Invoke's own memory tools, so it works on a new workspace with nothing connected. You'll see something like:

```text theme={null}
→ invoke_remember {'text': 'The staging deploy is frozen until Friday.'}
→ invoke_recall {}
I know that the staging deploy is frozen until Friday.
```

## Give it a real tool

In the console, open **Connectors** and connect a tool: GitHub, Slack, Linear, Notion or any MCP server. Its tools appear to your agent on the next run, with names a model API accepts (a GitHub connector's `create_issue` is listed as `github_create_issue`). Then ask for something that changes the world:

```bash theme={null}
python agent.py "Open an issue in acme/api titled 'Staging deploy frozen until Friday'"
```

Read back what happened with the [CLI](https://docs.invokehq.run/sdk/cli.md):

```bash theme={null}
invoke login --api-key "$INVOKE_API_KEY"
invoke gateway use ws_…        # the id in your MCP endpoint
invoke gateway receipts
```

Each write has a receipt that names your agent. If the agent claims a task first (`invoke_claim_task`), a retried write for that task is answered with its first receipt instead of running twice.

## What happened

* **Your agent acted as itself.** The key is its identity: Invoke records every call as that agent's.
* **Every call was checked before it ran:** the agent's permissions, your workspace's policies and its budget.
* **`invoke_remember` and `invoke_recall` are Invoke's own memory.** Notes an agent keeps across runs. Claiming a task again brings back its history and notes, and the workspace's other agents can read them.

## Other models

`MODEL` takes any LangChain model string. For Claude, `pip install langchain-anthropic` and set `MODEL=anthropic:claude-opus-5-5`.

## Next steps

* [CLI](https://docs.invokehq.run/sdk/cli.md): connect tools, then read receipts and the event log
* [Authentication](https://docs.invokehq.run/configuration/authentication.md): agent keys and account keys
* [Traces](https://docs.invokehq.run/concepts/traces.md): read a run back stage by stage


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.