Back to docs

Agents & sessions

When you send a message, Zod runs a real agent loop in your browser: it talks to your provider, executes tool calls on your machine, and streams back a rich, structured reply. The same loop powers chat, the scheduler, background agents, and agent runs.

How the agent loop works

Sending a message starts a four-step loop:

1

Build the message history

Zod flattens the current session's user and assistant messages into the OpenAI message shape, embedding any attached file contents as ### File: blocks.

2

Call the provider with all tool schemas

The request goes to your configured provider with the full set of built-in tool schemas offered as function calls.

3

Execute tool calls in the browser

If the model requests tool calls, Zod runs them locally — calculator, memory, timers, MCP tools, and more — and feeds the results back, repeating up to 6 rounds.

4

Stream the final answer

The final reply streams into the chat and is rendered as structured cards when the model uses section markers.

Up to 6 rounds

The tool loop repeats up to 6 rounds: send messages plus tool schemas, execute any requested tool calls locally, append the results, and call again. The same shared loop (runAgentChat) is used by chat, the scheduler, background agents, and agent steps — so agents behave consistently everywhere.

Structured output

The default system prompt instructs the model to optionally emit lightweight [section] markers. Zod parses each one and renders it as a distinct UI card. If no markers are present, the text passes through untouched.

Marker Rendered as
[thinking] Collapsible "Thinking" step list
[badges] Colored status chips (#info, !error, $secondary, @primary)
[findings] Findings list with success / info / error status dots
[suggestions] Clickable suggested next-step buttons that send the prompt
[todos] Checklist with checkboxes and strikethrough
[code:lang] Syntax-labeled code block
[file] / [files] File chip(s)
[error:type] Styled error card
[security-warning] Red warning banner
[tool:name] Agent tool result block
[confirmation] Approve / Reject plan card with tool checklist
[task-completed] Green "Task completed" pill
[team-feedback] Multi-agent feedback avatars
[viz] Inline bar-chart visualization
[html] Rendered HTML (DaisyUI/Tailwind classes)
[divider] Horizontal rule

Background agents

Scheduled work keeps running even when you close the tab. A classic service worker runs the scheduler in the background, side-by-side with the offline cache.

Mirrors state

The app snapshots its localStorage document into an IndexedDB store (zod-bg) on every save, so the worker always sees the latest settings, sessions, memory, and crons.

Runs due crons

The worker ticks every 2 seconds and runs due crons (bare prompts or agent harnesses) through the full agent loop against your configured provider.

Concurrent agents

Up to 3 cron runs execute in parallel, so multiple scheduled agents work simultaneously.

Writes results back

The worker pushes session, message, and cron-status updates to an IndexedDB outbox. When the app is reopened or focused, the page imports those rows — new sessions, assistant messages, and status updates — with no reload needed.