Building a research agent with LangGraph and MCP
Give an agent a paper search and an economic data source. Follow its decisions from the first lookup to the claim each source supports.
One question, two kinds of evidence
What happened to productivity when customer-support workers at one firm got an AI assistant? And how did U.S. nonfarm business output per hour change from 2022 Q4 to 2024 Q4? An economist might open a working paper in one tab and a statistical series in another. How would an agent decide what to open next?
The orchestration tutorial assigned work to a librarian, a writer and a referee. Here one agent decides which instrument to use. LangGraph carries the question and the evidence between decisions. This borrows two ideas from Anton Korinek’s examples: consult economic data, and return to research while a question remains open. Korinek, §§4.1–4.3
1 Give each source a job
Search NBER for the paper, then open its record. The authors measure how many customer issues a worker resolves per hour.
Find the BLS series in FRED, check its definition, and retrieve two quarterly index levels. Python computes the change between them.
2 Ask what a tool can do
The Model Context Protocol (MCP) gives an application a common way to discover and call tools. A server describes the operations it offers and the inputs each needs. A client in our notebook asks for that list and passes it to the model. The model can then ask for a particular operation.
- Discover
- The server advertises
get_paper_info. Its required input is a paper ID. - Call
- The agent has found
w31161in a title search and supplies that ID. - Read the reply
- The server returns the working-paper record, including its abstract. The agent can now report the study’s outcome.
In the live notebook, the community NBER-CLI server runs on the reader’s computer. The official FRED connector runs at the St. Louis Fed. Both use the same protocol. The percentage calculation is a small Python function the agent can call directly. MCP architecture
3 Give the agent a way back
Each LangGraph node does one job. The decision node reads the original question and the history of calls and replies. If it requests a tool, the tool node runs it, appends the result and hands control back. If the agent has enough information, it writes its answer. This conditional edge is the branching arrow in the diagram.
def next_step(state: ResearchState) -> Literal["use_tool", "finish"]:
if state["decision"]["tool"] == "finish":
return "finish"
return "use_tool"4 Watch the tools change with the question
Choose a question. Each row is a call executed by the notebook. Open a row to inspect the arguments and the reply that informed the agent’s next decision.
The examples replay model decisions through an in-process MCP teaching server. The paper record is a short paraphrase. The two index levels come directly from the BLS third-quarter 2026 table. Live FRED observations can change with revisions. BLS source table
5 Check the claim against the source
Which version did the agent read? The NBER working paper reports a 14% average gain for a sample of 5,179 workers. The published article reports 15% for 5,172 workers. Both numbers have a source. A citation that identifies the version tells the reader which number belongs in the answer. Working paper · Published article
How much of the national change came from AI? The firm study follows a rollout. The national index compares output per hour on two dates. Attributing some of that change to AI requires a credible estimate of what national productivity would have been without adoption. Calling both tools gives the agent enough evidence to explain that limit.
Build and run it
Open the companion notebook in Jupyter or VS Code. Install the two listed packages once, then use Run All to reproduce the three examples offline. Live mode uses a signed-in Codex CLI. The study run uses NBER-CLI. The national trend opens FRED’s sign-in and uses your free connector account. The website itself makes no model or data requests.