Sequence Diagrams
Concrete, step-by-step sequence diagrams for Anvio's most important flows — web chat, the tool loop, runtime OAuth routing, and memory provider selection.
4 min read
Purpose
High-Level Architecture shows the static shape of the system; Data Flow and Event Flow describe the mechanics in prose and flowcharts. This page collects the concrete sequence diagrams for reference when you need to trace exact call order.
Web Chat flow
The full-stack path when a message arrives over the WebSocket gateway rather than the CLI:
This is the same flow summarized in the unified gateway's single-daemon description: one process serves the Channel Hub, the agent worker, the REST API, and the WebSocket gateway together (anvio gateway start, default port 3001).
Tool loop (agent using a built-in tool)
Applies to anvio chat --agent <name> and anvio run <agent> <message>. Native tool_use is used for Anthropic, OpenAI, and Gemini providers; other providers rely on fenced ```anvio_tool``` blocks that the tool gateway parses out of the model's text response.
Runtime provider routing (vendor OAuth vs. local)
This models runtime.fallbacks: [cursor, codex, local] in an agent's frontmatter — the chain walks left to right and retries on auth failure mid-run (expired OAuth, 401), not just at startup.
Memory provider selection
Every memory provider (filesystem, SQLite, PostgreSQL, Qdrant, Honcho, or a custom plugin) implements the same MemoryProvider port, so switching providers is a config change plus a restart — no code changes, no migration script required for the interchangeability contract itself (though moving existing data between providers uses the optional migrate() method).
Not yet shipped
Qdrant is documented as a Phase 2/Level 3 memory provider (ADR 0004). Confirm it's wired up in your version of the repo before depending on it — the port and factory pattern exist, but semantic/vector memory is not part of the Level 1 default path.
Approval workflow
Implied by the runtime state machine (awaiting_approval state) described in Data Flow:
Best practices
- When debugging a flow, identify which diagram on this page it maps to first — most issues are a mismatch between expected and actual step order (e.g., a tool call that never returns, an OAuth chain that isn't falling back as expected).
- Use
anvio session export <id> --mdto get an actual trajectory export you can diff against the expected sequence for a given run. - For runtime routing issues specifically, use
anvio runtime test <provider>to isolate whether a single link in the fallback chain (not the whole chain) is misconfigured.
Common mistakes
- Assuming the tool loop retries indefinitely. It's capped at 5 model round-trips per turn.
- Expecting the runtime fallback chain to retry on every kind of error. It's specifically auth-failure-triggered failover (expired OAuth, 401), not a general retry-on-any-error policy.
- Skipping
healthCheck()after switching memory providers. The factory calls it during initialization — if a newly configured provider (e.g., Qdrant, PostgreSQL) isn't reachable, this is where you'll see the failure surface.
References
Last updated on