- The conversation
The console generates the conversation id itself, so the first message can stream before any round-trip. The core API then:
- reuses the conversation when the id exists and belongs to the caller,
- creates it with that id when it does not exist yet,
- refuses with 404 when the id exists but belongs to another member — a client can never take over, or even detect, someone else’s conversation.
agent.read; what the agent can then do is decided per tool.
- The model
LLM connections belong to a member, not to the workspace: each member connects their own providers in AI Studio, and the API key is stored encrypted under the workspace key. A run uses:
- the provider and model picked in the composer for this message, if any,
- otherwise the conversation’s connection,
- otherwise the member’s default model.
- The system context
The system context is assembled fresh for every run, in a fixed order — stable parts first, changing parts last — so providers that cache prompt prefixes can reuse most of it:
The history sent with it is pruned to the token budget, and summarized when it is too long. See Context and memory.
- The step loop
A run is a loop of steps. In each step the model receives the context, the history and the tool definitions, and returns text, reasoning and tool calls. Each tool call goes through the permission check, guard and approval gate, executes, and its result is fed into the next step.
- Step limit. A run stops after 50 steps by default; the member’s settings or the agent definition can change it. On the last allowed step the model gets no tools, so it must write an answer from what it has and say what is unfinished, instead of ending on a dangling tool call.
- Continuation. In Agent mode, a model that hits the limit while plan steps are still pending is not left mid-plan: the loop opens another iteration, with its own assistant message, as long as steps remain and the context budget allows, up to a hard ceiling of 50 iterations. Before each iteration, the context is compacted if it has grown past its budget.
- Subagent results. Results of subagents that finish while the run is going are handed to the model before its next step, so it never has to poll for them. Results that arrive after the run ended are delivered with the next message.
- Safety nets. If the model forgets to close the last plan step after answering, the run closes it. If the run fails, steps left in progress are reset to pending, so a retry picks them up instead of skipping them.
Timeouts
A provider that accepts a request and never answers would otherwise hang the run, so each step must produce its first output within 120 seconds. After that, chunks may be at most 30 seconds apart — or, when a call may be waiting for the user’s approval, the length of the approval window.
- Streaming
The response is a Server-Sent Events stream of AI SDK UI message chunks — text, reasoning, tool input and output — plus platform-specific data-* parts the console renders:
A run outlives its request
Closing the tab does not stop the agent. The core API keeps draining the stream after the client disconnects, and every chunk is also appended to a replay buffer in Redis. A client that reloads, or opens the conversation on another device, calls the resume endpoint: it replays the buffered chunks from the start of the run, then tails new ones live over Redis pub/sub until the run ends. The database stays the source of truth; the buffer only carries the answer still being streamed, and expires minutes after the run ends. Only two things stop a run: the Stop button (which also cancels the conversation’s pending and running subagents) or a new run started on the same conversation.
- Persistence
The assistant message is created as a placeholder marked streaming before the first token, and finalized as completed, stopped or failed — so a crash never leaves a message that claims to still be running. It stores:
- parts in their real order — reasoning, tool calls and text interleaved as they happened,
- tool calls in their own table, with arguments, result, duration and any policy that refused them,
- stats — input, output, reasoning and cached tokens, time to first token, and estimated cost.
Related
Context and memory
What the model sees, and how it is kept within the window
Guard and approvals
What happens to every tool call before it runs
Chat
The composer, modes and answers from the user’s side
