README
ΒΆ
Agenkit Examples
Comprehensive collection of 285 examples across 6 languages (including WASM!) demonstrating all Agenkit features, patterns, and integrations.
π― Start Here
New to Agenkit? Follow this path:
- 01_basic_agent.py - Your first agent
- 02_sequential_pattern.py - Composing agents
- 03_parallel_pattern.py - Parallel execution
- 05_tool_usage.py - Adding tools
- 06_pattern_composition.py - Complex patterns
Want structured learning? Check out our Tutorials with Jupyter and Marimo notebooks!
π Quick Stats
| Language | Examples | Status |
|---|---|---|
| Python | 156 | β Complete |
| Rust | 35 | β Complete (+ WASM!) |
| C++ | 42 | β Complete |
| Zig | 37 | β Complete |
| Go | 7 | β οΈ Growing |
| TypeScript | 8 | β οΈ Growing |
| Total | 285 |
π Examples by Category
π§ Core Patterns (11 examples)
The 11 foundational agent patterns from the Agenkit library.
Location: patterns/
| Pattern | Description | Python | Go | TS |
|---|---|---|---|---|
| ReAct | Reasoning + Acting loop | β | β | β |
| Reflection | Self-critique and improvement | β | β | β |
| Agents-as-Tools | Agents calling other agents | β | β | β |
| Orchestration | Coordinate multiple agents | β | β | β |
| Conversational | Stateful conversations | β | β | β |
| Task | Goal-oriented execution | β | β | β |
| Multiagent | Parallel agent collaboration | β | β | β |
| Planning | Multi-step planning | β | - | - |
| Autonomous | Self-directed agents | β | - | - |
| Memory Hierarchy | Tiered memory system | β | - | - |
| Reasoning with Tools | Tool-augmented reasoning | β | - | - |
Key Files:
patterns/react-pattern.py- Reason, Act, Observe looppatterns/reflection-pattern.py- Self-improvement cyclepatterns/orchestration-pattern.py- Multi-agent coordinationpatterns/multiagent-pattern.py- Parallel collaboration
π¨ Advanced Reasoning Techniques (6 examples)
Cutting-edge reasoning methods for complex problem-solving.
Location: techniques/reasoning/
| Technique | Description | File |
|---|---|---|
| Chain-of-Thought (CoT) | Step-by-step reasoning | cot_example.py |
| Tree-of-Thought (ToT) | Multi-path exploration | tot_example.py |
| Self-Consistency (SC) | Voting for reliability | sc_example.py |
| Graph-of-Thought (GoT) | Graph-based reasoning | got_example.py |
| Least-to-Most (LTM) | Decomposition strategy | ltm_example.py |
| Plan-and-Solve | Planning before execution | plan_and_solve_example.py |
Use Cases:
- Complex problem decomposition
- Multi-step reasoning
- Uncertainty handling
- Strategic planning
Learn More: Tutorial 03: Advanced Reasoning
π‘οΈ Production Middleware (8 examples)
Production-ready middleware for reliability, performance, and observability.
Location: middleware/
| Middleware | Purpose | File |
|---|---|---|
| Retry | Exponential backoff | retry_example.py |
| Circuit Breaker | Fail-fast pattern | circuit_breaker_example.py |
| Timeout | Request deadlines | timeout_example.py |
| Caching | LRU cache with TTL | caching_example.py |
| Metrics | Prometheus metrics | metrics_example.py |
| Rate Limiter | Token bucket | rate_limiter_example.py |
| Batching | Request batching | batching_example.py |
| Per-User Rate Limiter | User-specific limits | per_user_rate_limiter_example.py |
Key Features:
- Stack multiple middleware
- Zero-configuration defaults
- Production-tested patterns
- Full observability
Learn More: Tutorial 02: Production Patterns
π§ Composition Patterns (4 examples)
Compose agents into complex workflows.
Location: composition/
- Sequential: Pipeline processing (
sequential_example.py) - Parallel: Concurrent execution (
parallel_example.py) - Fallback: Graceful degradation (
fallback_example.py) - Conditional: Dynamic routing (
conditional_example.py)
Advanced Compositions: patterns/composition/
sequential-parallel.py- Hybrid workflowsrouter-supervisor.py- Routing + supervision
π Transport Layer (2 examples)
Network protocols for distributed agents.
Location: transport/
- gRPC: High-performance RPC (
grpc_example.py) - WebSocket: Real-time bidirectional (
websocket_example.py)
Cross-Language:
e2e/cross-language-system/- Python β Go β TypeScript
π LLM Adapters (9 examples)
Connect to any LLM provider.
Locations:
| Adapter | Provider | Files |
|---|---|---|
| OpenAI | GPT-4, GPT-3.5 | openai-basic.py, openai_example.py |
| Anthropic | Claude 3.5 | anthropic-basic.py, anthropic_example.py |
| Ollama | Local models | ollama-basic.py |
| LiteLLM | 100+ providers | litellm_providers.py |
| Remote | HTTP API | 01_basic_remote_agent.py |
Advanced Features:
- Streaming:
streaming_example.py,03_streaming.py - Provider Swapping:
swapping_providers.py - Agent + LLM:
agent_with_llm.py
Pattern Integration:
patterns/llm-integration/patterns-with-openai.pypatterns/llm-integration/patterns-with-anthropic.py
π§° Tools (3 examples)
Extend agents with external capabilities.
Location: tools/
- Database: SQL operations (
database_example.py) - Search: Web search integration (
search_example.py) - OS Tools: File system, shell commands (
os_tools_example.py)
Example: 05_tool_usage.py
π Safety & Permissions (4 examples)
Secure agents with validation and permissions.
Location: safety/
- Input Validation: Sanitize user input (
01_input_validation.py) - Output Validation: Filter agent responses (
02_output_validation.py) - Permissions: Fine-grained access control (
03_permissions.py) - Complete Stack: Production security setup (
04_complete_safety_stack.py)
Features:
- Content filtering
- PII detection
- Prompt injection defense
- Rate limiting
- Audit logging
π Authentication (1 example)
Secure agent communications.
Location: auth/
- Bearer Token: HTTP authentication (
bearer_token_example.py)
π§ Routing (2 examples)
Intelligent request routing.
Location: routing/
- Semantic Tool Selection: Embedding-based routing (
semantic_tool_selection_example.py) - Load Balancer: Distribute requests (
load_balancer_example.py)
πΎ Memory (1 example)
Stateful agents with memory.
Location: memory/
- Conversational Agent: Context-aware conversations (
conversational_agent.py)
See also: patterns/memory-hierarchy-pattern.py
π° Budget & Cost Tracking (2 examples)
Monitor and control LLM costs.
Location: budget/
- Cost Tracking: Monitor spending (
cost_tracking_demo.py) - Extended Thinking: Token budget management (
extended_thinking_demo.py)
πΎ Checkpointing (1 example)
Durable agents with state persistence.
Location: checkpointing/
- Durable Agent: Save/restore agent state (
durable_agent_demo.py)
π Observability (1 example)
Monitor agents with OpenTelemetry.
Location: observability/
- Full Stack: Tracing + Metrics + Logging (
observability_example.py)
Features:
- Distributed tracing
- Prometheus metrics
- Structured logging
- Grafana dashboards
Learn More: Tutorial 04: Deployment
π§ͺ Evaluation & Testing (3 examples)
Test, optimize, and compare agents.
Location: evaluation/
- Evaluation Demo: Quality metrics (
evaluation_demo.py) - A/B Testing: Compare agent versions (
ab_testing_demo.py) - Optimization: Hyperparameter tuning (
optimization_demo.py)
Learn More: Tutorial 05: Testing Patterns
π Pattern Usage Examples (7 examples)
Real-world pattern usage.
Location: patterns/usage/
sequential-usage.py- Sequential pipelinesparallel-usage.py- Parallel executionfallback-usage.py- Error handlingrouter-usage.py- Dynamic routingsupervisor-usage.py- Supervised agentscollaborative-usage.py- Agent collaborationhuman-in-loop-usage.py- Human feedback
π§ͺ Experimental Patterns (1 example)
Cutting-edge research implementations for validation and experimentation.
Location: experimental/
Recursive Language Models (RLM)
Directory: experimental/long_context_rlm/
Status: β οΈ EXPERIMENTAL - Research validation, not production ready
Novel inference strategy from Zhang et al. (2025) that treats long contexts as external environment variables accessed programmatically via REPL.
Key Features:
- Code Execution: Python REPL for context manipulation
- Recursive Sub-calls:
llm_query()function for delegating to sub-agents - Budget Protection: CostTracker + BudgetLimiter integration (high cost variance!)
- Pattern Composition: Combines ReasoningWithTools, AgentTool, ReAct, BudgetLimiter
Paper Results:
- BrowseComp+: 0% β 91% success rate
- OOLONG: 0.04% β 58% success rate
- Cost: Median comparable to baselines, 95th percentile 3-10x higher
Files:
basic_rlm.py- Core RecursiveREPLAgent implementation (364 LOC)document_qa.py- Multi-document QA example (180 LOC)test_with_api.py- Real API testing with budget protectiontest_with_api_simple.py- Minimal test for debuggingAPI_TEST_RESULTS.md- Validation results with Anthropic ClaudeANALYSIS.md- Gap analysis and design decisionstests/test_rlm_basic.py- 9 unit tests (all passing β )
Real API Test Results:
- β Code execution works
- β Recursive sub-calls work (llm_query())
- β Budget protection works
- β οΈ Prompt engineering needed (models not trained for RLM pattern)
Future Work: See Issue #473 for prompt engineering roadmap
Learn More:
- RLM README
- API Test Results
- Research Paper - Zhang et al., 2025
π Complete Applications (5 E2E examples)
Production-ready applications demonstrating full system architecture.
Location: e2e/
1. Code Review System
Directory: e2e/code-review/
Multi-agent code review with specialized reviewers.
Agents:
correctness_agent.py- Logic validationperformance_agent.py- Performance analysissecurity_agent.py- Security scanningstyle_agent.py- Style checkingsynthesis_agent.py- Report generation
Orchestration: review_orchestrator.py
Total: 7 files
2. Customer Support System
Directory: e2e/customer-support/
RAG-based support with escalation.
Agents:
classifier.py- Intent classificationqa_agent.py- Q&A with knowledge baseescalation_agent.py- Human handoffsynthesis_agent.py- Response generation
Knowledge Base: vector_store.py
Total: 7 files
3. Research Assistant
Directory: e2e/research-assistant/
Multi-source research with memory.
Agents: research_agent.py
Memory: memory_store.py (hierarchical memory)
Tools: tool_registry.py (search, summarize, analyze)
Total: 6 files
4. LLM Optimizer
Directory: e2e/llm-optimizer/
Automatic prompt and model optimization.
Features:
- Classification task optimization
- Model selection (GPT-4, Claude, etc.)
- Prompt tuning
- A/B testing
Total: 3 files
5. Cross-Language System
Directory: e2e/cross-language-system/
Python orchestrator coordinating Go and TypeScript agents.
Architecture:
- Python:
orchestrator.py(coordination) - Go: gRPC services
- TypeScript: WebSocket services
Total: 3 files (Python)
π Multi-Language Examples
Rust Examples (35 files) β¨
Location: agenkit-rust/examples/
Full pattern coverage with evaluation framework:
- All 11 core patterns (ReAct, Reflection, Orchestration, etc.)
- 7 pattern usage examples
- 8 evaluation examples (A/B testing, Bayesian optimization, etc.)
- LLM adapters (OpenAI, Anthropic, Ollama, LiteLLM, Gemini, Bedrock)
- HTTP transport
- WASM support!
wasm_browser_agent.html- Run agents in the browser
Why Rust?
- Memory safety without garbage collection
- Zero-cost abstractions
- Excellent performance
- Native WASM compilation for browser deployment
C++ Examples (42 files)
Location: agenkit-cpp/examples/
Full pattern coverage organized by category:
- All 11 core patterns
- Multiple adapters (OpenAI, Anthropic, etc.)
- Evaluation framework
- Integration examples
- Production-ready error handling
Why C++?
- Maximum performance for latency-sensitive applications
- Systems programming capabilities
- Existing C++ codebase integration
- Fine-grained memory control
Zig Examples (37 files)
Location: agenkit-zig/examples/
Modern systems programming with full pattern coverage:
- All 11 core patterns
- Evaluation framework
- Observability integration
- LLM adapters
- Integration examples
Why Zig?
- Modern, simple syntax
- C interoperability
- Compile-time execution
- Memory safety with manual control
Go Examples (7 files)
Location: go/
Reasoning techniques:
- Chain-of-Thought (CoT)
- Tree-of-Thought (ToT)
- Self-Consistency (SC)
- Graph-of-Thought (GoT)
Full implementation: agenkit-go/examples/
Why Go?
- Simple concurrency with goroutines
- Fast compilation
- Excellent for microservices
- Native gRPC support
TypeScript Examples (8 files)
Location: typescript/
Reasoning techniques + browser integrations:
Browser Examples: browser/
- React:
browser/react-example/ - Vue:
browser/vue-example/ - Svelte:
browser/svelte-example/ - Astro:
browser/astro-example/
Full implementation: agenkit-ts/examples/
Why TypeScript?
- Full-stack (Node.js + browser)
- Type safety for JavaScript
- Rich ecosystem
- Web framework integration
πΊοΈ Learning Paths
Path 1: Beginner (1-2 hours)
Perfect for first-time users.
- Basic Agent β
01_basic_agent.py - Sequential Pattern β
02_sequential_pattern.py - Parallel Pattern β
03_parallel_pattern.py - Tool Usage β
05_tool_usage.py - LLM Integration β
llm/openai_example.py
Next: Tutorial 01: Getting Started
Path 2: Production Engineer (2-3 hours)
For building production systems.
-
Middleware Stack:
middleware/retry_example.pymiddleware/circuit_breaker_example.pymiddleware/caching_example.pymiddleware/metrics_example.py
-
Safety:
safety/04_complete_safety_stack.py
-
Observability:
observability/observability_example.py
-
E2E Application:
e2e/customer-support/(complete system)
Next: Tutorial 02: Production Patterns
Path 3: AI Researcher (2-3 hours)
For advanced reasoning and experimentation.
-
Core Patterns:
patterns/react-pattern.pypatterns/reflection-pattern.pypatterns/orchestration-pattern.py
-
Reasoning Techniques:
techniques/reasoning/cot_example.pytechniques/reasoning/tot_example.pytechniques/reasoning/sc_example.py
-
Evaluation:
evaluation/ab_testing_demo.pyevaluation/optimization_demo.py
Next: Tutorial 03: Advanced Reasoning
Path 4: Full-Stack Developer (3-4 hours)
For multi-language and distributed systems.
-
Transport Layer:
transport/grpc_example.pytransport/websocket_example.py
-
Adapters:
adapters/01_basic_remote_agent.pyadapters/03_streaming.py
-
Cross-Language:
e2e/cross-language-system/
-
Browser Integration:
browser/react-example/
Next: Tutorial 04: Deployment
π― Examples by Use Case
Building a Chatbot?
patterns/conversational-pattern.py- Stateful conversationsmemory/conversational_agent.py- Memory managementllm/streaming_example.py- Streaming responsese2e/customer-support/- Complete support bot
Code Analysis?
patterns/react-pattern.py- Reasoning about codepatterns/reflection-pattern.py- Self-improvemente2e/code-review/- Multi-agent code review
Research & Analysis?
techniques/reasoning/cot_example.py- Chain-of-Thoughttechniques/reasoning/tot_example.py- Tree-of-Thoughte2e/research-assistant/- Full research system
Production Deployment?
middleware/retry_example.py- Reliabilitymiddleware/circuit_breaker_example.py- Fail-fastobservability/observability_example.py- Monitoringsafety/04_complete_safety_stack.py- Security- Tutorial 04: Deployment - Docker + K8s
Browser/WASM Deployment?
- Rust WASM Example - Run agents in browser
browser/react-example/- React integrationbrowser/vue-example/- Vue integrationbrowser/svelte-example/- Svelte integration
Why WASM?
- Run AI agents directly in the browser (no server required)
- Near-native performance
- Privacy-preserving (data never leaves device)
- Offline-capable applications
- Cross-platform (desktop, mobile, web)
π Quick Start
Run an Example
# Clone repository
git clone https://github.com/scttfrdmn/agenkit.git
cd agenkit/examples
# Install dependencies
pip install agenkit
# Set API keys (for LLM examples)
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
# Run basic example
python 01_basic_agent.py
# Run pattern example
python patterns/react-pattern.py
# Run E2E application
cd e2e/customer-support
python main.py
Explore by Category
# Patterns
cd patterns && ls *.py
# Reasoning techniques
cd techniques/reasoning && ls
# Middleware
cd middleware && ls
# E2E applications
cd e2e && ls -d */
π Related Resources
Documentation
Tutorials
- Getting Started - First agent
- Production Patterns - Middleware
- Advanced Reasoning - CoT, ToT, SC
- Deployment - Docker, K8s, CI/CD
- Testing Patterns - Testing guide
Migration & Integration
More Examples
- Python: agenkit/examples/
- Go: agenkit-go/examples/
- TypeScript: agenkit-ts/examples/
- Rust: agenkit-rust/examples/
- C++: agenkit-cpp/examples/
- Zig: agenkit-zig/examples/
π Example Complexity Matrix
| Category | Beginner | Intermediate | Advanced | Production |
|---|---|---|---|---|
| Patterns | β ReAct, Conversational | β Orchestration, Multiagent | β Planning, Autonomous | - |
| Techniques | - | β CoT, SC | β ToT, GoT, LTM | - |
| Middleware | β Retry, Timeout | β Circuit Breaker, Caching | β Metrics, Rate Limiter | β Complete Stack |
| Transport | - | β gRPC, WebSocket | - | β Cross-language |
| E2E Apps | - | - | β Code Review, Support | β Research, Optimizer |
π€ Contributing
Found a bug or want to add an example?
- Report issues: GitHub Issues
- Discuss ideas: GitHub Discussions
- Contribute: CONTRIBUTING.md
π Example Template
Creating your own example? Use this structure:
"""
Brief description of what this example demonstrates.
Features:
- Feature 1
- Feature 2
Usage:
python example_name.py
"""
from agenkit import Agent, Message
class YourAgent(Agent):
@property
def name(self) -> str:
return "your-agent"
async def process(self, message: Message) -> Message:
# Your implementation
return Message(role="assistant", content="response")
# Example usage
async def main():
agent = YourAgent()
response = await agent.process(Message(role="user", content="test"))
print(response.content)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
π Example Highlights
Most Popular
patterns/react-pattern.py- ReAct loopllm/openai_example.py- OpenAI integrationmiddleware/retry_example.py- Retry middleware
Most Complex
e2e/code-review/- 7-file multi-agent systeme2e/customer-support/- RAG + vectorstore + escalatione2e/research-assistant/- Memory hierarchy + tools
Hidden Gems
evaluation/optimization_demo.py- Hyperparameter tuningrouting/semantic_tool_selection_example.py- Embedding routingbudget/extended_thinking_demo.py- Token budget management
Ready to build? Start with 01_basic_agent.py or dive into E2E applications!
Made with β€οΈ by the Agenkit community
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
apps
|
|
|
deployment
|
|
|
aws-lambda/go
command
|
|
|
e2e
|
|
|
cross-language-system/go
command
|
|
|
go
|
|
|
techniques/reasoning
command
|
|
|
infrastructure
|
|
|
go
command
Production-ready agent with load balancing, health checks, and enhanced retry.
|
Production-ready agent with load balancing, health checks, and enhanced retry. |