Examples

In this sectionRunnable Python AI agent examples for 10xGraph with full source code: tools, streaming, MCP, memory, RAG, multi-agent, production features and full-stack apps.

  • 38 pages
  • About 334 min to read all

Every page in this section is a runnable example from the 10xGraph repository. Each page explains what the example builds, walks through the code file by file, and ends with the full source of every file in tabs, so you can read it here or copy it straight into your project.

Run any example

Terminal
git clone https://github.com/10xGraph/10xGraph.git
cd 10xGraph/agentflow
pip install "10xgraph[openai,google-genai,anthropic]"
cp examples/.env.example .env   # add the API key for the provider the example uses
python examples/quickstart/quickstart.py

Each page lists the extras and the one environment variable its example needs. The model string is written in each file, so changing provider is a one-line edit.

Getting started

Tools and integrations

Production

Memory and patterns

Multimodal and quality

Deployment

Use cases

Full-stack apps

All pages in Examples

Production

  1. Serve an agent with auth, from init to DockerScaffold the Full setup, run it with JWT auth, call it with curl and TenxGraphClient, then generate Docker files with 10xgraph build.4 min
  2. A payment tool that cannot charge twiceA charge_card tool that asks for approval with interrupt(), sends an idempotency key, and relies on the checkpointer tool ledger so a resumed run never charges twice.4 min
  3. Human approval over the APIPause a refund agent with interrupt() and a response_schema, read the open request from the API, resume with resume and interrupt_id, and handle 409 and 422.4 min
  4. Two users, one server, no shared threadsServe one agent to two users with JWT auth and ownership, then see what each user can and cannot reach. The statuses shown were captured from a running server.4 min
  5. File and web tools that stay in boundsGive a support agent a read-only knowledge base with create_file_tools, a host-restricted fetch_url wrapper, and a MediaFetchPolicy for customer-supplied image URLs.4 min
  6. Security regression tests for an agentCatch a prompt-injected agent in CI. An eval set that expects zero tool calls, plus a pytest check that no tool outside the allow-list was requested.4 min
  7. Graceful Shutdown for a Python AI Agent Service with 10xGraphHandle SIGINT and SIGTERM in a long-running 10xGraph agent service, flush checkpoint writes, and release resources with graph.aclose() and async with.7 min
  8. Retries, Fallback Models and Circuit Breaker for a Python AI Agent in 10xGraphMake a 10xGraph agent survive provider outages with RetryConfig backoff, a circuit breaker, cross-company fallback models, and a recursion limit.7 min
  9. Human-in-the-Loop Approval with interrupt() in a Python AI Agent (10xGraph)Pause a 10xGraph agent mid-run to ask a person for approval, validate the answer with a JSON schema, and resume the same thread in Python.7 min
  10. Persist Agent Conversations with SQLite, PostgreSQL and Redis Checkpointers in 10xGraphSave and resume a Python AI agent conversation by thread_id with 10xGraph's InMemory, SQLite and PostgreSQL plus Redis checkpointers, and read state back.9 min
  11. Context Window Management for Python AI Agents - Trim and Summarize with 10xGraphKeep long agent conversations inside the token limit in 10xGraph with MessageContextManager trimming and SummaryContextManager summaries from a cheaper model.6 min
  12. Callbacks, Validators and Lifecycle Hooks in 10xGraphAdd logging, timing, cost tracking, prompt injection validation, lifecycle hooks and secret redaction to a 10xGraph Python AI agent with CallbackManager.10 min
  13. Observability and Event Publishers for 10xGraph AgentsStream 10xGraph run events to the console, OpenTelemetry, Logfire, LangSmith, Redis, Kafka or RabbitMQ and combine several publishers in Python.10 min
  14. Serve a 10xGraph Agent as a REST and SSE APIDeploy a 10xGraph Python AI agent with the 10xgraph-api server. Configure 10xgraph.json, call /v1/graph/invoke and /v1/graph/stream, and use the TypeScript client.5 min

Getting started

  1. 10xGraph Quickstart - Your First Python AI Agent with ToolsBuild a Python AI agent with 10xGraph in about 30 lines: a ReactAgent with one tool, run with ainvoke or invoke, a thread_id and clean shutdown.4 min
  2. 10xGraph StateGraph Basics - Custom State, Routing and CommandLearn the 10xGraph StateGraph in Python with no API key: custom AgentState fields, function nodes, conditional edges and Command, plus a hand-built ReAct agent.6 min
  3. Streaming a 10xGraph Python AI Agent with astream and StreamEmitterStream agent output in 10xGraph with astream: read StreamChunk events, print text as it arrives, report tool progress with StreamEmitter, and stop a run with astop.5 min

Tools and integrations

  1. Tools in 10xGraph - @tool Decorator, Injected Params, ToolResult and Remote ToolsDefine Python agent tools in 10xGraph: the @tool decorator with tags, injected state and config, ToolResult state updates, prebuilt tools and client-side tools.9 min
  2. LLM Providers in 10xGraph - OpenAI, Gemini, Claude, DeepSeek, OllamaRun one 10xGraph ReactAgent on OpenAI, Google Gemini and Vertex AI, Anthropic Claude (direct, Vertex, Bedrock), DeepSeek and Ollama by changing the model string.8 min
  3. Dependency Injection in 10xGraph Agents with InjectQRegister your own services in an InjectQ container, receive them in 10xGraph tools and nodes with Inject[T], and swap them in tests with rebinding or override_node.6 min
  4. MCP Tools in a Python AI Agent with 10xGraphConnect a 10xGraph ReactAgent to local and remote MCP servers over streamable HTTP, use several servers at once, and send auth headers in Python.6 min
  5. GitHub MCP Server with a 10xGraph AgentUse GitHub's remote MCP server from a 10xGraph ReactAgent to list commits and download a README, authenticated with a GitHub token in Python.4 min
  6. Xquik MCP Server with a 10xGraph AgentConnect a 10xGraph ToolNode or ReactAgent to the remote Xquik MCP server with an API key and list its tools in Python.3 min

Memory and patterns

  1. Long-Term Agent Memory with Postgres and Qdrant in 10xGraphGive a 10xGraph Python agent long-term memory across sessions with MemoryConfig, PgVectorStore in Postgres or a local Qdrant store, user memory and shared agent memory.12 min
  2. RAG Agent with Qdrant and Reranking in 10xGraph (Python)Build a retrieval-augmented generation agent in Python with 10xGraph RAGAgent, a local Qdrant store, Gemini embeddings and optional Cohere or cross-encoder reranking.5 min
  3. Structured Output with Pydantic in 10xGraph AgentsGet typed Pydantic output from a 10xGraph Python AI agent with output_schema, or use StructuredOutputAgent to validate replies and retry with repair prompts.5 min
  4. Multi-Agent Patterns in Python with 10xGraphBuild supervisor, swarm, manual handoff and plan-act-reflect multi-agent systems in 10xGraph where each agent runs on a different company's LLM.12 min
  5. Agent Skills in 10xGraph - On-Demand and Per-Tenant Session ModeLoad SKILL.md instructions into a 10xGraph Python agent on demand with activate_skill, or preload a per-tenant persona with session mode, with bundled resources.10 min

Multimodal and quality

  1. Multimodal Agents in 10xGraph - Image, Document, Audio and Video InputSend images, PDFs, audio and video to a 10xGraph Python agent by URL, base64 or media-store reference, with gpt-5-mini and Gemini, MultimodalConfig and MediaFetchPolicy.8 min
  2. Realtime Voice Agent with Gemini Live in 10xGraph (Python)Build a realtime audio-to-audio voice agent with 10xGraph AudioAgent and Gemini Live. Stream a WAV file or microphone, call tools by voice, or use a WebSocket.11 min
  3. Test 10xGraph Agents Without an LLM Using pytestUnit test a 10xGraph Python AI agent offline with TestAgent, QuickTest, MockToolRegistry, MockMCPClient and override_node, with no API keys or network calls.9 min
  4. Evaluate a 10xGraph Agent with Trajectory and LLM Judge CriteriaEvaluate a 10xGraph Python agent with pytest. Score tool trajectories, run LLM-as-judge criteria and user simulation, and write console, JSON, HTML and JUnit reports.18 min

Use cases

  1. Customer Support Swarm with Human Approval and Memory in 10xGraphBuild a Python customer support agent swarm on Gemini, OpenAI and Claude with refund approval via interrupt(), SQLite persistence and Qdrant memory.21 min
  2. Research Assistant with Plan-Act-Reflect and a Structured Report in 10xGraphBuild a Python research agent that plans, searches, reflects and writes a Pydantic report, using Claude, GPT-5 mini, Gemini and DeepSeek in one 10xGraph.17 min
  3. 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
  4. 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

Apps

  1. Docs Assistant with RAG, Qdrant and a React Chat UI (10xGraph)Full-stack RAG docs assistant: a Claude ReAct agent with Qdrant search, Postgres threads, a React chat UI and Docker Compose.34 min
  2. CopilotKit Frontend for a 10xGraph Agent over AG-UIBuild a task board with a Next.js CopilotKit UI and a Python 10xGraph agent served over AG-UI, with shared state, approvals and Docker.22 min