Capstone: support bot with RAG + tools
Create the runnable skeleton and contracts
Types and env contracts make **support API: versioned policy retrieval + scoped order tool + cited answer or escalate** fail closed before any provider or cluster call.
1Try it yourself
Playground
Support bot: RAG + tool
Retrieve policy text, optionally fetch live order status, then answer with citations.
User: Can I refund order #8821 on my annual plan?
- → Retrieve FAQ chunk
- ○ Call order lookup tool
- ○ Generate cited reply
2Learn the idea
Read
Define trusted borders
Implement types or schemas around POST /v1/support/turn so illegal states are unrepresentable at the boundary. For support API: versioned policy retrieval + scoped order tool + cited answer or escalate, trusted inputs come from sessions, signatures, pinned digests, or workload identity — not from free-form model text. customer asking where order A12 is without leaking other customers' orders should be able to read the contract and know which fields are optional, which are enumerated, and which abort the request. Constructors and boot paths must not perform provider side effects; injection points keep tests honest.
Read
Environment and secrets contract
Document required env vars in .env.example with placeholders only. Rotation story belongs later, but the contract already forbids printing secrets and forbids defaulting to fail-open when a dependency is missing. Invariant to encode in types/tests: tool args bind to session customer_id; refunds never auto-executed. If a config number lacks units, fix the name (timeout_ms, rpm_hard) before writing logic.
Read
Implementation artifact
type Turn = { sessionCustomer: string; text: string };
type Out = { answer: string; citations: string[]; escalated?: boolean };
Read
Fixture kit
Create fixtures for the golden path and for CAP-SUPPORT-TOOL-09. Name files after the behavior (429-retry-after.json, cross-tenant.json, empty-citation.json) rather than test1. Each fixture carries expected status/code. This kit is the shared language for validation and failure pages.
Read
Stage depth
Compatibility promise: additive fields may appear only if readers ignore unknowns safely; breaking changes bump a version visible on the wire. For AI payloads, size limits arrive before JSON parse when hostile blobs are a risk. Document how clock skew, idempotency keys, and tracing headers travel through support API: versioned policy retrieval + scoped order tool + cited answer or escalate. If you use feature flags later, the contract already states that flags are not authorization. Link each config knob to a unit and a failure mode (“0 means disabled” vs “0 means divide-by-zero”). A peer reviewing the PR should find CAP-SUPPORT-TOOL-09 named in a comment on the adversarial fixture.
Read
Field notes for `capstone-support-bot` / `setup-and-contract`
Generate OpenAPI or a typed client only after the hand schema is stable for one fixture round-trip. Record how errors look on the wire — problem+json, envelope, or bare status — and stick to one. Clock sources must be injectable for skew tests. If webhooks appear later, document signature header names now even as TODOs. Keep sample payloads UTF-8 and free of real emails. Add a makefile or npm script that validates schemas without network. In this chapter the product is support API: versioned policy retrieval + scoped order tool + cited answer or escalate, the human stakeholder is customer asking where order A12 is without leaking other customers' orders, and the incident id you design against is CAP-SUPPORT-TOOL-09. Re-state the oracle in your notes — order lookup returns status+policy cite; cross-customer order_id → deny+escalate — and keep the invariant visible: tool args bind to session customer_id; refunds never auto-executed. Track unauthorized_tool_calls == 0 and citation_rate ≥ 0.9 as the scoreboard. Surface under change control: POST /v1/support/turn. If you only have forty minutes, finish the fixture for model passes attacker order_id and tool executes before polishing UI. Promotion language stays ternary: promote, hold, or roll back based on evidence, not hope.
Go deeper
Before you start
Why this matters
For Capstone: support bot with RAG + tools, sketch the request and response shapes that cross POST /v1/support/turn without naming a framework. Mark which fields are trusted (session, signatures, digests) versus untrusted (user text, model JSON, webhook bodies). If a field can change authorization, it does not belong in model output. Predict one 422/401 you will assert before coding adapters for support API: versioned policy retrieval + scoped order tool + cited answer or escalate.
Contracts you freeze now carry through the capstone demo of support API: versioned policy retrieval + scoped order tool + cited answer or escalate.
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.