Examples
In this sectionRunnable examples and reference architectures demonstrating 10xGraph agents, tools, streaming, MCP, memory, and multi-agent patterns.
- 26 pages
- About 147 min to read all
The examples section provides two types of learning resources. The first are guided walkthroughs of working example scripts from the repository’s examples/ folder: each covers a specific feature or pattern (agents, custom state, tools, streaming, MCP, memory, multi-agent handoff, testing and evaluation). The second are reference architectures for five common production use cases (customer support, data extraction, coding, research and RAG agents). Together they show how 10xGraph concepts translate into real, runnable code.
These examples sit between the quickstart and the reference documentation. If you learn best from reading and running actual code, start here. If you prefer concepts first, read the Concepts section and return here to see the patterns in action.
Getting started with examples
The examples are located in the repository at agentflow/examples/. Each example directory contains one or more runnable Python scripts (for example graph.py) and sometimes a README.md with setup instructions.
Clone the repository
Start by cloning the 10xGraph repository:
git clone https://github.com/10xGraph/10xGraph.git
cd 10xGraph/agentflowInstall with example dependencies
Most examples need a provider SDK. Install 10xGraph with the providers your examples require:
# Google Gemini examples
pip install "10xgraph[google-genai]"
# OpenAI examples
pip install "10xgraph[openai]"
# Anthropic (Claude) examples
pip install "10xgraph[anthropic]"
# MCP, memory, and other integrations
pip install "10xgraph[mcp,qdrant,pg_checkpoint]"For complete functionality, install everything:
pip install "10xgraph[all]"Set environment variables
Each example requires API keys for the model provider. Create a .env file in the agentflow/ directory:
# For Google Gemini
GEMINI_API_KEY=your-key-here
# For OpenAI
OPENAI_API_KEY=your-key-here
# For Anthropic
ANTHROPIC_API_KEY=your-key-hereLoad these in your script or shell:
export $(cat .env | xargs)Run an example
Navigate to an example directory and run its script:
cd examples/agent-class
python graph.pySome examples have additional setup (MCP servers, database initialization). Check the example’s README.md, where one exists.
What you’ll learn
The examples are organized in five groups that build on each other. Start with the Foundations group to understand the core patterns, then move into advanced integrations, streaming, multi-agent coordination, and production-ready testing and evaluation.
Foundations
The basics: how to define agents and tools, custom state, and the ReAct loop. These examples form the foundation for all other patterns.
- Agent Class Pattern: The smallest useful agent, showing the Agent class and how to invoke it
- Custom State: Define application-specific state beyond messages
- Tool Decorator: Create tools with type hints and automatic schema generation
- ReAct Agent: Multi-turn agent loop with tool calling and routing
- ReAct Agent with Validation: Input validation and error handling in agents
- Google GenAI: Using Google’s Gemini model as the LLM provider
Streaming
Real-time output and cancellation. Essential for interactive applications.
- React Streaming: Token-by-token streaming from the agent
- Stop Stream: Cancel a running agent mid-execution
Tools and MCP
Integrating external systems via tools and the Model Context Protocol.
- Dependency Injection: Pass database connections, config and user context into tools
- MCP Server: Implement a Model Context Protocol server
- MCP Client: Connect to an MCP server and use its tools
- MCP ReAct Agent: Combine ReAct with MCP tools
- GitHub MCP: Real-world example using GitHub’s MCP server
Multi-agent
Patterns for agents calling other agents and handling handoffs.
- Multiagent: Multiple agents in one graph, routing between them
- Handoff: Agent handoff patterns with context transfer
Memory and media
Persistent agent memory and multimodal input (images, audio, documents).
- Memory: Store and retrieve long-term agent memory
- Multimodal: Process images and other media alongside text
Production
Testing, evaluation, and graceful operation.
- Skills: Load Agent Skills (SKILL.md folders) on demand alongside normal tools
- Testing: Unit tests and mocked LLM calls for agent logic
- Evaluation: Define eval sets and run evaluations against a dataset
- Graceful Shutdown: Clean shutdown handling and resource cleanup
Use cases
Complete reference architectures for five common agent patterns. Each one shows the graph topology, the tools needed, and what to monitor in production.
- Customer Support Agent: Multi-tool support flow with human handoff and refund handling
- Data Extraction Agent: Structured data extraction from unstructured documents and text
- Coding Agent: Code generation, review, and tool-based execution
- Research Agent: Web search combined with synthesis and citations
- RAG Agent: Chat-with-your-docs with retrieval, grounding and citations
Learning path
If you are new to 10xGraph, follow this recommended order:
-
Start with the Foundations group. Begin with Agent Class Pattern to see the smallest useful graph. Continue with Custom State and Tool Decorator to understand state and tools, then build the ReAct Agent to assemble the core loop.
-
Add real-time interaction. Move to the Streaming group to learn token-by-token output and cancellation, essential for interactive UIs.
-
Integrate external systems. The Tools and MCP group shows how to connect APIs, databases and the Model Context Protocol.
-
Coordinate multiple agents. The Multi-agent group covers routing and handoff patterns.
-
Persist and enrich data. Memory and media examples demonstrate long-term memory and multimodal input.
-
Ship to production. The Production group covers testing, evaluation and clean shutdown.
-
Pick your use case. Once you understand the patterns, the Use cases group shows how to apply them end-to-end.
Before you start
Most examples assume:
- Python 3.12 or later
- 10xGraph installed with the appropriate provider extra (google-genai, openai, or anthropic)
- Environment variables set for API keys
- For MCP and some advanced examples, additional system dependencies (see the example’s README, where one exists)
Related docs
- Get started: The quickstart and tutorial path
- Concepts: Deep dives into state graphs, agents, tools and more
- Guides: Task-focused how-tos for building agents
- Reference: Complete API documentation
All pages in Examples
Foundations
- Agent Class PatternBuild a weather assistant using the Agent class with tools and conditional routing.6 min
- Custom StateExtend AgentState with typed domain fields and use partial state updates to build context-aware agents.6 min
- Tool DecoratorLearn how to use the @tool decorator to attach metadata, tags, and capabilities to Python tool functions, plus filter and inspect tools at runtime.5 min
- ReAct AgentWalk through a ReAct agent that calls a weather tool, injects tool_call_id and state, and keeps history per thread with a checkpointer.7 min
- ReAct Agent with ValidationReject unsafe or off-policy user messages before they reach the model by registering input validators on a CallbackManager for a ReAct agent.6 min
- Google GenAI AdapterConvert google-genai SDK responses to 10xGraph Message format with GoogleGenAIConverter4 min
Streaming
Tools and MCP
- MCP ServerExpose Python tools over Model Context Protocol using FastMCP so 10xGraph and other MCP clients can call them remotely.4 min
- MCP ClientConnect to MCP servers, discover remote tools, and invoke them directly using FastMCP.3 min
- MCP ReAct AgentBuild a ReAct agent graph whose tools live on a remote MCP server: configure the client, wire a ToolNode, route tool calls, and run it.4 min
- GitHub MCPConnect an agent to a remote GitHub MCP server to list commits and download files from repositories through MCP tools.5 min
- Dependency InjectionUse InjectQ with 10xGraph to inject shared services such as checkpointers, stores, callbacks, and app-specific dependencies into graph nodes and tools.5 min
Multi-agent
Memory and media
- MemoryBuild a chatbot that remembers user preferences across conversations, using Mem0 and Qdrant for long-term memory inside custom graph nodes.4 min
- MultimodalSend images, audio, video, and documents to a 10xGraph agent with content blocks, MediaRef (url, base64, file_id), MultimodalConfig, and a media store.6 min
Production
- SkillsRun an example graph that loads Agent Skills (SKILL.md files) on demand and combines them with normal Python tools.6 min
- TestingUse QuickTest to write low-boilerplate, deterministic tests for 10xGraph graphs without hitting a live model.5 min
- Evaluation exampleWalk through the weather-agent evaluation example: eval cases, QuickEval, trajectory criteria, user simulation and CI reports.6 min
- Graceful ShutdownRun a tool-calling 10xGraph agent as a long-running service that handles SIGINT and SIGTERM, protects startup and cleanup, and calls aclose().9 min
Use cases
- Build a Customer Support AI Agent in PythonReference architecture for a production customer support AI agent in Python. Intent routing, ticket lookup, refund tools, and human handoff with 10xGraph.8 min
- Build a Data Extraction AI Agent in PythonBuild a data extraction agent in Python that turns unstructured text into validated Pydantic records and retries when validation fails, with 10xGraph.6 min
- Build a Coding AI Agent in PythonBuild a plan-first coding agent with read, search, test and diff-proposing tools, so every file change is reviewed by a human before it lands.8 min
- Build a Research AI Agent in PythonBuild a research agent that searches the web, reads full pages and writes answers with [source-N] citations, plus a check for uncited claims.8 min
- RAG agent example walkthroughBuild a knowledge-base Q&A agent with RAGAgent, from a runnable keyword-search demo to Qdrant retrieval and optional reranking.7 min