The agent
How a visitor's message becomes an answer, through a fixed workflow with models inside it, built directly on AWS primitives.
Key points
The agent answers questions about my work, in my voice, from a Knowledge base of Markdown files.
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.
Models do what takes judgment, and code does what has to be true.
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.
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:
| Approach | Non-greeting messages that searched |
|---|---|
| Search rule in the tool description | 18 of 39 |
| Rules split across prompt and tools | 31 of 39 |
| Search forced on the first model call | 42 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 step | First words (median) | Cost per reply in the test (mean) | Result |
|---|---|---|---|
| Haiku 4.5 writes | 2.9 s | 0.40¢ | Invented more |
| Sonnet 4.6 writes | 3.0 s | 0.76¢ | Chosen |
| Nova drafts, Sonnet reviews | 5.4 s | 0.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:
| Step | Time limit | If it fails |
|---|---|---|
| Router | 4 s | Search on the visitor's own words; a bare greeting goes direct |
| Search | 5 s | The writer is told the search failed and says it doesn't know |
| Researcher | 4 s | The writer gets the raw passages |
| Writer | Function deadline | Text 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 provides | The system builds on top |
|---|---|
| Nova 2 Lite and Sonnet 4.6 through Bedrock | Which model does which step, prompts, temperatures, time limits and fallbacks |
| Knowledge Base, Titan embeddings, S3 Vectors | What gets indexed, chunking per source, when a search runs |
| Lambda with streaming Function URLs | The Turn workflow, streaming standard AG-UI events over server-sent events |
| CloudFront, WAF | Signed origins, rate rules, routing between two regions |
| DynamoDB, S3 | Budgets, conversation records, transcripts, snapshots |
| Parameter Store, CloudWatch, Budgets | The 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 code | Asked of the model |
|---|---|
| The search on a question about me, and which quotes reach the writer | Voice and length |
| The fixed "don't know" reply when a search finds no answer | Declining 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 path | Staying in character |
| A random boundary around the visitor's words | Not treating those words as instructions |
| Token budgets and the kill switch | Saying "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
| Decision | Chosen over | Why | Trade-off |
|---|---|---|---|
| Quotes checked before writing | A model checking finished replies | That 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 routes | Search on every message, or no router | In 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 answers | Default chunking | Default chunking found the wrong failure story in 3 of 3 test runs. | A second bucket and data source. |
| Budgets in tokens | Message counts | Tokens 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.