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

# LangGraph

> Use Ovra with LangGraph for stateful agent payment workflows.

[LangGraph](https://github.com/langchain-ai/langgraph) is graph-based agent orchestration with first-class checkpointing. Ovra's MCP tools plug in as native LangChain tools via `langchain-mcp-adapters` — your nodes can declare intents, mint credentials, and pay without leaving the graph.

<Note>
  Sandbox-only today. Use a `sk_sandbox_*` or `sk_test_*` key.
</Note>

## Install

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

## Setup

```python theme={}
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4.1")

async with MultiServerMCPClient({
    "ovra": {
        "url": "https://api.getovra.com/api/mcp",
        "transport": "streamable_http",
        "headers": {"Authorization": "Bearer sk_sandbox_..."},
    }
}) as client:
    tools = client.get_tools()  # all 19 ovra_* tools as LangChain Tool objects
    agent = create_react_agent(llm, tools)

    result = await agent.ainvoke({
        "messages": [
            {"role": "user", "content": "Buy a USB-C hub under EUR 30 on amazon.de"}
        ]
    })
```

## Human-in-the-loop with checkpointing

LangGraph's checkpointer pairs naturally with Ovra's `enforcementLevel: "approve"` policy mode — when an intent lands in `pending_approval`, the graph pauses; your approval surface flips it to `approved`; the graph resumes.

```python theme={}
from langgraph.checkpoint.memory import MemorySaver

agent = create_react_agent(llm, tools, checkpointer=MemorySaver())
```

For production, swap `MemorySaver` for `PostgresSaver` so the graph survives restarts.

## Multi-step example

```text theme={}
[node: research] -> find best USB-C hub under EUR 30 on amazon.de
[node: declare ] -> ovra_intent { action: "declare", ... }
[node: gate    ] -> wait for intent.status == "approved"
[node: pay     ] -> ovra_pay { action: "checkout", ... }
[node: verify  ] -> ovra_intent { action: "verify", actualAmountEuros, actualMerchant }
[node: report  ] -> ovra_outcome { action: "report", type: "purchase_completed", ... }
```

## Why LangGraph

* **Stateful workflows** — checkpointing for multi-step payment flows
* **Human-in-the-loop** built in — pairs with Ovra's `approve` enforcement level
* **Multi-agent** — purchaser, auditor, researcher in one graph
* **Streaming + async** for long-running flows

## Recommended tools to expose

| Tool               | Purpose                                  |
| ------------------ | ---------------------------------------- |
| `ovra_pay`         | Full flow in one call                    |
| `ovra_intent`      | Declare, verify, gate on approval status |
| `ovra_credential`  | Fine-grained lifecycle                   |
| `ovra_transaction` | History + memos                          |
| `ovra_policy`      | Read before declaring                    |
| `ovra_outcome`     | Report success for policy learning       |

## Next

<CardGroup cols={2}>
  <Card title="MCP overview" icon="info" href="/mcp/overview">
    Architecture and the full 19-tool list.
  </Card>

  <Card title="OpenAI Agents" icon="brain" href="/integrations/openai-agents">
    Hosted MCP integration.
  </Card>

  <Card title="CrewAI" icon="users" href="/integrations/crewai">
    Role-based multi-agent teams.
  </Card>
</CardGroup>
