Skip to main content
Hardcoded multi-agent orchestration is brittle: topology lives in framework-specific code, changes require redeploys, and bottlenecks are hard to see. Agent graphs externalize that topology into LaunchDarkly, while your application continues to own execution. In this tutorial, you’ll build a small multi-agent workflow, traverse it with the SDK, monitor per-node latency on the graph itself, and update a slow node’s model without changing application code.
How agent graphs work
  • Node = AgentControl config (model, instructions, tools)
  • Edge = handoff metadata (routing contract you define)
  • Graph = topology (which nodes connect)
  • Your app = execution + interpretation
LaunchDarkly provides graph structure, config, and observability. Your application owns execution semantics: you write the code that interprets edges and runs agents.
Agent graph with monitoring

Agent graphs: visual orchestration with per-node metrics overlaid directly on your workflow

What you’ll build

In this tutorial, you’ll add agent graphs to an existing multi-agent workflow:
  1. Build a graph visually in the LaunchDarkly UI
  2. Connect it to your code with a few lines of SDK integration
  3. Run your agents and watch the graph in action
  4. Monitor performance with per-node latency and invocation tracking
  5. Fix a slow agent by swapping models in the LaunchDarkly UI
By the end, you’ll have a multi-agent system where topology metadata changes happen in the UI, picked up by your traversal code on the next request.

Prerequisites

  • LaunchDarkly account with AgentControl access (sign up here)
  • Python 3.12+ and uv
  • An existing agent workflow (or use our sample repo)

The problem with hardcoded orchestration

Every multi-agent framework handles orchestration differently:
The topology is scattered across code. Agent graphs make it visible: you view the entire workflow in one place, edit connections in the UI, and traverse it with graph-aware SDK methods.

Why externalizing topology helps

If you’ve built multi-agent systems with LangGraph, OpenAI Swarm, or Strands, you’ve run into the same limitations:
  • Config duplication: Agent definitions scattered across framework-specific formats
  • Silent failures: An agent times out and you don’t know until users complain
  • No topology visibility: The workflow exists only in code
  • Custom observability: Getting consistent per-agent metrics means reconciling different trace formats and data schemas across frameworks
Deep dive on orchestratorsFor a detailed comparison of LangGraph, OpenAI Swarm, and Strands, read Compare AI orchestrators. Agent graphs work with multiple agent frameworks.
Agent graphs solve these by giving you a visual graph builder where you:
  • View your entire workflow at a glance, not buried in code
  • Monitor per-node metrics overlaid directly on the graph (latency, invocations, tool calls)
  • Add or remove agents without changing traversal logic, provided your runtime supports the node’s tools and output contract
  • Inspect routing logic on edges, with handoff data visible in the UI
  • Use graph-aware SDK primitives like resolve_graph(), reverse_traverse(), node.edges, and graph.root instead of hardcoding node wiring

Step 1: Create a project and configs

Agent graphs live in a LaunchDarkly project alongside your configs. Create a dedicated project for this tutorial, then seed it with an AgentControl config for each agent. The bootstrap script below handles config setup. If you already have a project, skip to Step 2.
Create a tutorial project firstAsk your coding assistant to create the project with the LaunchDarkly MCP server (or the projects agent skill), or create one manually under Account settings > Projects. Then copy its SDK key and project key into your .env.
New to AgentControl?Use the AgentControl quickstart or run the bootstrap script in our sample repo to seed your project with the three configs:
The bootstrap script creates the configs in the project you set in LD_PROJECT_KEY.
For this tutorial, we’ll use three configs:
  • supervisor-agent: Orchestrates the workflow and routes queries based on PII pre-screening
  • security-agent: Detects and redacts personally identifiable information (PII)
  • support-agent: Answers questions using dynamically loaded tools (search, RAG)

Step 2: Build the graph in the UI

This is where agent graphs diverge from code-based orchestration. Instead of writing add_edge() calls, you’ll view your topology and modify it visually. Open the LaunchDarkly UI and navigate to AI > Agent graphs.
  1. The first-time setup wizard appears. Since you already created configs in Step 1, expand Create a graph at the bottom.
First-time agent graph wizard

First-time setup wizard. Expand 'Create a graph' since you already have configs.

  1. Name your graph chatbot-flow and click Create graph.
Creating your first agent graph

Creating your first agent graph in the LaunchDarkly UI.

  1. Add your first node: click Add node and select supervisor-agent
  2. Add security-agent and support-agent as nodes
Adding security agent

Adding the security-agent node to the graph.

Adding support agent

Adding the support-agent node to complete the workflow.

  1. Draw edges: drag from supervisor-agent to both child agents
  2. Add handoff data to each edge to define routing logic:
supervisor-agent → security-agent:
PII detected edge

Edge from supervisor to security with route: security handoff data.

supervisor-agent → support-agent:
Clean edge

Edge from supervisor to support with route: support handoff data.

security-agent → support-agent:
Redacted edge

Edge from security to support with route: continue handoff data.

Notice what you’re seeing: the entire workflow topology in one view. This graph is your architecture diagram, always current. Each node shows which config variation it serves. The edges show routing logic that would otherwise be buried in conditional statements. When you need to add a new agent or change routing, you do it here, not in code.
The graph defines structure, your code defines behaviorLaunchDarkly doesn’t execute your graph. It provides:
  • Topology: Which nodes exist and how they connect
  • Handoff metadata: Whatever JSON you put on edges
  • Per-node config: Model, instructions, tools for each agent
Your code:
  • Decides which edges to follow based on agent decisions
  • Interprets handoff data however you want (the schema is yours)
  • Executes the actual agents
The handoff JSON is arbitrary metadata. You define the schema, you interpret it. LaunchDarkly stores and delivers it.

Step 3: Add the SDK to your project

Install the LaunchDarkly Python server SDK and the AI SDK core package:
Initialize the LaunchDarkly client and hand it to the AI SDK in config_manager.py:
Build a context for targeting and tracking. In the AI SDK, contexts are plain dictionaries:
Resolve the agent graph topology with resolve_graph() and pair it with GraphTracker for custom traversal telemetry:
Two ways to run an agent graphThe AI SDK offers a managed graph(key, handlers=...).invoke() runner that executes the graph and records all node and graph telemetry automatically. When your application walks the topology itself with resolve_graph(), as this tutorial does to support custom PII redaction state between hops, resolve_graph() returns topology only. The sample repo’s GraphTracker helper in config_manager.py emits the same $ld:ai:graph:* and per-node events on get_client().track() (converting the context dictionary with ldclient.Context.from_dict(context)).

Step 4: Integrate with your framework

This section walks through the integration code, starting with the building block (what runs at each node), then showing how nodes are orchestrated.

The generic agent pattern

The key to dynamic execution is create_generic_agent. Every node uses the same implementation, with no agent registry and no hardcoded agent types. In launchdarkly-ai-server 1.0+, each node’s config is a plain dictionary containing model, provider, instructions, and tools:
Why this enables adding agents without code changesThe generic agent pattern means:
  • No agent registry: Every node uses the same create_generic_agent function
  • Config-driven behavior: Model, instructions, and tools all come from LaunchDarkly
  • Dynamic routing: Valid routes are injected from graph edges, not hardcoded
  • Minimal code changes: Add a new agent in LaunchDarkly, create its config, add it to your graph, and it works, provided your runtime supports the node’s tools and output contract

The AgentService class

The AgentService class is the entry point for processing messages through your agent graph:

Executing the graph

The execute_with_graph method resolves the graph from LaunchDarkly, collects its nodes with reverse_traverse(), and walks from graph.root along the selected edges:
How edge-driven routing works
  1. Start at graph.root: The walk begins at supervisor-agent.
  2. Inspect current_node.edges: Each outgoing edge’s handoff["route"] value is injected into the node’s prompt so the model knows which routes exist.
  3. Follow only the selected edge: After the node runs, _select_next_node matches result["routing_decision"] against edge.handoff["route"] and advances current_node to nodes[edge.target_key].
The supervisor routes to either security-agent or support-agent, and only the chosen path executes. When security-agent runs, _update_context replaces ctx["messages"] with result["redacted"] so PII never reaches support-agent.

Routing between nodes

The _select_next_node method determines which node to route to based on the agent’s routing decision:
The key insight: your graph topology comes from LaunchDarkly, not hardcoded orchestration. Change the graph in the UI, and your code picks up the new structure on the next request.

Step 5: Run it

With the AgentService wired up in Step 4, you can process messages through your agent graph. The service handles:
  1. Building the LaunchDarkly context for targeting
  2. Resolving the graph and walking nodes along the selected edges
  3. Recording node and graph metrics for monitoring
  4. Returning the final response
Test it by sending a message:
Now go back to the LaunchDarkly UI. Add a new node or change an edge. Run your code again. Topology changes are picked up by your traversal code on subsequent SDK evaluations.

Step 6: Monitor agent performance

This is the key differentiator: monitoring happens on the graph itself, not in a separate view. Metrics appear overlaid on the same visual topology you built, which means bottlenecks are immediately obvious. The sample repo’s GraphTracker in config_manager.py records per-node duration, token usage, generation success or error, and tool calls alongside the graph-level node, handoff, and invocation events. If you use the SDK’s managed graph().invoke() runner, the SDK emits all of these events automatically. After running some traffic, open your agent graph to review the results. Navigate to AI > Agent graphs > chatbot-flow. A metrics bar at the top of the graph view lets you toggle different metrics on and off.

Metrics on the graph

Here’s what makes this different from traditional application performance monitoring (APM): the metrics appear directly on your workflow visualization. No mental mapping between a separate view and your code. No correlating trace IDs. The slow node lights up on the graph. Turn on Latency to review duration data overlaid directly on your graph:
  • Total duration: The combined time for the entire graph invocation.
  • Per-node duration: How long each individual agent takes.
Turn on Invocations to check how often each node is reached. This reveals which paths your users take most frequently. In a routing graph, you can quickly tell whether most queries go through security or skip directly to support. Turn on Tool calls to check the average number of tool invocations per node. If an agent is calling tools excessively, you’ll spot it here.

Monitoring page

Click Monitoring to review all metrics over time. This view shows:
  • Latency trends: Duration per node over hours, days, or weeks.
  • Invocation patterns: Traffic flow through your graph.
  • Tool call breakdown: Which specific tools are being called and how often.
Monitoring view

Node-level metrics broken down by agent, showing invocations, tool calls, and latency over time

Instrument tool trackingWhen walking a graph yourself with resolve_graph(), emit $ld:ai:tool_call with toolKey in the event payload for each tool an agent invokes, as GraphTracker.track_tool_call() does in the sample repo (or wrap your tool_handlers map with wrap_tool_handlers()). If you use graph().invoke() with tool_handlers, the SDK records $ld:ai:tool_call automatically.

Generate traffic to see metrics

Run the traffic generator from the sample repo to send queries through your graph:
This sends a mix of queries (some with PII, some without) to exercise both the security and support paths. After a few minutes, you’ll see metrics populate on the graph.

Detecting a slow agent

With traffic flowing, suppose the security-agent starts averaging 5 seconds per call. With latency metrics enabled on the graph, you see it immediately: the security-agent node shows a high duration value while other nodes stay fast. The invocation numbers also tell a story. If security-agent shows 50 invocations and support-agent shows 80, you know ~30 queries are bypassing security (the clean path). This helps you understand whether the slow agent is affecting most users or just a subset. Without agent graphs, you’d need custom logging, Datadog queries, and manual correlation. With agent graphs, you spot the problem in 30 seconds.

Step 7: Fix without deploying

The security-agent is slow because it’s using claude-sonnet-4-6 for PII detection. A smaller, faster model may be sufficient for this task. In the LaunchDarkly UI, update the security-agent variation:
  • Change model from Anthropic.claude-sonnet-4-6 to Anthropic.claude-haiku-4-5-20251001
Or use Agent Skills to make the change from your coding assistant:
No code changes. No deploy. Changes are picked up on subsequent SDK evaluations. Run the traffic generator again and watch the latency drop.

What just happened

  1. Traffic generator sent queries through the graph
  2. Monitoring showed the slow agent on the graph
  3. Model swap happened in the UI (or via Agent Skills)
  4. Your code automatically used the new configuration
No deploys. No PRs. The fix is live.

OpenAI Agents SDK integration (conceptual)

Agent graphs work with multiple frameworks. You can pass resolve_graph() directly to to_openai_agents from launchdarkly-ai-openai-agents, or build OpenAI Agent objects yourself with reverse_traverse():
Same graph definition, adapted to each framework’s execution model. The topology metadata lives in LaunchDarkly. Your code interprets and executes it.

Best practices

Start simple: Begin with a linear graph (A → B → C) before adding conditional routing. Use handoff data for context passing: Include metadata like action type, reason, or state that the next agent needs to continue the workflow. Let the SDK track if you use managed runners: If you run a graph with graph().invoke(), the SDK records all per-node and graph-level events automatically. Native framework runners (to_lang_graph, to_openai_agents, to_claude_agents) also emit a framework-specific subset of graph and node events automatically, which means you only need a custom helper like GraphTracker when walking resolve_graph() yourself. Test with targeting: Use LaunchDarkly targeting to route test users to experimental graph configurations. Handle unmatched routes and disabled graphs: When outgoing edges define route keys, fail closed if no edge matches the routing decision by recording a handoff failure and raising an error rather than falling back to another edge. Reserve unconditional handoffs for edges without route keys. Check graph.enabled before traversing, because turning off any node’s config disables the resolved graph as a whole. Keep execution state request-scoped: Store execution state inside the context object (ctx) passed through traversal, not in instance-level variables. Treat graph traversal as request-scoped to avoid concurrency issues.

Graph events reference

The managed graph().invoke() runner in the SDK and GraphTracker in the sample repo emit the following events. Native framework runners such as to_lang_graph, to_openai_agents, and to_claude_agents emit a subset of these events. Native runners never emit handoff_failure, omit sourceKey and targetKey on handoff_success, and always emit total_tokens. Only graph().invoke() and GraphTracker emit per-node $ld:ai:generation:error, and to_openai_agents also omits per-node duration and tokens. Build your custom metrics on these event keys:
EventValuePayloadWhen
$ld:ai:graph:node1nodeKey, indexOnce per node, as it is entered
$ld:ai:graph:handoff_success1sourceKey, targetKeyPer successful edge traversal
$ld:ai:graph:handoff_failure1sourceKey, targetKeyPer failed edge traversal
$ld:ai:graph:invocation_success1NoneOnce, when the walk completes
$ld:ai:graph:invocation_failure1NoneOnce, when the walk raises
$ld:ai:graph:total_tokensTotal tokensNoneOnce, and only when greater than zero
$ld:ai:graph:duration:totalElapsed msNoneOnce per run
$ld:ai:tool_call1toolKeyPer tool invocation
Every event carries runId and graphKey. Per-node events such as $ld:ai:tool_call, $ld:ai:duration:total, $ld:ai:generation:*, and $ld:ai:tokens:* also carry the node’s configKey, variationKey, version, modelName, and providerName, which means you can break down per-node metrics by variation or model. Under graph().invoke() and GraphTracker, all $ld:ai:graph:* events set configKey to the graph key and carry no model or provider, with variationKey and version reflecting the graph itself under graph().invoke(). Under native framework runners such as to_lang_graph, to_openai_agents, and to_claude_agents, $ld:ai:graph:node and $ld:ai:graph:handoff_success instead carry the node’s configKey, variationKey, version, modelName, and providerName. The four run-level graph events, $ld:ai:graph:invocation_success, $ld:ai:graph:invocation_failure, $ld:ai:graph:duration:total, and $ld:ai:graph:total_tokens, still carry the graph key and no model or provider. Keep three details in mind when building metrics on these events:
  • Node events fire per node, not per run: $ld:ai:graph:node fires once for each node entered, carrying its zero-based position in index. The ordered series of these events is the path the walk took.
  • Nodes are recorded on entry, not on completion: A run that fails inside its third node still leaves events for all three nodes, showing how far the failed run progressed.
  • Synthetic routing tools are excluded from $ld:ai:tool_call: Internal __handoff_ tools do not count toward $ld:ai:tool_call, which means the metric measures real tool use rather than graph routing. Use the handoff events for routing metrics.
Upgrading from the legacy AI SDKSeveral event keys changed between launchdarkly-server-sdk-ai and launchdarkly-ai-server. A metric built on an old key does not error. It stops receiving data, which looks like the feature losing traffic:
Legacy keyCurrent key
ld:ai:graph:path</code></td><td><code>ld:ai:graph:path</code></td> <td><code>ld:ai:graph:node, one event per node entered instead of one per run
ld:ai:graph:nodeinvocation</code>(0.15–0.16)</td><td><code>ld:ai:graph:node_invocation</code> (0.15–0.16)</td> <td><code>ld:ai:graph:node
ld:ai:graph:latency</code>(0.15–0.17)</td><td><code>ld:ai:graph:latency</code> (0.15–0.17)</td> <td><code>ld:ai:graph:duration:total
ld:ai:graph:toolcall</code>(0.15–0.16)</td><td><code>ld:ai:graph:tool_call</code> (0.15–0.16)</td> <td><code>ld:ai:tool_call
$ld:ai:graph:redirectRemoved, with no replacement
Other graph and tool event keys ($ld:ai:graph:handoff_success, $ld:ai:graph:handoff_failure, $ld:ai:graph:invocation_success, $ld:ai:graph:invocation_failure, $ld:ai:graph:total_tokens, and $ld:ai:tool_call in 0.17+) are unchanged. Keep your legacy metrics until the new ones receive data to keep the cutover visible.

What you’ve built

You now have a multi-agent system where:
  • Graph topology is externalized and self-documenting
  • Routing logic is visible on edges, not buried in code
  • Monitoring appears on the graph itself, not a separate view
  • Per-node configuration lets you update any agent’s model, instructions, or tools independently without touching other nodes
  • Multiple frameworks can consume the same graph metadata
When you spot a slow agent in monitoring, swap the model in the LaunchDarkly UI without a deploy.

Next steps

Conclusion

Hardcoded orchestration was fine when you had one agent. With multi-agent systems, it becomes a liability. Every change requires a deploy. Every incident requires a developer. Agent graphs flip this. Define your workflow in LaunchDarkly, integrate it with your framework, and fix many problems without touching code. Your agents become as dynamic as your feature flags. Ready to stop hardcoding? Get started with AgentControl and create your first agent graph.