Build agents

In this sectionTask-oriented guides for building, deploying and monitoring production agents. Step-by-step instructions, complete code examples and best practices for real applications.

  • 41 pages
  • About 313 min to read all

Guides are hands-on, task-oriented instructions that walk you through solving specific problems. Unlike concepts, which explain how 10xGraph works, guides show you how to do something: build a graph, add tools, set up memory, handle errors, or deploy to production.

Each guide is self-contained and runnable. You get complete code examples with all imports and no placeholders, plus how to verify the result worked. Guides assume you have read the Get Started section and understand the basics.

Five most common tasks

Start here if you are building an agent for the first time. These cover the decisions you make in almost every project.

  1. Build a graph: Construct and wire nodes, edges, and routing logic. Shows when to use a custom StateGraph vs a prebuilt agent.

  2. Configure an agent: Choose a model and provider (OpenAI, Google, Anthropic, or custom), set system prompts, and handle provider-specific options like reasoning or batch mode.

  3. Add tools to an agent: Write tool functions, understand how the LLM sees the schema (from your type hints and docstring), inject dependencies like state or db, and handle errors.

  4. Set up checkpointing and memory: Enable thread state persistence so runs resume correctly after crashes. Choose a checkpointer for your durability needs: in-memory for development, SQLite for single-server, or Postgres+Redis for production.

  5. Stream and monitor runs: Use Python’s astream() to emit tokens or messages as they arrive, inspect intermediate steps, and understand the streaming event types.

How guides are organized

Guides are grouped by topic. Click through to find what you need.

Agents and graphs

Build the core graph logic. These guides cover the fundamental patterns: constructing graphs by hand, choosing when to use prebuilt agents, and customizing state and nodes.

Prebuilt agents

10xGraph ships seven prebuilt agents that handle common patterns. Use one if it matches your needs; customize or extend it if not.

Tools and MCP

Give your agents the ability to take action. Covers writing custom tools, using prebuilt tools, Model Context Protocol (MCP), and emitting progress during long-running operations.

State, memory and context

Manage graph state, persistence, and memory. These guides cover how messages accumulate, how to keep history across threads, and when to trim old context.

Multi-agent and control flow

Coordinate multiple agents and implement advanced control flow. Covers handoff patterns, human-in-the-loop approval, and background tasks.

Streaming, media and realtime

Handle continuous output and multimodal input. Covers streaming tokens, sending images and documents to models, realtime audio, and batch processing for cost savings.

Safety

Protect against prompt injection and misuse. Covers input validation, guardrails, callbacks, and authorization scopes.

Observability and operations

Monitor agents in production. Covers logging, tracing, metrics, graceful shutdown, and ID generation.

Agent Skills

Extend 10xGraph with special capabilities for coding assistants (Claude Code, GitHub Copilot, and similar).

Guides vs concepts vs reference

Concepts explain how 10xGraph works: the architecture, the execution model, memory layers, and design decisions. Read them to understand the “why” before building.

Guides show you how to do something: how to build a graph, add tools, set up memory, stream responses. Each guide is a complete, working example that solves a specific problem. Read them when you know what you want to do and need the steps.

Reference documents every class, function, parameter, and option in the API. Use it to look up details: what parameters does Agent accept? What exceptions can be raised? What fields are in the request payload? Reference pages are not tutorials.

Getting the most from guides

  • Start with Get Started if you are brand new to 10xGraph.
  • Pick a guide that matches your current task. Guides are independent; you do not have to read them in order.
  • Every guide has complete, runnable code. Copy it and try it; modify it for your use case.
  • If a guide references a concept you do not know, read that concept first (links point there).
  • If you need to know all the options for something, the reference page has the full list (links point there).

All pages in Build agents

Agents and graphs

  1. Build a graphCreate a StateGraph with nodes and routing, compile it, and run it with invoke.6 min
  2. How to configure AgentReference for the Agent constructor, including model, provider, system_prompt, tool_node, reasoning_config, retry_config, fallback_models, and output_schema.12 min
  3. Use custom stateExtend AgentState with application-specific fields and understand state reducers for controlled field updates.9 min
  4. Write custom nodesBuild nodes as plain Python functions with auto-injected state, config, and framework services. Route dynamically with Command.7 min
  5. Structured outputGet typed output from LLMs with automatic validation and repair. Use output_schema with Agent or StructuredOutputAgent.6 min
  6. Visualize a graphInspect and visualize your compiled graph structure to understand agent flow and debug routing.6 min

Prebuilt agents

  1. Choose and use prebuilt agentsOverview of ReactAgent, PlanActReflectAgent, StructuredOutputAgent, SupervisorTeamAgent, SwarmAgent, RAGAgent, and AudioAgent with quick comparison and code snippets.6 min
  2. ReactAgentReactAgent implements the ReAct pattern, a simple LLM loop that reasons about what to do and acts by calling tools until it reaches a final answer.8 min
  3. PlanActReflectAgentPlan-act-reflect loops add an evaluation phase to prevent incomplete answers, making agents iterate until they finish the task.10 min
  4. SwarmAgentSwarmAgent enables peer-to-peer multi-agent coordination where any member can hand off to any other member, with no bottleneck at a central supervisor.12 min
  5. SupervisorTeamAgentRoute tasks from a supervisor LLM to specialized worker agents, each independently configured with their own model and tools.8 min
  6. RAGAgentRAGAgent retrieves relevant documents from a knowledge base, optionally reranks them, then answers questions grounded in that context.11 min
  7. StructuredOutputAgentStructuredOutputAgent validates LLM output against a Pydantic schema and auto-repairs invalid JSON through a GENERATE/REPAIR loop.9 min
  8. AudioAgentBuild realtime audio-to-audio agents with Gemini Live, driven by duplex WebSocket sessions with optional tools, memory and skills.11 min

Tools and MCP

  1. How to use the @tool decoratorMark Python functions as agent tools with metadata, parameter schemas, error handling, and dependency injection using the @tool decorator.9 min
  2. Use prebuilt toolsReady-made production tools: fetch URLs, calculate safely, read and search files, search the web, manage memory, and transfer between agents.9 min
  3. Web ToolsFetch web pages and search the public web with SSRF protection, grounding sources, and datastore support.9 min
  4. File ToolsSafe, workspace-scoped file tools for agents to read, write, and search text files within a configured root directory.9 min
  5. Memory Toolsmemory_tool, user_memory_tool, and agent_memory_tool give agents long-term memory to store, search, update, and delete facts across conversations.8 min
  6. Use MCP tools in agentsConnect 10xGraph agents to MCP servers and mix local Python tools with remote MCP tools in a single graph.7 min
  7. Emit Tool Progress UpdatesLearn how to send live progress, errors, and status updates from tools during streaming execution.5 min

State, memory and context

  1. Set up checkpointingChoose and configure a checkpointer for state persistence: InMemoryCheckpointer for development, SqliteCheckpointer for client agents, or PgCheckpointer for production.7 min
  2. Durability and concurrencyEnsure reliable execution: thread isolation, state history, optimistic concurrency, and idempotent tool calls.7 min
  3. How to use the memory storeGuide to using QdrantStore and Mem0Store for long-term vector memory, factory helpers, and enabling agent-level memory with MemoryConfig.10 min
  4. Manage conversation contextKeep message history within your LLM's context window using trimming and summarization.6 min
  5. How to use dependency injectionGuide to using InjectQ for binding services and injecting them into node functions, tool functions, and agents via Inject[T] parameter defaults.8 min

Multi-agent and control flow

  1. Route between agents with handoffTransfer control between agents in a multi-agent graph using handoff tools and Command routing.6 min
  2. Add human approval with interrupt()Pause a graph mid-execution for human approval, correction, or choice from inside a node or tool. Resume when the decision is made.9 min
  3. Run work in the backgroundLaunch fire-and-forget async tasks from a node without blocking the response using BackgroundTaskManager.4 min

Streaming, media and realtime

  1. Stream graph responsesStream token-by-token output using astream(), handle StreamChunk events, and pause with interrupts9 min
  2. Send media to modelsSend images, audio, and documents to your models from Python using content blocks, MediaRef, and storage backends.6 min
  3. How to build a realtime audio agentBuild a live audio-to-audio agent with AudioAgent and Gemini Live: arealtime sessions, LiveInputQueue, image input, reconnection, and the WebSocket bridge.8 min
  4. Batch LLM callsUse OpenAI and Anthropic batch APIs for cost-effective processing of large request volumes.8 min

Safety

  1. Validate input and guard promptsHow to validate and sanitize user input before it reaches your agent's LLM, protecting against prompt injection, jailbreaks, and other OWASP LLM01:2025 attacks.6 min
  2. Use Callbacks and HooksHook into graph execution to log, validate, trace, and respond to events at two levels6 min
  3. Authorization scopesRead caller identity and enforce scopes inside graph nodes and tools using get_authz, has_scope, and isolation_scope.7 min

Observability and operations

  1. Emit events from your graphForward structured events to observability systems using Redis, Kafka, RabbitMQ and more.6 min
  2. Send traces to Logfire and LangSmithSend 10xGraph spans to Pydantic Logfire or LangSmith over OpenTelemetry using helpers, publishers, or configuration.6 min
  3. Configure ID generatorsControl the format of thread IDs and run IDs using built-in or custom generators to match your storage backend and observability requirements.6 min
  4. Graceful shutdownHandle agent shutdown cleanly with signal handlers, timeout coordination, and protected cleanup sections.5 min

Agent Skills

  1. Give an agent Agent SkillsAdd Agent Skills (SKILL.md folders with scripts, references and assets) to a 10xGraph Agent, validate them, and observe when the model uses them.6 min