FR Demo

Agent

A LangGraph agent that answers questions about spending, and proves every figure it says.

Overview

cmp Where each technology is usedA question goes through LangGraph, which calls the language model through LangChain and tools through MCP. Only the receipt search uses RAG.Ask pageLangGraph: order of the stepsclassifyplancheck numbersanswerrun toolsLanguage model(LangChain)MCP server(LangChain tools)Totals and prices(SQL)RAGkeywordsmeaningmergereranksearch_documentscmp Where each technology is used
cmp LangGraph, RAGA question goes through LangGraph, which calls the language model through LangChain and tools through MCP. Only the receipt search uses RAG.Ask pageLanguage model(LangChain)LangGraph: order of the stepsclassifyplanrun toolscheck numbersanswerMCP server(LangChain tools)Totals and prices(SQL)search_documentsRAGkeywordsmeaningmergererankcmp LangGraph, RAG

One question

The real graph, with a scripted language model. Choose how the model behaves.

One question through the agent graphThree scripted models go through the real graph. The number check rejects an invented figure and cannot see a real figure in the wrong place.startrouteagenttoolsverify_numbersredraftanswer« Combien coûtait le lait ? »1. the question2. a question about the data3. search_documents("lait")4. Lait demi-écrémé, 1,05 € …5. draft : Le lait coûtait 1,50 €.6. 1,50 € is in no result ✗7. new draft : Le lait coûtait 1,05 €.8. every figure is proven ✓answer9. Le lait coûtait 1,05 € [rct_1].
One question through the agent graphThree scripted models go through the real graph. The number check rejects an invented figure and cannot see a real figure in the wrong place.startrouteagenttoolsverify_numbersredraftanswer« Combien coûtait le lait ? »1. the question2. a question about the data3. search_documents("lait")4. 2 passages found5. draft : Le lait coûtait 1,50 €.6. 1,50 € is in no result ✗7. new draft : Le lait coûtait 1,05 €.8. every figure is proven ✓answer9. Le lait coûtait 1,05 € [rct_1].

LangGraph

stm Agent graph (LangGraph)The compiled LangGraph: each box is a node, dashed lines are choices made at run time.ambiguousreplysmall talkabout datatool callunprovenstartrouteclarifychatagenttoolsverify_numbersredraftanswerstm Agent graph (LangGraph)
Shared state
The question, what the tools returned, the draft and its check
Choices
Clarify, chat or look up; accept the draft or correct it
Interrupt
Asks one clarifying question, and asks approval before changing data
Checkpointer
Keeps each conversation, so a pause can resume
Limits
Six tool steps, two corrections
Not used
The ready-made agent of LangGraph: it has no place for the number check
agent/src/costmap_agent/graph/agent.py
g = StateGraph(State)
for name, fn in (("start", start), ("route", route), ("clarify", clarify), ("chat", chat), ("agent", agent), ("tools", run_tools),
                 ("verify_numbers", verify_numbers), ("redraft", redraft), ("answer", answer)):
    g.add_node(name, fn)
g.add_edge(START, "start")
g.add_edge("start", "route")
g.add_conditional_edges("route", lambda s: {"clarify": "clarify", "chat": "chat"}.get(s["route"], "agent"), ["clarify", "chat", "agent"])
g.add_edge("clarify", "route")
g.add_edge("chat", "verify_numbers")
g.add_conditional_edges("agent", after_agent, ["tools", "verify_numbers"])
g.add_edge("tools", "agent")
g.add_conditional_edges("verify_numbers", after_verify, ["answer", "redraft"])
g.add_conditional_edges("redraft", after_redraft, ["tools", "verify_numbers"])
g.add_edge("answer", END)
return g.compile(checkpointer=checkpointer)

LangChain

Tools
Each MCP tool becomes a LangChain tool, plus a calculator
Models
Same interface for Workers AI, Gemini or a local Ollama model: the model is a setting
Not used
The official MCP adapter: it required an older MCP version, so I wrote the 20-line bridge
agent/src/costmap_agent/graph/tools.py
async def mcp_tools(client: Any) -> list[BaseTool]:
    """One LangChain tool per MCP tool. `client` is a connected `mcp.Client`; the tool schemas come straight from the server."""
    tools = []
    for t in (await client.list_tools()).tools:
        async def call(_name: str = t.name, **kwargs: Any) -> str:
            res = await client.call_tool(_name, kwargs)
            body = res.structured_content.get("result", res.structured_content) if res.structured_content is not None else None
            if body is None:  # the server sent the result as text: decode JSON when it is JSON
                text = "".join(getattr(c, "text", "") for c in res.content)
                try:
                    body = json.loads(text)
                except ValueError:
                    body = {"text": text}
            return json.dumps(body, ensure_ascii=False, default=str)

        tools.append(StructuredTool(name=t.name, description=t.description or "", args_schema=t.input_schema, coroutine=call))
    return tools

MCP tools

ToolWhat it does
search_purchasesPayments by shop, period, category
spending_summaryTotals by category or shop
price_historyOne product over time
compare_pricesOne product across shops
upcoming_subscriptionsNext payments due
open_questionsWhat waits for the user
get_receiptOne receipt
search_documentsRetrieval over receipt text
answer_questionChanges data: needs approval

Number check

act Ask about spendingThe model proposes; the agent only shows a figure that a tool returned, or flags it.UserAgentLanguage modelSpending toolsAsk a questionPick the kindof questionChoose what tolook upReturn figuresand sourcesWrite a draftanswerCheck every figureagainst the tools[unproven]Correct thefigure[twice at most][all proven]Add sources, flagwhat stays unprovenRead the answeract Ask about spending
agent/src/costmap_agent/graph/agent.py
async def verify_numbers(state: State) -> dict:
    ev = collect_evidence([e["result"] for e in state.get("evidence", [])])
    rep = verify(state.get("draft", ""), ev)
    return {"verification": {"ok": rep.ok, "unverified": rep.unverified, "n_claims": len(rep.claims), "message": rep.message()}}

Evaluation

74 questions, scripted models that make mistakes on purpose. No real language model yet.

Stand-inCorrectWarnedSilent errors
Careful model100 %0 %0
Model that invents a figure85 %15 %0
Model that swaps two real figures63 %0 %23

Known weakness: a real figure put in the wrong place passes the check.