Back to home
AI concepts in economicsDownload notebook ↓

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 decision loop
ReaderAsk a question
AgentRead the evidence. Choose the next action.
Ready
AnswerExplain what the sources support.
↓   Name + inputs↑   Tool reply
Available toolsFind a paper · Read a series · Calculate a change

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

Evidence from a firmGenerative AI at Work

Search NBER for the paper, then open its record. The authors measure how many customer issues a worker resolves per hour.

Evidence from a national seriesNonfarm business productivity

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.

One exchange with the paper server
Discover
The server advertises get_paper_info. Its required input is a paper ID.
Call
The agent has found w31161 in 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.

From the notebook · routing the next decision
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.

Research question

What happened to productivity when customer-support workers at one firm got an AI assistant?

1. Paper search · Find the working paper

Tool and arguments

search_papers {
  "query": "Generative AI at Work"
}

Reply

[
  {
    "id": "w31161",
    "title": "Generative AI at Work"
  }
]
2. Paper record · Read the study estimate

Tool and arguments

get_paper_info {
  "paper_id": "w31161"
}

Reply

{
  "id": "w31161",
  "title": "Generative AI at Work",
  "version": "November 2023 working paper",
  "finding": "Following a staggered rollout of AI assistance, 5,179 customer-support agents resolved 14% more issues per hour on average when given access to the tool.",
  "url": "https://www.nber.org/papers/w31161"
}

Agent’s answer

At one firm, access to an AI assistant increased customer-support productivity by 14% on average, measured as issues resolved per hour, following a staggered rollout among 5,179 agents. This finding comes from the November 2023 working paper Generative AI at Work. [NBER]

How did U.S. nonfarm business output per hour change between 2022 Q4 and 2024 Q4?

1. Series search · Find nonfarm business productivity

Tool and arguments

search_series {
  "query": "U.S. nonfarm business output per hour quarterly index"
}

Reply

[
  {
    "id": "productivity",
    "title": "U.S. nonfarm business labor productivity"
  }
]
2. Series definition · Check the units and frequency

Tool and arguments

series_metadata {
  "series_id": "productivity"
}

Reply

{
  "id": "productivity",
  "title": "U.S. nonfarm business labor productivity",
  "measure": "Output per hour worked",
  "units": "Index, 2017 = 100",
  "frequency": "Quarterly",
  "seasonal_adjustment": "Seasonally adjusted",
  "vintage": "BLS third-quarter 2026 table",
  "url": "https://www.bls.gov/charts/productivity-and-costs/nonfarm-business-sector-indexes.htm"
}
3. Observations · Retrieve the quarterly levels

Tool and arguments

series_observations {
  "series_id": "productivity",
  "start": "2022-10-01",
  "end": "2024-10-01"
}

Reply

{
  "observations": [
    {
      "date": "2022-10-01",
      "value": 110.219
    },
    {
      "date": "2024-10-01",
      "value": 116.978
    }
  ],
  "url": "https://www.bls.gov/charts/productivity-and-costs/nonfarm-business-sector-indexes.htm"
}
4. Python calculation · Calculate the cumulative change

Tool and arguments

percent_change {
  "start_level": 110.219,
  "end_level": 116.978
}

Reply

{
  "percent_change": 6.132
}

Agent’s answer

U.S. nonfarm business output per hour rose from 110.219 in 2022 Q4 (2022-10-01) to 116.978 in 2024 Q4 (2024-10-01), a cumulative increase of 6.132%. These seasonally adjusted quarterly levels are indexes (2017 = 100) from the BLS third-quarter 2026 vintage. [BLS]

What happened to productivity when customer-support workers at one firm got an AI assistant? How did U.S. nonfarm business output per hour change between 2022 Q4 and 2024 Q4?

1. Paper search · Find the working paper

Tool and arguments

search_papers {
  "query": "Generative AI at Work"
}

Reply

[
  {
    "id": "w31161",
    "title": "Generative AI at Work"
  }
]
2. Paper record · Read the study estimate

Tool and arguments

get_paper_info {
  "paper_id": "w31161"
}

Reply

{
  "id": "w31161",
  "title": "Generative AI at Work",
  "version": "November 2023 working paper",
  "finding": "Following a staggered rollout of AI assistance, 5,179 customer-support agents resolved 14% more issues per hour on average when given access to the tool.",
  "url": "https://www.nber.org/papers/w31161"
}
3. Series search · Find nonfarm business productivity

Tool and arguments

search_series {
  "query": "nonfarm business output per hour quarterly index"
}

Reply

[
  {
    "id": "productivity",
    "title": "U.S. nonfarm business labor productivity"
  }
]
4. Series definition · Check the units and frequency

Tool and arguments

series_metadata {
  "series_id": "productivity"
}

Reply

{
  "id": "productivity",
  "title": "U.S. nonfarm business labor productivity",
  "measure": "Output per hour worked",
  "units": "Index, 2017 = 100",
  "frequency": "Quarterly",
  "seasonal_adjustment": "Seasonally adjusted",
  "vintage": "BLS third-quarter 2026 table",
  "url": "https://www.bls.gov/charts/productivity-and-costs/nonfarm-business-sector-indexes.htm"
}
5. Observations · Retrieve the quarterly levels

Tool and arguments

series_observations {
  "series_id": "productivity",
  "start": "2022-10-01",
  "end": "2024-10-01"
}

Reply

{
  "observations": [
    {
      "date": "2022-10-01",
      "value": 110.219
    },
    {
      "date": "2024-10-01",
      "value": 116.978
    }
  ],
  "url": "https://www.bls.gov/charts/productivity-and-costs/nonfarm-business-sector-indexes.htm"
}
6. Python calculation · Calculate the cumulative change

Tool and arguments

percent_change {
  "start_level": 110.219,
  "end_level": 116.978
}

Reply

{
  "percent_change": 6.132
}

Agent’s answer

Within one firm, AI access increased issues resolved per hour by 14% on average among 5,179 customer-support agents, according to the November 2023 working paper [NBER]. U.S. nonfarm business output per hour rose from 110.219 in 2022 Q4 (2022-10-01) to 116.978 in 2024 Q4 (2024-10-01), a cumulative 6.132% increase in the seasonally adjusted index (2017 = 100) [BLS]. The within-firm finding and national trend cannot establish AI’s aggregate effect because the firm’s results need not generalize and the national data do not isolate AI from other influences.

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.