Build an agent that answers questions about your own documents and data, and can file a summary ticket.
Architecture:
1. Tools — an MCP filesystem/docs server for retrieval, a SQL tool for metrics, `create_ticket` behind an approval gate. 2. Loop — ReAct with a max of 10 steps and per-tool timeouts. 3. Memory — scratchpad compression at 12k tokens; long-term facts in a table with a vector column. 4. Guardrails — input injection screen, output PII redaction, allow-listed egress. 5. Observability — one trace per run with step spans, token counts, and cost; sample traces into a review queue. 6. Evals — 30 trajectory cases in CI with mocked tools; nightly staging run.
ts
export async function research(goal: string, userId: string) {
const trace = startTrace({ userId, goal });
try {
const answer = await runAgent(goal, registry, 10);
trace.ok({ answer });
return answer;
} catch (e) {
trace.fail(e);
return "I could not complete this safely. A human has been notified.";
}
}Ship criteria: every run traced, every irreversible action gated, eval suite green, and a documented per-task cost ceiling with an alert when it is exceeded.
Exercise: run the capstone against ten real questions from colleagues and log which failures were retrieval problems, which were tool-schema problems, and which were genuine reasoning errors. Fix in that order.