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:

Terminal
git clone https://github.com/10xGraph/10xGraph.git
cd 10xGraph/agentflow

Install with example dependencies

Most examples need a provider SDK. Install 10xGraph with the providers your examples require:

Terminal
# 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:

Terminal
pip install "10xgraph[all]"

Set environment variables

Each example requires API keys for the model provider. Create a .env file in the agentflow/ directory:

Terminal
# For Google Gemini
GEMINI_API_KEY=your-key-here

# For OpenAI
OPENAI_API_KEY=your-key-here

# For Anthropic
ANTHROPIC_API_KEY=your-key-here

Load these in your script or shell:

Terminal
export $(cat .env | xargs)

Run an example

Navigate to an example directory and run its script:

Terminal
cd examples/agent-class
python graph.py

Some 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.

Streaming

Real-time output and cancellation. Essential for interactive applications.

Tools and MCP

Integrating external systems via tools and the Model Context Protocol.

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.

Learning path

If you are new to 10xGraph, follow this recommended order:

  1. 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.

  2. Add real-time interaction. Move to the Streaming group to learn token-by-token output and cancellation, essential for interactive UIs.

  3. Integrate external systems. The Tools and MCP group shows how to connect APIs, databases and the Model Context Protocol.

  4. Coordinate multiple agents. The Multi-agent group covers routing and handoff patterns.

  5. Persist and enrich data. Memory and media examples demonstrate long-term memory and multimodal input.

  6. Ship to production. The Production group covers testing, evaluation and clean shutdown.

  7. 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)
  • 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

  1. Agent Class PatternBuild a weather assistant using the Agent class with tools and conditional routing.6 min
  2. Custom StateExtend AgentState with typed domain fields and use partial state updates to build context-aware agents.6 min
  3. 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
  4. 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
  5. 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
  6. Google GenAI AdapterConvert google-genai SDK responses to 10xGraph Message format with GoogleGenAIConverter4 min

Streaming

  1. React StreamingStream graph responses token-by-token using astream with ResponseGranularity, and understand the difference between invoke and stream.5 min
  2. Stop StreamGracefully stop a running 10xGraph stream from the caller by using app.stop(config).5 min

Tools and MCP

  1. MCP ServerExpose Python tools over Model Context Protocol using FastMCP so 10xGraph and other MCP clients can call them remotely.4 min
  2. MCP ClientConnect to MCP servers, discover remote tools, and invoke them directly using FastMCP.3 min
  3. 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
  4. GitHub MCPConnect an agent to a remote GitHub MCP server to list commits and download files from repositories through MCP tools.5 min
  5. 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

  1. MultiagentRoute work between specialist nodes in one 10xGraph graph with a coordinator node and conditional edges, using a deterministic, runnable example.4 min
  2. HandoffBuild a multi-agent 10xGraph system where agents transfer work to each other using handoff tools.5 min

Memory and media

  1. MemoryBuild a chatbot that remembers user preferences across conversations, using Mem0 and Qdrant for long-term memory inside custom graph nodes.4 min
  2. 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

  1. SkillsRun an example graph that loads Agent Skills (SKILL.md files) on demand and combines them with normal Python tools.6 min
  2. TestingUse QuickTest to write low-boilerplate, deterministic tests for 10xGraph graphs without hitting a live model.5 min
  3. Evaluation exampleWalk through the weather-agent evaluation example: eval cases, QuickEval, trajectory criteria, user simulation and CI reports.6 min
  4. 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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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