The agent

How a visitor's message becomes an answer, through a fixed workflow with models inside it, built directly on AWS primitives.

case study · 2026
~/dansabin.com — chat Ask about this project

Key points

What it is

The agent answers questions about my work, in my voice, from a Knowledge base of Markdown files.

The workflow

A question about me runs as a fixed workflow: a small model routes, code runs the search, a small model picks quotes, code checks them, and a larger model writes with no tools.

The rule

Models do what takes judgment, and code does what has to be true.

The foundation

The system is built directly on AWS primitives, with Strands as the agent framework inside one Lambda function and no hosted agent platform. The workflow, limits and fallbacks are its own.

What happens in a Turn

A Turn is one visitor message and everything done to answer it. Every Turn starts the same way: the request passes through CloudFront to a Lambda Function URL, which accepts only requests CloudFront has signed. The function verifies the visitor's anonymous signed token, reads the kill switch and reserves tokens against two budgets. No model runs until those checks pass.

A small model then routes the message. From there, a Turn takes one of two paths.

One Turn on the search pathThis drawing shows one Turn on the search path, from top to bottom. The visitor's message passes CloudFront and WAF to the Lambda function, which checks identity and the kill switch, reserves tokens and loads the conversation. Nova 2 Lite routes the message, and the visitor sees the holding line. The function searches the Knowledge Base, shows the search words and sources, and Nova 2 Lite picks quotes. Code keeps the quotes found in a passage. Sonnet 4.6 writes from them with no tools, the answer streams to the visitor, and the function stores the Turn and settles its budgets. Two paths leave early: a greeting or off-topic message goes from the router to Sonnet 4.6 with its tools, and a question with no answer gets the fixed reply. A refusal at any check ends the stream with one error event.VisitorbrowserCloudFrontWAFLambdaTurn workflowNova 2 Literoutes, picksKnowledge BasesearchSonnet 4.6writesDynamoDBS3messagesigned requestidentity, kill switchreserve tokens, load conversationroute itsearch words, lineholding linesearch5 best of up to 50 passagessearch words, sourcespassagesup to 5 quoteskeep quotes found in a passagechecked quotes, no toolsreply, streamedanswerstore the Turn, settle budgetsrun finished One Turn on the search pathThis drawing shows one Turn on the search path, from top to bottom. The visitor's message passes CloudFront and WAF to the Lambda function, which checks identity and the kill switch, reserves tokens and loads the conversation. Nova 2 Lite routes the message, and the visitor sees the holding line. The function searches the Knowledge Base, shows the search words and sources, and Nova 2 Lite picks quotes. Code keeps the quotes found in a passage. Sonnet 4.6 writes from them with no tools, the answer streams to the visitor, and the function stores the Turn and settles its budgets. Two paths leave early: a greeting or off-topic message goes from the router to Sonnet 4.6 with its tools, and a question with no answer gets the fixed reply. A refusal at any check ends the stream with one error event.CloudFront, WAFsigns the requestLambdaidentity, kill switch, budgetsNova 2 Literoutes, holding line shownKnowledge Base5 best of up to 50, sources shownNova 2 Litepicks up to 5 quotesCodekeeps quotes found in a passageSonnet 4.6writes with no tools, streamedDynamoDB, S3stores the Turn, settles budgets
This drawing shows one Turn on the search path, from top to bottom. The visitor's message passes CloudFront and WAF to the Lambda function, which checks identity and the kill switch, reserves tokens and loads the conversation. Nova 2 Lite routes the message, and the visitor sees the holding line. The function searches the Knowledge Base, shows the search words and sources, and Nova 2 Lite picks quotes. Code keeps the quotes found in a passage. Sonnet 4.6 writes from them with no tools, the answer streams to the visitor, and the function stores the Turn and settles its budgets. Two paths leave early: a greeting or off-topic message goes from the router to Sonnet 4.6 with its tools, and a question with no answer gets the fixed reply. A refusal at any check ends the stream with one error event.

The router fills in a fixed form: whether to search, what to search for, and a short holding line to show the visitor. It never sees the Knowledge. Code checks the holding line before it's shown and replaces a line that breaks a rule with one written in advance.

On the search path, code searches the Knowledge Base on the visitor's words and on the router's at once, a reranker orders the passages from both, up to 50, and the five best go on. The researcher reads them and returns up to five quotes. Code keeps a quote only if it appears word for word in a single passage. If the passages don't answer the question, code searches once more with new words. If there's still no answer, the visitor gets a fixed "don't know" reply and the writer isn't called, unless the question made a claim or named a different role, and then the writer declines or corrects it.

The visitor sees this as it happens: the holding line, the search words, the source files, then the answer. Private sources are labeled "private notes," and passages never reach the browser. This activity is stored with the reply, so it survives a reload.

Why the facts sit behind a search

A prompt can only ask a model to behave. Testing showed how far asking goes:

ApproachNon-greeting messages that searched
Search rule in the tool description18 of 39
Rules split across prompt and tools31 of 39
Search forced on the first model call42 of 42

Forcing the search worked, and replies could still state things the passages didn't support. So the design controls what the writer receives. Code runs the search and checks the quotes, and the writer gets only what survives.

The prompt keeps what a model does well and where a miss is less costly: voice, length and what to decline. The resume moved out of it, so the prompt stays small as the Knowledge grows.

How Strands is used

Strands is an SDK built around the agent loop. The model reads the conversation and either answers or calls a tool. Strands runs the tool, returns the result and asks again, until the model answers.

The direct path uses it that way. For a greeting or an off-topic message, the writer keeps its search and date tools and makes its own choices, because a wrong choice costs little.

The search path removes every tool before the writer starts, so the loop makes one call. Strands still provides the Bedrock stream, a snapshot of each conversation in S3, summaries of long histories, limits on tokens and cycles, and a hook on each model call. That hook adds the Turn's checked quotes to the system prompt and wraps the visitor's words in a random boundary, so they can't pass as instructions.

The router and researcher are direct Bedrock calls and don't go through Strands. The fixed path itself is ordinary code rather than a Strands graph, and two of its steps, the search and the quote check, use no model.

Why two models

Amazon Nova 2 Lite routes, researches and summarizes long histories. Claude Sonnet 4.6 writes. List prices per million input and output tokens are $0.33 and $2.75 for Nova, and $3.30 and $16.50 for Sonnet. The cheaper model does the reading, and the writing is what visitors judge.

Three ways of producing the final reply were compared on 12 hard questions, three runs each, with Nova doing the research:

Final stepFirst words (median)Cost per reply in the test (mean)Result
Haiku 4.5 writes2.9 s0.40¢Invented more
Sonnet 4.6 writes3.0 s0.76¢Chosen
Nova drafts, Sonnet reviews5.4 s0.83¢Rewrote all 31 drafts, with no streaming

Those costs are test figures, and they explain the choice. They aren't what a visitor's turn costs. A typical turn is about 2 cents, from 52 turns on production over 14 days. About 8 cents is the ceiling a long conversation can reach: 7 cents of that is the context sent to Sonnet, the reply itself is under a cent, and the Nova calls are fractions of a cent.

Nova does the model work where it can. Claude writes for its ability to sound more human, which seemed worth the cost, and that choice can still be tuned or adjusted.

Cost control and failure handling

Usage is metered in model tokens against one budget per visitor and one for the site, both in DynamoDB. A Turn reserves its worst case, then settles to what it used. As a budget runs low, the output cap and history shrink. A Turn is refused only when the budget can't cover its minimum.

The kill switch is a Parameter Store value that refuses new Turns while the rest of the site keeps serving. The operator can set it, an AWS Budget alert sets it for every environment, and a CloudWatch alarm on a burst of tokens sets it for one environment until traffic has been quiet. If the switch can't be read, the Turn is refused.

Every step has a planned outcome when it fails:

StepTime limitIf it fails
Router4 sSearch on the visitor's own words; a bare greeting goes direct
Search5 sThe writer is told the search failed and says it doesn't know
Researcher4 sThe writer gets the raw passages
WriterFunction deadlineText already streamed is kept as a cut-short reply; otherwise an error event

Built on AWS primitives

The system runs just above the bare metal of the cloud: AWS primitives, with Strands as the agent framework inside the function and no hosted agent platform in between. An app calling a model API with a key holds a secret and pays a separate vendor, and its levers are the ones that vendor offers. Here the models are one more AWS service. The function's IAM role can call two inference profiles and search one Knowledge Base, and no model key exists. Its Function URL takes only requests CloudFront has signed. Each profile carries the environment's tags, so model spend counts toward the AWS Budget, on the AWS bill, and Bedrock's metrics drive an alarm for each model.

AWS providesThe system builds on top
Nova 2 Lite and Sonnet 4.6 through BedrockWhich model does which step, prompts, temperatures, time limits and fallbacks
Knowledge Base, Titan embeddings, S3 VectorsWhat gets indexed, chunking per source, when a search runs
Lambda with streaming Function URLsThe Turn workflow, streaming standard AG-UI events over server-sent events
CloudFront, WAFSigned origins, rate rules, routing between two regions
DynamoDB, S3Budgets, conversation records, transcripts, snapshots
Parameter Store, CloudWatch, BudgetsThe kill switch and what trips it

No Bedrock Agents or AgentCore sit in the path. Everything is declared in CDK and deployed per environment.

The Knowledge itself is Markdown in the repository, checked at deploy. Documents use Bedrock's default chunking. Each of my written answers is its own file with chunking off.

Keeping the agent honest

My first brief for the agent said the bot must not invent facts and it should stay in character as me. Some of that can be enforced, and some of it can only be asked for.

Enforced in codeAsked of the model
The search on a question about me, and which quotes reach the writerVoice and length
The fixed "don't know" reply when a search finds no answerDeclining reserved topics
No tools for the writer on the search path or when it declines a hostile message, and only search and date otherwise on the direct pathStaying in character
A random boundary around the visitor's wordsNot treating those words as instructions
Token budgets and the kill switchSaying "don't know" on the direct path

The boundary and the planning step both began as my questions: whether visitor text could be wrapped in bookends, and whether the model could produce a short plan to check before the reply streams. The router began the same way, as a cheap small model that decides whether a message needs a search.

The Knowledge is Markdown in the repository, reviewed and versioned like code. It starts from my own words and my resume. Those files hold the reasoning, and the agent can only explain what they give it.

Design decisions and trade-offs

DecisionChosen overWhyTrade-off
Quotes checked before writingA model checking finished repliesThat checker flagged 55 of 157 real replies in one version and caught 23 of 33 planted problems in another, and would hold every reply back from streaming.The check proves a quote exists, not that the writer's wording stays within it. Nothing verifies a finished reply.
A small model routesSearch on every message, or no routerIn tests, it missed 6 of 66 needed searches, against 18 with no router.A missed search sends a question down the direct path, where the writer may search but doesn't have to.
Whole files for my written answersDefault chunkingDefault chunking found the wrong failure story in 3 of 3 test runs.A second bucket and data source.
Budgets in tokensMessage countsTokens track what a Turn uses.Sonnet and Nova tokens differ in price, and production meters tokens, not dollars.

Replies are tested on a fixed set of 56 messages, three runs each, with seven checks in code and six scored by a Sonnet judge. The judge never runs on a visitor's reply.

Want the details?

Ask the window anything this page skips.