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.
-
Build a graph: Construct and wire nodes, edges, and routing logic. Shows when to use a custom
StateGraphvs a prebuilt agent. -
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.
-
Add tools to an agent: Write tool functions, understand how the LLM sees the schema (from your type hints and docstring), inject dependencies like
stateordb, and handle errors. -
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.
-
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.
- Build a graph: StateGraph, nodes, edges, and routing
- Configure an agent: Model selection, system prompts, provider options
- Use custom state: Extend AgentState with your own fields
- Use custom nodes: Write nodes that are not agents or tool dispatchers
- Get structured output: Output a typed, validated schema from an agent
- Visualize a graph: Inspect and draw your compiled graph
Prebuilt agents
10xGraph ships seven prebuilt agents that handle common patterns. Use one if it matches your needs; customize or extend it if not.
- Prebuilt agents overview: Quick comparison and when to use each
- ReactAgent: The standard tool-calling loop
- RAGAgent: Retrieval-augmented generation with vector stores
- PlanActReflectAgent: Plan, act, reflect, revise cycle
- SupervisorTeamAgent: Supervisor routing tasks to specialists
- SwarmAgent: Peer agents that hand off to each other
- StructuredOutputAgent: Guaranteed typed output
- AudioAgent: Realtime audio input and streaming
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.
- Use the @tool decorator: Write tools that the LLM can call
- Prebuilt tools overview: Built-in tools for common tasks
- Web tools: Fetch, search, and parse HTML
- File tools: Read, write, and manipulate files
- Memory tools: Store and retrieve long-term facts
- Use MCP: Model Context Protocol servers and clients
- Emit tool progress: Show progress for long-running tools
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.
- Set up checkpointing: Thread state and durability options
- Durability and concurrency: Optimistic concurrency, retries, and the tool ledger
- Use a memory store: Long-term facts and retrieval
- Use context managers: Trim or summarize old messages automatically
- Use dependency injection: Inject user_id, db, config, and custom parameters into nodes and tools
Multi-agent and control flow
Coordinate multiple agents and implement advanced control flow. Covers handoff patterns, human-in-the-loop approval, and background tasks.
- Handoff between agents: Agent A asks agent B to take over
- Add human approval: Pause runs for human review before proceeding
- Run background tasks: Spawn work that does not block the run
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.
- Stream a graph: Emit messages or tokens as they arrive
- Send media: Images, audio, and documents to models
- Use realtime audio: Bidirectional audio streaming
- Batch LLM calls: Batch processing for cost optimization
Safety
Protect against prompt injection and misuse. Covers input validation, guardrails, callbacks, and authorization scopes.
- Validate input and guard prompts: Prevent injection attacks
- Use callbacks: Hooks before/after invoke, on error, and on completion
- Authorization scopes: Read user identity and scopes inside tools
Observability and operations
Monitor agents in production. Covers logging, tracing, metrics, graceful shutdown, and ID generation.
- Use publishers: Stream events to observability platforms
- Send traces to Logfire and LangSmith: Production tracing and debugging
- Configure ID generation: Snowflake IDs for distributed systems
- Graceful shutdown: Finish inflight requests before stopping
Agent Skills
Extend 10xGraph with special capabilities for coding assistants (Claude Code, GitHub Copilot, and similar).
- Give an agent Agent Skills: Enable agents to create and modify 10xGraph projects
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
- Build a graphCreate a StateGraph with nodes and routing, compile it, and run it with invoke.6 min
- 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
- Use custom stateExtend AgentState with application-specific fields and understand state reducers for controlled field updates.9 min
- Write custom nodesBuild nodes as plain Python functions with auto-injected state, config, and framework services. Route dynamically with Command.7 min
- Structured outputGet typed output from LLMs with automatic validation and repair. Use output_schema with Agent or StructuredOutputAgent.6 min
- Visualize a graphInspect and visualize your compiled graph structure to understand agent flow and debug routing.6 min
Prebuilt agents
- Choose and use prebuilt agentsOverview of ReactAgent, PlanActReflectAgent, StructuredOutputAgent, SupervisorTeamAgent, SwarmAgent, RAGAgent, and AudioAgent with quick comparison and code snippets.6 min
- 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
- PlanActReflectAgentPlan-act-reflect loops add an evaluation phase to prevent incomplete answers, making agents iterate until they finish the task.10 min
- 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
- SupervisorTeamAgentRoute tasks from a supervisor LLM to specialized worker agents, each independently configured with their own model and tools.8 min
- RAGAgentRAGAgent retrieves relevant documents from a knowledge base, optionally reranks them, then answers questions grounded in that context.11 min
- StructuredOutputAgentStructuredOutputAgent validates LLM output against a Pydantic schema and auto-repairs invalid JSON through a GENERATE/REPAIR loop.9 min
- 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
- 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
- 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
- Web ToolsFetch web pages and search the public web with SSRF protection, grounding sources, and datastore support.9 min
- File ToolsSafe, workspace-scoped file tools for agents to read, write, and search text files within a configured root directory.9 min
- 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
- 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
- Emit Tool Progress UpdatesLearn how to send live progress, errors, and status updates from tools during streaming execution.5 min
State, memory and context
- Set up checkpointingChoose and configure a checkpointer for state persistence: InMemoryCheckpointer for development, SqliteCheckpointer for client agents, or PgCheckpointer for production.7 min
- Durability and concurrencyEnsure reliable execution: thread isolation, state history, optimistic concurrency, and idempotent tool calls.7 min
- 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
- Manage conversation contextKeep message history within your LLM's context window using trimming and summarization.6 min
- 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
- Route between agents with handoffTransfer control between agents in a multi-agent graph using handoff tools and Command routing.6 min
- 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
- 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
- Stream graph responsesStream token-by-token output using astream(), handle StreamChunk events, and pause with interrupts9 min
- Send media to modelsSend images, audio, and documents to your models from Python using content blocks, MediaRef, and storage backends.6 min
- 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
- Batch LLM callsUse OpenAI and Anthropic batch APIs for cost-effective processing of large request volumes.8 min
Safety
- 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
- Use Callbacks and HooksHook into graph execution to log, validate, trace, and respond to events at two levels6 min
- 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
- Emit events from your graphForward structured events to observability systems using Redis, Kafka, RabbitMQ and more.6 min
- Send traces to Logfire and LangSmithSend 10xGraph spans to Pydantic Logfire or LangSmith over OpenTelemetry using helpers, publishers, or configuration.6 min
- 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
- Graceful shutdownHandle agent shutdown cleanly with signal handlers, timeout coordination, and protected cleanup sections.5 min