Complete collection of examples demonstrating all features of the SDK, organized from basic to advanced.
# Install dependencies
npm install
# Run any example
npx tsx 01-basic/01-simple-agent.ts
# Or use the universal runner
npx tsx run.ts 01Perfect for beginners. Learn the fundamentals.
| File | Description | Key Concepts |
|---|---|---|
| 01-simple-agent.ts | Basic conversational agent | Agent creation, run() |
| 02-agent-with-tools.ts | Adding capabilities | Tools, parallel execution |
| 03-multi-agent.ts | Agent coordination | Handoffs, specialization |
| 04-sessions.ts | Conversation memory | Sessions, context |
Intermediate features for production apps.
| File | Description | Key Concepts |
|---|---|---|
| 05-guardrails.ts | Safety and validation | Input/output guardrails |
| 06-streaming.ts | Real-time responses | Streaming, events |
| 07-tracing.ts | Observability | Langfuse, debugging |
Advanced patterns and integrations.
| File | Description | Key Concepts |
|---|---|---|
| 09-embeddings-rag.ts | Semantic search | Embeddings, RAG |
| 10-vision.ts | Image understanding | Vision models, multimodal |
| 11-toon-format.ts | Token optimization | TOON format, efficiency |
| 12-mcp-integration.ts | Model Context Protocol | MCP servers, tool discovery |
| 13-dynamic-approvals.ts | Human-in-the-loop | Approvals, safety |
| 14-multi-agent-research.ts | Complex coordination | Research patterns |
Complete production-ready systems.
| File | Description | Key Concepts |
|---|---|---|
| 15-ecommerce-system.ts | E-commerce assistant | Full system, workflows |
| 16-complete-showcase.ts | All features | Comprehensive demo |
Proven agentic patterns and architectures.
| File | Description | Key Concepts |
|---|---|---|
| 17-agentic-patterns.ts | Agentic design patterns | Architecture, best practices |
- 01-simple-agent.ts → Learn basic agent creation
- 02-agent-with-tools.ts → Add capabilities
- 03-multi-agent.ts → Agent coordination
- 04-sessions.ts → Add memory
- 05-guardrails.ts → Add safety
- 06-streaming.ts → Real-time UX
- 07-tracing.ts → Observability
- 09-embeddings-rag.ts → Semantic search
- 12-mcp-integration.ts → Tool discovery
- 13-dynamic-approvals.ts → HITL safety
- 15-ecommerce-system.ts → Full system
npx tsx 01-basic/01-simple-agent.ts# Run by number
npx tsx run.ts 01
# Run by name
npx tsx run.ts simple-agent
# List all examples
npx tsx run.ts --list# Auto-reload on changes
npx tsx watch 01-basic/01-simple-agent.tsCreate a .env file:
# Required
OPENAI_API_KEY=sk-...
# Optional
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_AI_API_KEY=...
LANGFUSE_PUBLIC_KEY=pk-...
LANGFUSE_SECRET_KEY=sk-...- all-features.ts - Comprehensive feature reference
- run.ts - Universal example runner
- STRUCTURE.md - Detailed structure documentation
Create a basic agent:
const agent = new Agent({
name: 'Assistant',
model: openai('gpt-4o-mini'),
instructions: 'You are helpful.',
});
const result = await run(agent, 'Hello!');Add tools:
const tool = tool({
description: 'Calculate',
inputSchema: z.object({ expr: z.string() }),
execute: async ({ expr }) => eval(expr)
});Multi-agent coordination:
const coordinator = new Agent({
subagents: [specialist1, specialist2]
});Add memory:
const session = new MemorySession('user-id');
await run(agent, 'Hello', { session });Want to add an example? Follow the structure:
- Create file with number prefix (e.g.,
08-my-example.ts) - Add clear comments explaining what and why
- Keep it focused on ONE concept
- Update this README
- All examples use TypeScript
- Examples are self-contained and runnable
- Check
utils/folder for shared helpers - Examples use
gpt-4o-miniby default (change if needed)
Ready to start? Begin with 01-basic/01-simple-agent.ts! 🚀