How vanna-ai/vanna works
Purpose and Entry Points
Vanna 2.0 is a Python framework for user-aware natural-language data agents: it turns questions into SQL-backed answers and streams structured UI components. Public package exports begin at src/vanna/__init__.py. Runnable examples are available through src/vanna/examples/__main__.py; server launching is exposed through src/vanna/servers/__main__.py. Applications typically embed Vanna into an existing FastAPI or Flask service.
Agent Orchestration
Agent is the central request orchestrator, coordinating identity, prompts, LLM calls, tool use, streaming, and recovery. Its configuration controls agent behavior and its default workflow defines the standard execution pipeline.
• src/vanna/core/agent/agent.py
• src/vanna/core/agent/config.py
• src/vanna/core/workflow/default.py
Identity, Authorization, and Request Boundaries
An incoming HTTP request is converted into a request context and resolved into a User; that identity propagates to tools and supports group-based authorization. Tool abstractions define executable, permission-aware capabilities and their input/result models. This is the primary security boundary between transport authentication and backend actions.
• src/vanna/core/user/resolver.py
• src/vanna/core/user/request_context.py
• src/vanna/core/tool/base.py
LLM, Context, and Memory Layer
The core defines provider-neutral LLM contracts, system prompts, enrichers, middleware, and agent memory capabilities. The agent uses these abstractions to assemble context and invoke a selected model; integrations supply concrete OpenAI, Anthropic, Azure OpenAI, Gemini, or local Ollama implementations. Vector/memory backends are independently swappable.
• src/vanna/core/llm/base.py
• src/vanna/core/enricher/base.py
• src/vanna/capabilities/agent_memory/base.py
• src/vanna/integrations/openai/llm.py
Tools and Data Execution
Tools translate model-directed actions into controlled operations. Built-ins include SQL execution, Python, filesystem, memory, and visualization. SQL runners form the database boundary, allowing engines such as SQLite, PostgreSQL, Snowflake, BigQuery, MySQL, and others; implementations should enforce user-aware filtering/authorization at this layer where required.
• src/vanna/tools/run_sql.py
• src/vanna/capabilities/sql_runner/base.py
• src/vanna/integrations/sqlite/sql_runner.py
Streaming API and Presentation Model
Server adapters expose chat handlers and framework routes, delivering streamed rich components rather than only text. Components represent tables, charts, status/progress, cards, and interactions; chart generation is available through Plotly integration. FastAPI and Flask are alternate HTTP runtimes, not required application hosts.
• src/vanna/servers/base/rich_chat_handler.py
• src/vanna/servers/fastapi/routes.py
• src/vanna/components/rich/data/dataframe.py
• src/vanna/components/rich/data/chart.py
Web Component and External Interfaces
The optional TypeScript web component consumes the backend streaming API and renders <vanna-chat> in arbitrary web frameworks. Its API client is the frontend/backend protocol boundary. External infrastructure is selected through integrations: LLM APIs, SQL databases, vector stores (Chroma, Pinecone, Qdrant, Weaviate, Azure Search, etc.), and local persistence/audit/storage implementations.
• frontends/webcomponent/src/components/vanna-chat.ts
• frontends/webcomponent/src/services/api-client.ts
• src/vanna/integrations/
• src/vanna/integrations/local/audit.py
Operational Extension Points and Compatibility
Lifecycle hooks, audit, observability, validation, storage, and recovery provide production control points around the agent workflow. Registries/component management enable composition. The legacy subtree and adapter preserve migration paths from Vanna 0.x, separated from the 2.0 core.
• src/vanna/core/lifecycle/base.py
• src/vanna/core/observability/base.py
• src/vanna/core/registry.py
• src/vanna/legacy/adapter.py
Main entry points: agent.py Agent · default.py Default workflow · resolver.py User resolver · rich_chat_handler.py Rich chat handler
Components 24
Vanna Core
Framework contracts and agent workflow.
- Package exports
src/vanna/__init__.py - Agent configuration
src/vanna/core/agent/config.py - Agent · Coordinates identity, context, model calls, tools, streaming, and recovery.
src/vanna/core/agent/agent.py - Default workflow
src/vanna/core/workflow/default.py - Request context
src/vanna/core/user/request_context.py - User resolver
src/vanna/core/user/resolver.py - LLM contract
src/vanna/core/llm/base.py - Context enrichers
src/vanna/core/enricher/base.py - Agent memory · Swappable memory and vector backends.
src/vanna/capabilities/agent_memory/base.py
Execution & Integrations
Controlled tool execution and pluggable backends.
- Tool abstractions · Defines executable capabilities and input/result models.
src/vanna/core/tool/base.py - Run SQL tool
src/vanna/tools/run_sql.py - SQL runner contract · Backend implementations enforce user-aware data access where needed.
src/vanna/capabilities/sql_runner/base.py - SQLite runner
src/vanna/integrations/sqlite/sql_runner.py - Integration catalog · Supplies LLM, SQL, vector, storage, and other concrete providers.
- OpenAI LLM
src/vanna/integrations/openai/llm.py
Streaming Delivery
HTTP adapters and rich response model.
- Rich chat handler · Streams structured chat components.
src/vanna/servers/base/rich_chat_handler.py - FastAPI routes · Alternate server runtime for embedding or standalone delivery.
src/vanna/servers/fastapi/routes.py - Rich data components · Tables, charts, status, cards, and interactions.
src/vanna/components/rich/data/dataframe.py - Chart component
src/vanna/components/rich/data/chart.py
Optional Web Client
- vanna-chat · Optional embeddable TypeScript chat UI.
frontends/webcomponent/src/components/vanna-chat.ts - API client · Frontend/backend streaming protocol boundary.
frontends/webcomponent/src/services/api-client.ts
Operations & Compatibility
Production extension points and migration support.
- Lifecycle & observability · Production lifecycle, audit, validation, and recovery controls.
src/vanna/core/lifecycle/base.py - Registry
src/vanna/core/registry.py - Legacy adapter · Separates Vanna 0.x migration paths from the 2.0 core.
src/vanna/legacy/adapter.py
Connections 25
- Package exports → Agent: exports
- Agent configuration → Agent: configures
- Agent → Default workflow: runs
- Request context → User resolver: resolves identity
- User resolver → Agent: supplies user
- Default workflow → Context enrichers: builds context
- Context enrichers → Agent memory: uses
- Default workflow → LLM contract: invokes
- OpenAI LLM → LLM contract: implements
- Integration catalog → OpenAI LLM: includes
- Default workflow → Tool abstractions: executes tools
- User resolver → Tool abstractions: authorizes actions
- Run SQL tool → Tool abstractions: implements
- Run SQL tool → SQL runner contract: queries through
- SQLite runner → SQL runner contract: implements
- Integration catalog → SQLite runner: includes
- Agent → Rich chat handler: streams responses
- FastAPI routes → Rich chat handler: exposes
- Rich chat handler → Rich data components: emits
- Chart component → Rich data components: extends
- vanna-chat → API client: uses
- API client → FastAPI routes: streams with
- Lifecycle & observability → Agent: hooks around
- Registry → Agent: composes
- Legacy adapter → Agent: migrates to