Digital Twin Chatbot: How I Built an Open-Source AI Twin for My Website
The path of one message through my open-source AI twin: cheap checks before the model, a guard on every streamed chunk, and nothing stored.
The Digital Twin Chatbot is an open-source (MIT) AI twin for a personal website. Visitors ask about the owner's work and get first-person answers drawn from a knowledge base the owner writes. It says plainly that it is an AI, checks every streamed chunk against a deny list before anyone sees it, and stores nothing visitors type.
The path of one message through my open-source AI twin: cheap checks before the model, a guard on every streamed chunk, and nothing stored.
Key Takeaways
- The model is the easy part: One API call gets you a chatbot. The work is everything around it: caps, guards, forced retrieval and a memory that forgets.
- Guard the stream, not the finished reply: Each chunk is checked against the whole reply so far before it is sent, so a blocked term split across two chunks is still caught.
- Don't ask the model to search, make it: Told in the prompt to search first, the model still answered follow-ups from memory. Forcing the tool call fixed it.
- Store nothing and there is nothing to leak: Chats live in RAM for 30 idle minutes. No IP, user agent or chat text reaches the logs.
- The engine is public: MIT on GitHub, with a made-up persona, 581 passing tests and a 23-attack red-team suite.
Table of Contents
- The Path of One Message
- Search First, Then Speak
- Guarding a Reply While It Streams
- Openly an AI, and It Stores Nothing
- One Engine, Two Personas
- A Twin You Can Read, Test and Switch Off
Putting a chatbot on your own website sounds like a weekend project. One API call, a text box, done.
Now ask yourself: what happens when it speaks in your first person, under your name, to a stranger, while you're asleep?
A twin that answers as me can invent a project I never built. It can bring up things I've ruled out. It can be talked into doing someone's homework on my bill. And every wrong answer becomes "he said".
I put an AI twin on stratoslouvaris.gr on 25 Nov 2026 and open-sourced the engine behind it. The model call is the smallest part of that code. Let me show you the rest by following one message from the widget to the reply.
The Path of One Message
Start from first principles. A public chatbot has three jobs besides answering: don't run up my bill, don't say what I've ruled out, and don't keep what visitors tell it. The architecture is those three jobs in order: cheap checks before the model, a guard on every chunk after it, nothing stored.
1. The widget. One async script tag loads a Web Component in Shadow DOM, with no dependencies. It stays hidden until the backend's health check answers.
2. Three checks that can reply without the model. Caps come first: 30 messages per conversation, 200 a day in all, 15 per visitor IP. That daily number is the ceiling on my bill. Then a plain "hi" or "γεια" gets a canned greeting, and an input guard answers the obvious injection, role-play and do-my-task patterns with a refusal in character.
3. The agent. A Pydantic AI agent behind FastAPI searches the knowledge base (sqlite-vec or pgvector), then calls the model through OpenRouter (Claude Haiku 5.5 by default).
4. The output guard. Every chunk the model streams is checked before it goes out over Server-Sent Events.

Search First, Then Speak
The knowledge base is a JSON file of question-and-answer entries written in the first person. My live twin has 57. The public repo ships 23 made-up ones for a sample persona called John Doe, who stands in for me in every example here:
{
"id": 10,
"category": "projects",
"question": "What is Quarry?",
"answer": "Quarry is an open-source command-line tool I wrote. ..."
}
Each entry is embedded at startup. At question time the visitor's message is embedded too, and the three closest entries go to the model. (My RAG primer covers the mechanics.)
My prompt said "search before you answer". On the first live runs the model answered follow-ups from memory anyway. Worse, it said it had no specifics on a topic while the answer was the top result of a search it never ran.
A prompt is a request. So I stopped asking. A small capability called SearchFirst forces the search tool on every request of a turn until that turn has a result (app/agent/agent.py):
def per_request(ctx: RunContext[ChatbotDeps]) -> ModelSettings:
if (ctx.model_settings or {}).get("thinking") or searched_this_turn(ctx.messages):
return ModelSettings()
return ModelSettings(tool_choice=[SEARCH_TOOL])
Search results also filled the history, so a name a visitor gave in turn one was gone by turn four. Past turns now keep the question and the answer only.
One more that can bite you too. Pydantic AI's message history docs say that when message_history is not empty, "a new system prompt is not generated". A chat that opened with a canned greeting ran with no persona and no rules. The prompt now goes out as instructions=, with every request.
Guarding a Reply While It Streams
Streaming is what makes a chat feel alive. It's also what makes guarding it awkward: by the time the reply is finished, the visitor has already read it.
So the guard runs on every chunk, before it is sent, and it scans the whole reply so far, never the chunk alone. Models stream in fragments, and a blocked term can arrive as two harmless halves.
What's blocked? One list, in app/core/sensitive.py. Mine covers my current job, which stays out of this chat entirely: the twin answers "where do you work now?" with one fixed line.
Why a hard block rather than "name it, but say nothing else"? Because a deny list is enforceable. A model that may name the job can invent plausible details about it, and no guard catches a plausible invention.
In the sample persona the employer is a made-up company called "Init", which shows off the hard case: "Init" is also how "Initializer" starts. If the text so far ends in "Init", is that a leak or half of a harmless word? The guard can't know yet, so it holds that text back and waits:
- The next chunk continues the word ("ializer"): release everything.
- The next chunk ends the word (a space, a full stop): that's a hit.
On a hit, the server sends a text_replace event and the widget swaps what it has shown for a fallback line. The same scan looks for a canary token planted in the system prompt, for claims of being human and for vendor names.

The same list runs in CI: a scrubber fails the build if a knowledge entry contains a blocked term.
Now the honest part. A regex only catches the phrasings it lists. Seven of the repo's 23 red-team attacks are marked as expected failures on purpose, such as the employer's name spelled backwards or given as initials.
No pattern catches those. The system prompt does, and a live run against the real model checks that it still does. I'd rather show you the gap than pretend the guard is a wall.
Openly an AI, and It Stores Nothing
Two decisions shaped the twin more than any code.
It says it's an AI. My plan from July had the opposite rule: never admit it. I reversed that on 23 Nov 2026, two days before launch. Article 50(1) of the EU AI Act, which applies from 2 August 2026, requires that people "are informed that they are interacting with an AI system" (my reading, not legal advice). And a twin that denies being an AI hides the very thing it's there to show.
So the old guard got inverted. It used to block "I'm an AI". Now it blocks "I'm a real person" and "I'm Claude", and lets the truthful "I'm not human" through. The twin still says "my work". It never claims I'm the one typing.
It stores nothing. A live chat sits in RAM so the twin can follow the conversation, and it's forgotten after 30 idle minutes or at any restart. The database holds the knowledge base and its embeddings, never a chat. The logs carry no IP, no user agent and no chat text. A test runs a whole chat through the API and fails if any of those show up.

The price: I can't read what visitors asked, so I can't debug a bad answer from a transcript. All I get is counts and guard reasons. I took that trade gladly. The safest visitor data is the data you never had.
One Engine, Two Personas
The public repo is the engine that runs my twin, with a different person inside. Everything personal lives in a handful of files: the knowledge base, the prompt, the deny list, the canned lines and a few settings. Swap those, set one OpenRouter key, run make ci, and it's yours.
make ci is where the rules get teeth:
- 581 tests pass as of 30 Nov 2026, at 89% line coverage, with no API key: the agent runs against scripted models.
- The red team runs on every pull request against a scripted model that gives in to each attack, so a guard has to catch it. On demand, the same attacks go to the real model.
Open-sourcing paid for itself before anyone else had read a line. The pgvector store had one test, and it was skipped. When I wrote real ones against PostgreSQL, seven of eight failed: the store passed entry ids as strings into an integer column, so an app started on pgvector crashed. My live twin runs sqlite-vec, so I'd never have noticed.
Frequently Asked Questions
Is anything I type to the twin stored?
Not by the app. Your chat lives in RAM for up to 30 idle minutes. The only other trace is a message count against your IP for the daily cap, also in RAM, gone when the day rolls over. Your message does travel to the model provider to produce the reply.
Can someone jailbreak it?
Someone can always make a model say something silly. What limits the damage is what the twin can't do: it has exactly one tool, a read-only search over entries I wrote. The worst case is a wrong sentence, swapped out mid-stream if it trips a guard. There is no action to hijack.
What does it cost to run?
The caps are the answer. At most 200 messages a day counting both sides, each reply capped at 500 output tokens, on a small model with prompt caching on. Greetings and blocked inputs never reach the model.
Does it work in languages other than English?
Mine speaks English and Greek. One detail worth copying: the fixed employer line is written out in both languages. Left to translate it, the model once answered a Greek visitor in English.
A Twin You Can Read, Test and Switch Off
Here's the thing about a chatbot that carries your name: the model was never the product. Anyone can rent the same model. What's yours is the system around it, the part that decides what the model sees, what it may say and what is remembered afterwards. I've written before about why that harness matters more than the model inside it.
It's also why I published the code. If I ask visitors to trust what a machine says about me, the least I can do is show them the rules it runs under. A twin that speaks for you should be one you can read, test and switch off.
So go talk to it at stratoslouvaris.gr. Ask it about my projects, then ask it what it is. Then clone the repo and put yourself inside.
Trust isn't what the model promises. It's what the system can't do.
P.S. If you're ready to build your own twin, head over to the Digital Twin Chatbot repo on GitHub. Its DECISIONS.md explains why each piece exists and what broke before it did.
Don't miss out on future posts and exclusive content—subscribe to my free newsletter today.
Ready to connect or explore more? Head over to my LinkedIn profile