From Exam Rules to Production: The Obligation Q&A Agent
The use case: a budget analyst wants to ask a Claude-based assistant plain-English questions about DoD obligation data pulled from public FedFM sources — "What did we obligate against this appropriation last quarter?" — instead of filing a data-pull ticket and waiting two days for an answer that is already stale by the time it arrives. This is the same shape as my CCAR-P capstone: a TypeScript agent over public FedFM obligation data, backed by an architecture decision record, an eval harness, a risk register, and a stakeholder brief. Treat this page as that capstone's design review, written out in full, the way a principal architect would actually defend it to a skeptical stakeholder — not a glossary of terms.
本页用一个真实案例贯穿全部考试领域:一个基于 Claude 的问答助手,让预算分析师用自然语言查询联邦财务管理(FedFM)的公开拨款数据,取代手动拉数据、等两天还可能过期的工单流程。这就是我 CCAR-P 毕业项目的真实样子:一个基于 TypeScript 的智能体,配有架构决策记录、评测框架、风险台账和业务方简报。把这页当成毕业项目的完整设计评审,而不是术语表。
Overview: why this shape, before any step
The trap in this kind of project is starting from the technology ("let's build a Claude agent") instead of the failure mode you're actually defending against. A budget analyst asking for an obligation figure is not primarily a natural-language problem. It is primarily a trust problem: the number has to be right, traceable to its source, and clearly dated, because it will end up in a briefing to someone who did not watch it get produced. Every architectural choice below follows from that one sentence. Get the trust properties right first; the chat interface is the easy 10%.
That reframing is what separates an architect's design from a developer's demo. A demo optimizes for "it answered the question." A production system optimizes for "it answered the question, and if it's wrong, I can prove why, who's accountable, and how fast I'll know."
What's actually at stake
| Stakeholder | What they actually care about | Cost of getting it wrong | Who owns the control |
|---|---|---|---|
| Budget analyst | A fast, correct answer they can act on without re-verifying it by hand | Re-does the manual pull anyway; the tool loses trust after one bad answer | Product owner (sets accuracy bar) |
| CFO / front office | Any number quoted up the chain is defensible under scrutiny | A wrong figure in a briefing becomes a credibility problem, not just a bug ticket | Architect (output validator design) |
| Data/platform team | The agent doesn't become an unbounded, unmonitored query surface against production data | Uncontrolled load, a security finding, or an audit question with no evidence trail | Architect + security review (tool scoping, authz) |
| Auditor (FIAR/DODIG lens) | Every control has a named owner and evidence, same as any other financial process control | An NFR-style finding against the system itself | Risk register owner |
Naming these four up front is what makes every later tradeoff decidable. A design that's fast for the analyst but unauditable for the CFO is not a good design — it's a deferred finding.
架构设计前先把利益相关方和风险讲清楚:分析师要速度和可信,CFO 要经得起追问,数据团队要防止失控的查询面,审计视角要求每个控制都有责任人和证据。把这四点先定下来,后面每一步的取舍才有依据。
Step 1 · Discovery before design D6 Conduct structured discovery and requirement gathering
The request arrives as "build us a chatbot that can answer anything about our obligations." That sentence is not a requirement; it's a wish, and it's the single most common way these projects get the architecture wrong before anyone writes code. If you let "anything" stand, you will over-build toward an open-ended agent for a problem that is actually a bounded, enumerable lookup-and-aggregate task.
Work the discovery in this order:
- Pin the data boundary. Which FedFM extracts, exactly, and on what refresh cadence? "All our financial data" is not a boundary; "the public obligation extract, refreshed nightly" is.
- Enumerate the question types, don't describe them. Sit with the analyst and collect eleven real questions they've asked a human for in the last month. If you can sort them into four or five repeatable shapes (lookup by TAS, lookup by period, period-over-period comparison, roll-up by appropriation), that's your real scope — not "anything."
- Price the failure. What does a wrong number cost here, specifically? A misquoted obligation figure heading into a CFO briefing is not the same severity as a wrong answer in an internal FAQ bot. This number drives how much you invest in the validator in Step 7, not a vague "be careful."
- Write down what's explicitly out of scope for v1. No write access. No cross-system reconciliation. No analysis beyond the enumerated question shapes. Out-of-scope items you name now are the ones you won't quietly build halfway through.
- Get the scope signed, not just discussed. A one-paragraph scope note the stakeholder actually reads and agrees to is worth more than a requirements doc nobody re-opens.
| Dimension | Why it matters here |
|---|---|
| Cost of skipping this step | Low today, high later — a pattern chosen for the wrong scope means rebuilding the retrieval and tool layer, not tuning a prompt |
| Risk if scope stays vague | You build an agent (open-ended) for a workflow (bounded) problem, inheriting cost, latency, and failure-surface you didn't need |
| Decision owner | Product/business owner defines the requirement; architect translates it into the pattern decision in Step 2 |
Q: "Why not just start building? We can refine scope as we go."
先完成结构化需求挖掘:锁定数据边界、把问题归纳成几种可枚举的类型(而不是"什么都能问")、量化出错代价、明确 v1 不做的事,并让业务方对范围签字确认。这些决定了后面该选工作流还是智能体。
Step 2 · Pattern selection D1 Select appropriate architectural patterns
With Step 1's question shapes in hand, lay them against the three patterns the exam cares about: an augmented single call (one retrieval, one answer, no branching), a workflow (routing and/or chaining across a known set of steps), or an agent (the model decides its own next tool call in a loop it controls). The obligation Q&A set — lookup, compare, roll-up — is enumerable: you can draw the full decision tree today. That's the textbook case for a routing workflow, not an agent.
How to make the call, step by step:
- Draw the decision tree from Step 1's question shapes. If you can draw it completely on a whiteboard in twenty minutes, the path is enumerable.
- Identify the routing key. Here it's question type (lookup/compare/roll-up) plus the entities named in it (TAS, period). A classification step picks the branch; each branch calls a fixed, known sequence of tools.
- Stress-test for the agent case. Ask: is there a real question shape where the number of steps and which tools get called can't be known in advance? If every real example you collected in Step 1 fits a fixed branch, you don't have that case yet.
- Default to the cheaper, more constrained pattern and upgrade only on evidence. A workflow is easier to test exhaustively (you can enumerate every branch in your eval set), cheaper to run, and has a bounded failure surface. An agent earns its added cost, latency, and risk only when the path truly isn't enumerable in advance.
- Document the choice in the ADR with the specific question shapes that justified it, so a future "let's just make it an agent" conversation has something concrete to argue against.
| Dimension | Workflow (chosen) | Agent (rejected here) |
|---|---|---|
| Cost per query | Lower — fixed, known tool calls per branch | Higher — variable tool-call count, harder to bound |
| Latency | Predictable, easier to meet an SLA | Variable; a reasoning loop can run long |
| Testability | Every branch is enumerable in the eval set | Harder to exhaustively test an open decision space |
| Risk surface | Bounded to the fixed tool set per branch | Broader; any reachable tool combination is in play |
| Decision owner | Architect, with the question inventory from Step 1 as evidence | |
Q: "Shouldn't it be an agent, so it can handle anything the analyst asks later?"
问题类型可枚举(查询、比较、汇总),可以完整画出决策树,这正是路由工作流的典型场景,而不是自主智能体。智能体的额外成本、延迟和风险只有在路径确实无法预先枚举时才值得承担;为"以后可能会问的问题"现在就上智能体,是在为假设的未来买单。
Step 3 · Model and context engineering D2 Select models based on trade-offs; optimize context windows
Context design and model choice are two separate decisions that get conflated constantly. Context design decides what the model sees on this call. Model choice decides which tier processes it. Get the first one wrong and no model tier fixes it; get the second one wrong and you're overpaying or under-delivering on a correctly-scoped call.
Context design, concretely:
- Separate what's static from what's per-query. Static: role, output schema, the handful of formatting rules (how to present a dollar figure, how to state the data-as-of date). Per-query: the specific obligation records the current question needs.
- Put the static block first, and enable prompt caching. Every call reuses the same cached prefix; you pay the full cost once per cache window, not per call.
- Never paste obligation data into the system prompt. It's retrieved per question through the Step 4 tools. The system prompt describes the schema and the rules for using that data, not the data itself.
- Resist "just add the whole glossary for safety." If a term isn't needed to answer the current question, it doesn't belong in this call's context — it belongs in the retrieval layer, fetched only when a question actually touches it (progressive discovery, not monolithic context).
Model tier, concretely: Sonnet-class for the narration step. The task is grounded synthesis — take verified tool output, state it clearly with the right caveats — not frontier-level reasoning. Pick the smallest tier that clears the Step 6 eval bar on the golden set, and re-check that choice if the question set ever grows harder, not by default assumption.
| Dimension | Note |
|---|---|
| Cost | Caching the static prefix plus a smaller model tier are the two biggest levers; both compound across call volume |
| Latency | A shorter, targeted per-query context beats a bloated one on time-to-first-token, cache or not |
| Quality | Grounding comes from retrieval accuracy, not context volume — a bigger prompt doesn't make a number more correct |
| Maintainability | A static system prompt plus a documented retrieval contract is easier to version than a growing, undifferentiated context blob |
| Decision owner | Architect (context shape), with engineering validating the model tier against the eval harness |
Q: "For accuracy, why not load the whole FMR glossary and the full chart of accounts into the system prompt?"
把稳定不变的内容(角色、输出格式、展示规则)放在提示词最前面并开启缓存;具体拨款数字按问题从检索层获取,不整段塞进系统提示词。模型选择能通过评测门槛的最小档位,而不是默认选最大模型;上下文越大不代表答案越准,关键在于检索是否命中。
Step 4 · Integration protocol D3 Evaluate connection protocols (MCP, API/CLI, agent-to-agent)
This decision is purely about who else needs this tool surface, and when. The retrieval and aggregation functions here are called directly from the app's own backend. A direct tool/function call is the right choice because there is exactly one caller: this app, this request path, nothing else in the environment needs to discover or reuse these functions right now.
Work the decision this way, every time:
- Count real consumers today, not hoped-for ones. One app, one backend, one request path → direct call. Multiple distinct Claude clients (a dashboard, a Slack bot, another team's app) genuinely needing the same tool surface → MCP earns its overhead.
- Check who owns versioning and change risk. A direct call versions with the app that owns it. An MCP server becomes a shared dependency with its own release discipline the moment a second consumer attaches — don't take on that discipline before you need it.
- Separate "shareable in principle" from "shared now." Almost any tool is shareable in principle. That's not the test. The test is whether a second real caller exists today.
- Leave an extraction seam, don't pre-build the abstraction. Keep the retrieval functions cleanly separated from the app's request-handling code so that, if a second consumer does show up, wrapping them in an MCP server is a refactor, not a rewrite.
| Dimension | Direct call (chosen) | MCP (not yet) |
|---|---|---|
| Overhead | Minimal — one caller, one contract | Server to run, version, and secure independently |
| Change risk | Low — changes and consumer live together | Any breaking change now affects every attached client |
| When it's the right call | Single consumer, current state | Multiple distinct Claude clients need the identical tool set |
| Decision owner | Architect, revisited the moment a second real consumer is proposed | |
Q: "Our team's internal dashboards might also want this later — shouldn't we build it as an MCP server now, just in case?"
这个决定只看一件事:现在真正有几个调用方。本案例检索和聚合函数由本应用后端直接调用,属于直接的工具调用,不用 MCP;MCP 的开销(独立运行、版本管理、安全维护)只有在多个不同的 Claude 客户端确实需要共用同一套工具时才值得承担。保持检索层与业务逻辑解耦,未来真有第二个调用方时再抽取成 MCP 服务。
Step 5 · Tool scope and least privilege D3 Evaluate tool/agent configuration for capability bloat; analyze authorization requirements
This is the step my own instinct fights hardest, and it's worth naming why: enterprise and government practice trains you to add a check in front of a broad capability (log it, confirm it, review it later). The architect's answer here is structurally different: don't grant the broad capability at all. Every exam item that smells like this one wants removal, not detection.
Scoping the tool surface, concretely:
- Start from the five question shapes in Step 1, not from "what could this data store do." Each shape gets exactly one tool:
getObligationsByTAS,getObligationsByPeriod,compareObligationPeriods,rollUpByAppropriation. - Parameterize, don't generalize. Each tool takes typed, validated parameters (a TAS string, a period range) and returns only the fields the UI is allowed to show. No tool accepts a raw query string.
- Make write access structurally absent, not merely unused. There is no update/delete/export tool in the configuration at all — not a read-only flag on a powerful tool, an actually absent capability.
- Resolve authorization server-side from the session, never from a role or scope the incoming message claims. "I'm an analyst with export rights" typed into a chat box is not an authorization source.
- Review the tool list itself as a standing control. Before every release, ask: does every tool in this list still map to a real, current question shape? A tool nobody's workflow uses anymore is bloat sitting in the attack surface for no benefit.
| Dimension | Narrow, parameterized tools (chosen) | Generic query tool (rejected) |
|---|---|---|
| Build speed | Slower upfront — one tool per shape | Faster upfront — one tool does everything |
| Risk surface | Bounded to exactly the enumerated shapes | Unbounded — anything expressible in the query language |
| What enforces safety | Structure (the tool literally cannot do more) | Wording (a prompt instruction hoping the model won't) |
| Decision owner | Architect, with security review signing off the final tool list | |
Q: "A single generic run_query tool would be so much faster to build than four narrow ones. Can't we just tell it in the prompt to only run safe, read-only queries?"
只提供与五种问题类型对应的少量、参数化、只读工具,没有通用查询工具,也没有任何写入能力。权限由服务端根据会话解析,不接受用户在对话里自称的角色。提示词里的"请只读、别乱改"不是可执行的护栏;架构师的做法是直接移除多余能力,而不是靠指令约束,并把工具清单本身作为每次发布前的常规审查项。
Step 6 · Evaluation harness D4 Define evaluation metrics; design evaluation datasets and test frameworks
The eval harness is written before the production code, not after, because it's what turns "I think this works" into a measurable claim. For an obligation Q&A agent, most of what matters has a verifiable correct answer — which argues for code-based scoring as the default, with LLM-as-judge reserved for the narrower slice that genuinely needs judgment.
Building the harness, step by step:
- Build the golden dataset from real questions, not invented ones. Pull the same question inventory from Step 1, and for each one, record the exact correct figure from the source extract at a known point in time.
- Score every numeric claim with code. Exact match (or a defined tolerance for rounding) against the golden source. This is deterministic; there is no reason to pay for a judge call on a check a script can make.
- Reserve LLM-as-judge for narrative quality only. Clarity, whether the data-as-of date is stated, whether the right caveats appear when data is incomplete. Give the judge a tight rubric and a small label set, and calibrate it against a human-labeled sample before trusting its scores.
- Segment the results before reading the average. Break scores out by appropriation type and by TAS category. A regression hiding in one high-visibility segment is exactly the failure a single blended average will hide.
- Re-run the full suite on every prompt, tool, or model-version change. No exceptions for "small" edits — the smallest wording change can shift grounding behavior in ways intuition won't catch.
- Watch for a stale golden set. If the underlying FedFM extract refreshes and the golden answers don't get re-derived, the suite starts measuring agreement with outdated numbers, not correctness.
| Scoring method | Use for | Cost | Weakness |
|---|---|---|---|
| Code-based | Every numeric obligation figure, date formatting, schema of the tool-call output | Near zero; never drifts | Can't judge tone or explanatory quality |
| LLM-as-judge | Narrative clarity, caveat presence, tone | About one call per item | Needs calibration; inconsistent at edge cases |
Q: "The last prompt change raised our average eval score from 91% to 94%. Ship it?"
能用确定性数字核对的内容(拨款金额、日期格式)用代码评分,不花成本请大模型做裁判;叙述质量(是否说明数据截止日期、措辞是否清晰)才用小规模的 LLM 评委打分,并先用人工标注校准。结果必须按细分维度(拨款类型、TAS)查看,总体平均分提高但某个高风险细分退步时不能上线。每次改动提示词、工具或模型版本都要重跑整套评测。
Step 7 · Guardrails and the risk register D5 Implement guardrails and safety controls; identify risks and failure modes
Guardrails here are structural, not conversational. The single highest-value rule: every dollar figure the analyst sees must trace back to a tool-returned value. The model is never allowed to be the last word on what number appears on screen.
Building this in, concretely:
- Make the rendering layer the enforcement point, not the prompt. The UI component that displays a dollar figure accepts only values that arrived through a validated tool-call result object — it has no code path that renders a number pulled from free-form model text.
- Validate the tool-output schema before it reaches the model's context. If a retrieval call returns something malformed, that's a fail-closed condition, not a best-effort pass-through.
- Build the risk register like a corrective action plan. For each failure mode — stale data shown as current, a misattributed TAS, an unauthorized export attempt — write the specific control, name an owner, and define what evidence proves the control is operating (a log query, a test result, a config screenshot).
- Treat human review as a designed step for the highest-stakes outputs, not a fallback for when the model seems unsure. If an answer is heading into a CFO-facing export, route it through a lightweight review step by design, not by exception.
- Review the register on a calendar cadence, the same discipline as a FIAR/DODIG control test, not only after an incident prompts a look.
| Failure mode | Control | Evidence |
|---|---|---|
| Model states a figure not backed by a tool result | Rendering layer rejects non-tool-sourced numbers | Unit test on the render component; eval case that attempts this |
| Stale extract shown as current | Every response carries a data-as-of date sourced from the extract's own timestamp | Spot-check against the extract's refresh log |
| User-claimed role grants extra access | Authorization resolved server-side from session only | Security review sign-off; penetration test note |
Q: "Can't we just add a line to the prompt: 'never make up a number, always be accurate'?"
护栏是结构性的,不是对话式的:界面上显示的每个数字都必须来自工具返回的结构化结果,渲染层没有任何代码路径能显示模型自由生成的数字;工具返回的数据在进入模型上下文前先校验格式,格式不对就直接失败而不是勉强放行。风险台账的每一项都要有责任人、具体控制措施和证据,和 FIAR/DODIG 的整改计划一样按日历节奏定期复查,而不是只在出事后才想起来看。
Step 8 · Observability and lifecycle D7 D6 Monitor system performance; support lifecycle phases
Launch is the midpoint of this project, not the end. The two things an infrastructure dashboard will never show you: slow answer-quality drift, and whether the business actually believes the thing is working. Both need their own instrumentation and their own owner.
Running it in production, concretely:
- Trace every tool call with latency, cost, and the query parameters that triggered it, tied to a shared trace ID per request so a bad answer can be reconstructed end to end.
- Separate uptime monitoring from quality monitoring. Infra dashboards (error rates, latency, 5xx counts) answer "is it up." A sampled output-quality score, read by segment, on its own schedule, answers "are the answers still good" — a different failure mode entirely.
- Set a trend trigger, not just a threshold alert. A slow decline across weeks won't fire a single-point alert; it needs an owned, periodic look at the trend line itself.
- Run a calendar-based audit, independent of alerts, appropriate to a regulated financial-data domain — the same logic as a periodic control test that happens whether or not anything looks wrong.
- Pin model and dependency versions, and gate every version swap through the Step 6 eval suite with a pre-set pass threshold, rather than auto-upgrading and finding out from user complaints.
- Report to the stakeholder in auditable-control-backed terms: ticket volume avoided, time-to-answer, eval pass rate by segment — never a vague "productivity gain" claim with no control or measurement behind it.
| Signal | Catches | Cadence |
|---|---|---|
| Infra dashboard (latency, errors) | Outages, dependency failures, timeouts | Real-time alerting |
| Sampled output-quality score, by segment | Retrieval drift, stale index, subtle grounding regressions | Continuous sampling + periodic review |
| Calendar audit | Anything neither of the above was built to catch | Fixed schedule, regardless of alerts |
Q: "The dashboards are all green. Why would we need a separate quality review?"
上线只是项目的中点,不是终点。基础设施监控显示系统在运行,不代表答案质量没有下降;检索漂移、索引过期或模型版本被悄悄升级都可能在各项运行指标全绿的情况下发生。因此需要独立的、按细分抽样的输出质量评分,并按固定节奏做日历审查,而不只是依赖告警。向业务方汇报的指标必须有可审计的控制支撑(避免的工单量、响应时间、按细分的评测通过率),而不是空泛的"提升了效率"。
Putting it together
The pattern across all eight steps is the same one: whenever my instinct, trained by years of enterprise and government practice, reached for a detective control — more logging, a confirmation prompt, a prompt instruction, "we'll catch it in review" — the better answer was almost always structural: remove the capability, retrieve instead of stuff the context, scope the tool narrowly, validate the output shape at the boundary, resolve authorization server-side, separate uptime from quality monitoring. That's the lens the exam rewards, and it's the same lens that survives a real design review. Building the capstone alongside the study is what made the lens automatic instead of memorized.