Published September 22nd, 2025
This tutorial was published in September 2025, before LaunchDarkly shipped several features that complement or supersede the targeting patterns shown below. The walkthrough still works, but for new builds you may want to use:
To learn more, read AgentControl.
Here’s what nobody tells you about multi-agentic systems: the hard part isn’t building them but making them profitable. One misconfigured model serving enterprise features to free users can burn $20K in a weekend. Meanwhile, you’re manually juggling dozens of requirements for different user tiers, regions, and privacy compliance and each one is a potential failure point.
Part 2 of 3 of the series: Chaos to Clarity: Defensible AI Systems That Deliver on Your Goals
The solution? LangGraph multi-agent workflows controlled by config targeting rules that intelligently route users: paid customers get premium tools and models, free users get cost-efficient alternatives, and EU users get Mistral for enhanced privacy. Use the LaunchDarkly REST API to set up a custom variant-targeting matrix in 2 minutes instead of spending hours setting it up manually.
In the next 18 minutes, you’ll transform your basic multi-agent system with:
✅ Part 1 completed with exact naming:
multi-agent-chatbotsupervisor-agent, security-agent, support-agentsearch_v2, rerankingsupervisor-basic, pii-detector, rag-search-enhanced🔑 Add to your .env file:
The automation scripts in this tutorial use the LaunchDarkly REST API to programmatically create configurations. Here’s how to get your API key:
To get your LaunchDarkly API key, start by navigating to Organization Settings by clicking the gear icon (⚙️) in the left sidebar of your LaunchDarkly dashboard. Once there, access Authorization Settings by clicking “Authorization” in the settings menu. Next, create a new access token by clicking “Create token” in the “Access tokens” section.

When configuring your token, give it a descriptive name like “multi-agent-chatbot”, select “Writer” as the role (required for creating configurations), use the default API version (latest), and leave “This is a service token” unchecked for now.

After configuring the settings, click “Save token” and immediately copy the token value. This is IMPORTANT because it’s only shown once!

Finally, add the token to your environment:
Security Note: Keep your API key private and never commit it to version control. The token allows full access to your LaunchDarkly account.
Your agents need more than just your internal documents. Model Context Protocol (MCP) connects AI assistants to live external data and they agents become orchestrators of your digital infrastructure, tapping into databases, communication tools, development platforms, and any system that matters to your business. MCP tools run as separate servers that your agents call when needed.
The MCP Registry serves as a community-driven directory for discovering available MCP servers - like an app store for MCP tools. For this tutorial, we’ll use manual installation since our specific academic research servers (ArXiv and Semantic Scholar) aren’t yet available in the registry.
Install external research capabilities:
MCP Tools Added:
These tools integrate with your agents via LangGraph while LaunchDarkly controls which users get access to which tools.
Now we’ll use programmatic API automation to configure the complete setup. The LaunchDarkly REST API lets you manage tools, segments, and AgentControl programmatically. Instead of manually creating dozens of variations in the UI, this configuration automation makes REST API calls to provision user segments, config variations, targeting rules, and tools. These are the same resources you could create manually through the LaunchDarkly dashboard. Your actual chat application continues running unchanged.
Configure your complete targeting matrix with one command:
What the script creates:
search_v1 (basic search), arxiv_search and semantic_scholar (MCP research tools)security-agent with 2 new geographic variationssupervisor-agent, search_v2, and reranking tools from Part 1The automation works by reading a YAML manifest and translating it into LaunchDarkly API calls. Here’s how the key parts work:
Segment Creation with Geographic Rules:
Model Configuration Mapping:
Customizing for Your Use Case:
To adapt this for your own multi-agent system:
Add your geographic regions in the YAML segments:
Define your business tiers:
Map your models in the script:
The script handles the complexity of LaunchDarkly’s API while letting you define your targeting logic in simple YAML.
Expected terminal output:
In your LaunchDarkly dashboard, navigate to your multi-agent-chatbot project. You should see:
supervisor-agent, security-agent, support-agent) with new variationseu-free, eu-paid, other-free, other-paid)search_v1, arxiv_search, semantic_scholar)Troubleshooting Common Issues:
❌ Error: “LD_API_KEY environment variable not set”
.env file contains: LD_API_KEY=your-api-key❌ Error: “config ‘security-agent’ not found”
multi-agent-chatbotsupervisor-agent, security-agent, and support-agent exist in your LaunchDarkly project❌ Error: “Failed to create segment”
❌ Script runs but no changes appear
Here’s how the smart segmentation works:
By Region:
By Business Tier:
search_v1)search_v1, search_v2, reranking, arxiv_search, semantic_scholar)This geo-segmentation is fully correct for the non-Bedrock path (direct OpenAI / Anthropic / Mistral APIs) — EU vs non-EU routing of model, provider, and PII-redaction strictness works exactly as described. On the AWS Bedrock path it likewise segments the model and redaction correctly, but it cannot segment the AWS inference region: the region prefix is process-global (set once via BEDROCK_INFERENCE_REGION), so every Bedrock call in a deployment uses the same region regardless of the user’s EU/non-EU segment. Making the inference region a per-variation property is a planned LaunchDarkly enhancement; until then, run separate deployments per region if EU-region inference is a hard requirement.
The included test script simulates real user scenarios across all segments, verifying that your targeting rules work correctly. It sends actual API requests to your system and confirms each user type gets the right model, tools, and behavior.
First, start your system:
Expected test output:
This confirms your targeting matrix is working correctly across all user segments!
Now let’s see your segmentation in action through the user interface. With your backend already running from Step 4, start the UI:
Open http://localhost:8501 and test different user types:

In Part 3, we’ll prove what actually works using controlled A/B experiments:
Instead of guessing which configurations work better, you’ll have data proving which tool implementations provide value, which models use tools more efficiently, and what security enhancements actually costs in performance.
You’ve built something powerful: a multi-agent system that adapts to users by design. More importantly, you’ve proven that sophisticated AI applications don’t require repeated deployments; they require smart configuration.
This approach scales beyond tutorials. Whether you’re serving 100 users or 100,000, the same targeting principles apply: segment intelligently, configure dynamically, and let data guide decisions instead of assumptions.
Questions? Issues? Reach out at aiproduct@launchdarkly.com or open an issue in the GitHub repo.