# How to Build LangGraph FX Macro Agents with FXMacroData

Canonical: https://fxmacrodata.com/articles/build-langgraph-fx-macro-agents-with-fxmacrodata
Author: Robert Tidball
Published: 2026-07-10T07:51:54Z

Build a LangGraph FX macro agent with FXMacroData using stateful graph steps, REST tools, MCP adapters, persistence, and human approval gates.

[LangGraph](https://docs.langchain.com/oss/python/langgraph/overview) is a strong fit when an FX macro assistant needs state, repeatable steps, tool calls, review gates, and resumable execution rather than a one-shot chat answer. FXMacroData supplies the current macro evidence:[release calendars](/dashboard/release-calendar) , announcement history,[EUR/USD](/dashboard/EUR_USD) context,[COT](/dashboard/cot) positioning,[commodities](/dashboard/commodities) , and[FX session](/dashboard/fx-sessions) data.

**Quick answer:**use LangGraph when the workflow has more than one step: collect FXMacroData evidence, ask a model to draft a note, check stale-data and risk flags, then pause for human approval before any downstream action. Start with direct REST tools for deterministic control, and add MCP through LangChain's MCP adapter when you want LangGraph or a LangChain agent to discover FXMacroData tools from`https://mcp.fxmacrodata.com`.

This guide uses LangGraph as the process layer rather than treating any model as the data source. A model can summarize[US CPI](/api-data-docs/usd/inflation) ,[Non-Farm Payrolls](/api-data-docs/usd/non_farm_payrolls) , or a[Federal Reserve policy rate](/api-data-docs/usd/policy_rate) setup, but the graph should keep the evidence, assumptions, and approvals explicit.

**Fit**

**Use this for**

Macro briefing agents, release-risk workflows, research QA, portfolio-note drafting, and multi-step analyst assistants.

**Do not start with**

Autonomous order placement, hidden prompt chains, or agents that can change risk without a separate approval layer.

**Best first build**

A read-only graph that fetches FXMacroData rows, drafts an event briefing, and stops for human review.

## Why LangGraph Fits FX Macro Agents

LangGraph is designed for long-running, stateful agent workflows. The official documentation describes it as an orchestration runtime focused on durable execution, streaming, human-in-the-loop workflows, and persistence. That matters in FX because research agents need to remember what data was fetched, which releases were checked, which output the model drafted, and which approvals still remain.

The practical split is simple. FXMacroData should own the facts. LangGraph should own the workflow state. The model should write, compare, and reason over the evidence that the graph has already collected.

**LangGraph is useful when the agent needs memory between steps.**

**Evidence**
Fetch FXMacroData rows before the model writes.

**State**
Keep release dates, values, and checks visible.

**Review**
Pause before side effects or trade-prep handoff.

**Resume**
Continue after approval, correction, or data refresh.

## The Workflow Shape

A useful first graph has five nodes. Keep each node narrow so failures are obvious and easy to test.

Node What it does What it should output**Plan**Classify the currency, release type, and required data. Currency, indicators, pair context, and scope.**Fetch evidence**Call FXMacroData REST or MCP tools. Dated rows, announcement values, and source context.**Draft briefing**Ask the model to explain the setup using only fetched evidence. A structured note with assumptions and confidence limits.**Risk check**Reject stale data, missing source fields, or execution-like output. Risk flags and required fixes.**Human review**Pause for approval, edit, rejection, or a data refresh request. Approved note or feedback loop.

## Step 1: Define Agent State

LangGraph models workflows as graphs with state, nodes, and edges. In an FX macro workflow, the state should carry evidence and review status, not just chat messages.

```
from typing_extensions import TypedDict

class MacroAgentState(TypedDict):
    question: str
    currency: str
    pair: str
    evidence: dict
    draft: str
    risk_flags: list[str]
    approved: bool
```

This state shape keeps the evidence layer separate from the model's prose. That separation is what lets the graph reject an answer when the data is stale or missing.

## Step 2: Add FXMacroData REST Tools

Use REST when your application owns credentials, caching, logging, and validation. Start with a narrow wrapper around the production FXMacroData API.

```
curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/calendar/usd"
curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/announcements/usd/inflation"
curl -H "X-API-Key: YOUR_API_KEY" "https://api.fxmacrodata.com/v1/forex/eur/usd"
```

```
import requests

API_ROOT = "https://api.fxmacrodata.com/v1"

def fxmd_get(path: str, api_key: str) -> dict:
    response = requests.get(
        f"{API_ROOT}/{path}",
        headers={"X-API-Key": api_key},
        timeout=10,
    )
    response.raise_for_status()
    return response.json()
```

Keep this wrapper read-only. For a first LangGraph build, the tool should retrieve evidence, not place trades, send orders, or change risk settings.

## Step 3: Add FXMacroData MCP Tools

Use MCP when the graph or its surrounding LangChain agent should discover FXMacroData tools from a hosted server. LangChain's documentation describes`langchain-mcp-adapters`for loading tools from MCP servers.

```
from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient({
    "fxmacrodata": {
        "transport": "http",
        "url": "https://mcp.fxmacrodata.com",
        "headers": {"Authorization": "Bearer YOUR_API_KEY"},
    }
})

tools = await client.get_tools()
```

The REST and MCP paths are complementary. REST is the most controlled path for production application code. MCP is better when the agent runtime should discover a reusable set of FXMacroData tools through one server URL.

## Step 4: Build the LangGraph Flow

Once the state and tool functions exist, wire the nodes. The exact model call can vary by provider; the graph contract should stay stable. This minimal version takes the Plan step from the input state; add a`plan`node before`fetch_evidence`when the graph needs to route by currency or release type.

```
from langgraph.graph import StateGraph, START, END

builder = StateGraph(MacroAgentState)
builder.add_node("fetch_evidence", fetch_evidence)
builder.add_node("draft_briefing", draft_briefing)
builder.add_node("risk_check", risk_check)
builder.add_node("human_review", human_review)

builder.add_edge(START, "fetch_evidence")
builder.add_edge("fetch_evidence", "draft_briefing")
builder.add_edge("draft_briefing", "risk_check")
builder.add_edge("risk_check", "human_review")
builder.add_edge("human_review", END)

graph = builder.compile()
```

For real trading-desk use, make the graph output structured fields: evidence used, timestamp checked, data gaps, market implication, confidence, and next catalyst. That makes it easier to test the workflow and harder for a fluent model answer to hide missing data.

## Step 5: Add Review and Risk Gates

LangGraph's persistence and human-in-the-loop patterns are especially useful for finance. The graph can pause after a model proposes a note, save state, and resume after approval, edit, rejection, or a request for a fresh data check.

**Guardrail checklist**

- Require every briefing to name the FXMacroData tools or REST paths used.

- Reject output when announcement values, timestamps, or currency scope are missing.

- Separate research approval from broker execution or portfolio changes.

- Persist graph state so reviewers can see the evidence trail.

- Prefer read-only tools until the workflow has real monitoring and audit coverage.

A good first production pattern is "draft only." LangGraph produces the analyst note, the risk check adds flags, and a human approves the note before it is sent anywhere important.

## Sources

- [LangGraph overview](https://docs.langchain.com/oss/python/langgraph/overview)

- [LangGraph Graph API overview](https://docs.langchain.com/oss/python/langgraph/graph-api)

- [LangGraph persistence documentation](https://docs.langchain.com/oss/python/langgraph/persistence)

- [LangChain human-in-the-loop documentation](https://docs.langchain.com/oss/python/langchain/human-in-the-loop)

- [LangChain MCP documentation](https://docs.langchain.com/oss/python/langchain/mcp)

- [FXMacroData API documentation](https://fxmacrodata.com/documentation)

- [FXMacroData MCP server documentation](https://fxmacrodata.com/documentation/mcp-server)

- [FXMacroData production OpenAPI schema](https://api.fxmacrodata.com/openapi.json)

Source: FXMacroData
