This guide shows how to connect an Anthropic Claude-powered application to LaunchDarkly AgentControl. Claude is well-suited for complex reasoning, code generation, and long-context tasks. By the end, you will be able to manage your model configuration and prompts outside of your application code, and track metrics automatically.
AgentControl supports two modes:
instructions string. Use it when your runtime or framework expects a goal/instructions input for a structured workflow. Agent mode changes the configuration shape from messages to instructions. Your application maps these instructions into your provider or framework’s native input.Both modes support tool calling. This guide walks through completion mode as the main path, with an optional agent config section. To learn more about when to use each mode, read When to use completion mode vs agent mode.
This guide provides examples in both Python and Node.js (TypeScript).
If you’re new to AgentControl, start with the Quickstart and return to this guide when you are ready for a more detailed example.
To learn more about AgentControl-specific SDKs, read AI SDKs. For Python-specific details, read the Python AI SDK reference.
To complete this guide, you need the following:
Before you begin, review these key concepts.
An AgentControl config is a LaunchDarkly resource that controls how your application uses large language models. Each AgentControl config contains one or more variations. Each variation specifies:
You can update these settings in LaunchDarkly at any time without changing your application code.
A context represents the end user interacting with your application. LaunchDarkly uses context attributes to:
{{ ldctx.* }} placeholders in your prompts with context attribute valuesOther placeholders, such as {{ topic }}, are populated from the variables argument you pass at runtime.
When you retrieve an AgentControl config, call createTracker() (Node.js) or create_tracker() (Python) on the returned object to mint a tracker. The tracker records metrics from your Anthropic calls, including:
These metrics appear on the AI Insights dashboard in LaunchDarkly.
Install the LaunchDarkly AI SDK and the Anthropic SDK in your application. AgentControl is supported by LaunchDarkly server-side SDKs only. The Node.js examples in this guide use the server-side Node.js AI SDK.
Here is how to install the required packages:
Create a .env file in your project root to store your API keys:
Add .env to your .gitignore to keep credentials out of version control.
Initialize both the LaunchDarkly client and the Anthropic client. Store your API keys in environment variables.
Here is the initialization code:
Create an AgentControl config in the LaunchDarkly UI to store your Anthropic model settings and prompts.
If you have the LaunchDarkly MCP server or agent skills configured, prompt your coding assistant to create the AgentControl config for you. For example:
“Create a completion mode AgentControl config called ‘Anthropic assistant’ with a ‘Claude Sonnet 4’ variation using the claude-sonnet-4-20250514 model, temperature 0.7, maxTokens 1024, and the system message: ‘You are a helpful assistant. Answer questions about {{topic}}.’ Enable targeting.”
To create the AgentControl config:
To create a variation:
claude-sonnet-4-20250514 Anthropic model.temperature to 0.7 and maxTokens to 1024.
To enable targeting:

Retrieve the AgentControl config from LaunchDarkly by calling the completion config function. Pass a context that represents the current user. You can also pass an optional fallback configuration so your application fails gracefully if LaunchDarkly is unreachable.
Here is how to get the AgentControl config:
Check the enabled property and handle the disabled case in your application. When you pass a fallback configuration, the SDK uses it if LaunchDarkly is unreachable.
For production use:
Anthropic’s Messages API expects a specific format. The system message goes in a top-level system parameter, separate from the user/assistant messages.
To track metrics, define an anthropic_metrics (Python) / anthropicMetrics (TypeScript) converter function that maps an Anthropic response to an LDAIMetrics object. Then pass it to tracker.track_metrics_of / tracker.trackMetricsOf along with a callable that performs the Anthropic API call. The tracker handles duration, success, and error tracking automatically.
Define the metrics converter:
Then call Anthropic with the config using tracker.track_metrics_of / tracker.trackMetricsOf. Variation parameters are stored in the same snake_case shape Anthropic’s SDK expects (max_tokens, top_p, …), so they pass through directly:
Agent-mode AgentControl configs return a single instructions string instead of a message list, and they let you attach reusable tools from the LaunchDarkly tools library. With Anthropic, the instructions map to the top-level system parameter and tools pass through on the top-level tools parameter.
First, define the tool in LaunchDarkly so the AgentControl config variation can reference it:
get_order_status as the Key.

claude-sonnet-4-20250514.max_tokens to 1024.get_order_status.
To learn more about managing tools, read Tools in AgentControl.
Use agent_config() instead of completion_config(). The SDK returns the attached tools under parameters.tools in OpenAI’s type=function shape, so convert them to Anthropic’s {name, description, input_schema} shape and pass them on the top-level tools= argument. Tool handler functions stay in your application code — LaunchDarkly stores the schema, your application owns the behavior.
In completion mode, you can attach judges to variations in the LaunchDarkly UI for automatic evaluation. In agent mode, invoke judges programmatically through the AI SDK.
To learn more, read When to use completion mode vs agent mode and Agents in AgentControl.
Use the LaunchDarkly UI to monitor how your applications are performing across all AgentControl configs and for individual configs.
To view aggregated metrics across all your AgentControl configs, navigate to Insights in the left navigation under the AI section. The Insights overview page displays cost, latency, error rate, invocation counts, and model distribution across your organization. To learn more, read AI Insights.
To view metrics for a specific AgentControl config:
The dashboard displays the following metrics:
Metrics update approximately every minute. Use these metrics to compare variations and optimize your prompts. To learn more, read Monitor AgentControl configs.

The AI SDKs emit OpenTelemetry-compatible spans for each generation call. You can forward these spans to your existing observability stack for deeper analysis. To learn more, read Observability and LLM observability.
Close the LaunchDarkly client when your application shuts down to flush pending events.
Here is how to close the client:
Always flush events before closing. Trailing events are at risk of being lost otherwise, in short-lived scripts and long-running services alike.
Here is how to flush events:
Here is a complete working example that combines all the steps.
After you have the basic integration working, you can extend it with:
For more AgentControl guides, read the other guides in the AgentControl guides section.
If you are experiencing problems with your configuration, this section lists common errors and solutions.
If metrics do not appear on the AI Insights dashboard:
tracker.track_metrics_of() (Python) or tracker.trackMetricsOf() (Node.js) with the correct metrics converter.flush() before closing the client, especially for short-lived scripts.If the LaunchDarkly SDK fails to initialize:
If you always receive the fallback configuration:
If you receive Anthropic API errors:
In this guide, you connected an Anthropic Claude-powered application to LaunchDarkly AgentControl. You can now: