Concepts
How it works
What you will learn: the journey of one message, from the visitor to the answer.
The big picture#
text
Browser (your page)
│ 1. The visitor types or speaks
▼
Your server (speeq handler)
│ 2. Loads recent history from your store
│ 3. Asks your model what to do
▼
Your model ──► "Run the tool find_order" or "Say this reply"
│
▼
Your tools and data (checked, with the visitor's permissions)
│
▼
Back to the browser, streaming: text, page opens, approvalsOne turn, step by step#
- The visitor says something. The browser sends the text, the language, and what page the visitor is on. The first message also creates a session.
- Your server wakes up. It checks the session, then loads the recent conversation from your database.
- The model decides. speeq sends your instructions, the history, and the list of tools to the model.
- Text streams back. As the model writes, the words flow to the page a few at a time.
- The model may ask for a tool. Your server checks the input, runs your function with the current user's permissions, and gives the result to the model. The model may then use another tool, open a page, or write the final answer.
- Changes ask first. If a tool changes data, the turn pauses and the visitor sees an Approve or Reject choice.
- Everything is saved. Each step is written to your store as an event.
Why the server remembers nothing#
Your database is the memory. Each turn loads history from the store, so any server copy can answer any request. This also gives you the audit log for free.
The messages the browser receives#
The server sends a stream of small events. The most useful ones:
| Event | Meaning |
|---|---|
assistant.delta |
A few more words of the answer |
assistant.message |
The full finished message |
tool.started / tool.finished |
A tool began or ended |
navigate |
Open this page |
confirmation.required |
Ask the visitor to approve a change |
turn.finished |
The turn is over, with the reason |
The React hooks turn these into simple values like messages and pendingConfirmation. The full list is in the HTTP protocol.