Cookbook
Run the example path from first text call to Studio and integrations.
The cookbook is the runnable companion to the guides. Use it when you want to verify a concept from the command line before adapting it into product code.
Each level introduces one layer at a time:
| Level | Focus |
|---|---|
| Basics | Text calls, chat history, static context, streaming, and ReadableStream output |
| Tools | Tool calls, streamed tool events, hooks, concurrency, conditional tools, application state, guarded tools, and dynamic tool selection |
| Structured output | Extraction, output schemas, context, retries, and extraction with history |
| Providers and multimodal | Provider adapters, model capabilities, model listing, reasoning streams, attachments, image generation, audio generation, and transcription |
| Pipelines | Step transforms, composition, named parallel branches, batching, agents, extraction, and richer workflows |
| Retrieval | Embeddings, vector search, metadata filters, RAG context, document loaders, vector stores, and embedding provider variants |
| Multi-agent | Basic agent-tools, pipeline-backed parallel specialists, streaming agent-tools, and event stores |
| Evals | Deterministic metrics, semantic similarity, custom metrics, agent eval targets, and LLM judge/score |
| Studio | Single-agent, multi-agent, and subagent runners, tool approvals, questions, and Knowledge inspection |
| Integrations | MCP tools, local skills, Langfuse tracing, and Langfuse eval reporting |
1. Install Dependencies
From the repository root:
pnpm installCreate a local .env file for examples that call provider APIs:
OPENAI_API_KEY=...
OPENAI_BASEURL=...
ANTHROPIC_API_KEY=...
GEMINI_API_KEY=...
MISTRAL_API_KEY=...Anvia clients still receive credentials explicitly in code. The cookbook uses dotenv only as a local configuration source.
2. Run the First Example
pnpm cookbook:basics:01That runs examples/cookbook/01_basics/01-text-call.ts.
3. Follow the Path
Run the default example for each level:
pnpm cookbook:basics
pnpm cookbook:tools
pnpm cookbook:structured-output
pnpm cookbook:providers
pnpm cookbook:pipelines
pnpm cookbook:retrieval
pnpm cookbook:multi-agent
pnpm cookbook:evals
pnpm cookbook:studio
pnpm cookbook:integrationsNumbered scripts are available when you want to step through a level in order:
pnpm cookbook:tools:01
pnpm cookbook:pipelines:04
pnpm cookbook:retrieval:05
pnpm cookbook:studio:06
pnpm cookbook:integrations:04Legacy names such as cookbook:basic:05, cookbook:intermediate:14, cookbook:pipeline:04, cookbook:rag:05, and cookbook:multimodal:03 remain available as aliases.
4. Use Chroma Examples
Start ChromaDB before running the Chroma-backed RAG examples:
docker compose -f examples/cookbook/compose.cookbook.yml up -d
pnpm cookbook:retrieval:05
pnpm cookbook:retrieval:06
pnpm cookbook:retrieval:07
pnpm cookbook:retrieval:08Use the in-memory and Transformers examples when you do not need a separate vector database.
5. Map Examples to Guides
| Goal | Cookbook | Guide |
|---|---|---|
| Add a tool | tools:01 | Add Tools |
| Return structured data | structured-output:01, structured-output:02 | Structured Output |
| Inspect model capabilities | providers:03 | Provider Clients and Models |
| List provider models | providers:10 | Model Listing |
| Stream agent events | tools:02 | Streaming Events |
| Render reasoning summaries | providers:04 | Streaming Events |
| Select dynamic tools | tools:09 | Tool Sets |
| Add approval behavior | tools:08, studio:03 | Human in the Loop |
| Add retrieval | retrieval:01 through retrieval:06 | Add Retrieval |
| Run evals | evals:01 through evals:05, integrations:04 | Evals |
| Generate or transcribe media | providers:07 through providers:09 | Image Generation |
| Inspect locally in Studio | studio:01, studio:05, studio:06 | Run Studio |
Before changing public APIs, add or update a cookbook example so behavior is easy to verify from the command line.
