Class LdAiClient
The LaunchDarkly AI client. The client is capable of retrieving AI Configs and agent graphs from LaunchDarkly, and generating events specific to usage of those configs when interacting with model providers.
Inherited Members
Namespace: LaunchDarkly.Sdk.Server.Ai
Assembly: LaunchDarkly.ServerSdk.Ai.dll
Syntax
public sealed class LdAiClient : ILdAiClient, ILdAiGraphClient
Constructors
| Edit this page View SourceLdAiClient(ILaunchDarklyClient)
Constructs a new LaunchDarkly AI client. Please note, the client library is an alpha release and is not considered ready for production use.
Example:
var baseClient = new LdClient(Configuration.Builder("my-sdk-key").Build());
var aiClient = new LdAiClient(new LdClientAdapter(baseClient));
Declaration
public LdAiClient(ILaunchDarklyClient client)
Parameters
| Type | Name | Description |
|---|---|---|
| ILaunchDarklyClient | client | an object satisfying ILaunchDarklyClient, such as an LdClientAdapter |
Methods
| Edit this page View SourceAgentConfig(string, Context, LdAiAgentConfigDefault, IReadOnlyDictionary<string, object>)
Retrieves a LaunchDarkly AI Agent Config identified by the given key. The return value
is an LdAiAgentConfig, which provides Instructions, Tools,
and a CreateTracker method for generating a tracker that emits model usage events.
Any variables provided will be interpolated into the agent's instructions. Additionally, the current LaunchDarkly context will be available as 'ldctx' within the instructions template.
Declaration
public LdAiAgentConfig AgentConfig(string key, Context context, LdAiAgentConfigDefault defaultValue = null, IReadOnlyDictionary<string, object> variables = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | the AI Agent Config key |
| Context | context | the context |
| LdAiAgentConfigDefault | defaultValue | the default config, if unable to retrieve from LaunchDarkly. When not provided, a disabled config is used as the fallback. |
| IReadOnlyDictionary<string, object> | variables | the list of variables used when interpolating the instructions |
Returns
| Type | Description |
|---|---|
| LdAiAgentConfig | an AI Agent Config |
AgentConfigTemplate(string, Context, LdAiAgentConfigDefault)
Retrieves a LaunchDarkly AI Agent Config with Mustache placeholders left intact (no interpolation). Useful for auditing instruction templates or building UI previews.
Declaration
public LdAiAgentConfig AgentConfigTemplate(string key, Context context, LdAiAgentConfigDefault defaultValue = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | the AI Agent Config key |
| Context | context | the context |
| LdAiAgentConfigDefault | defaultValue | the default config, if unable to retrieve from LaunchDarkly. When not provided, a disabled config is used as the fallback. |
Returns
| Type | Description |
|---|---|
| LdAiAgentConfig | an AI Agent Config with raw (non-interpolated) instructions |
AgentConfigs(IEnumerable<AgentConfigRequest>, Context)
Retrieves multiple LaunchDarkly AI Agent Configs in a single call. Each request is evaluated independently. A single aggregate usage event is fired for the entire batch.
Declaration
public IReadOnlyDictionary<string, LdAiAgentConfig> AgentConfigs(IEnumerable<AgentConfigRequest> agentConfigs, Context context)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<AgentConfigRequest> | agentConfigs | the collection of agent config requests |
| Context | context | the context |
Returns
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, LdAiAgentConfig> | a dictionary mapping each agent config key to its evaluated LdAiAgentConfig |
AgentGraph(string, Context, IReadOnlyDictionary<string, object>)
Retrieves and validates an agent graph identified by graphKey.
Fires a usage tracking event, evaluates the graph flag, fetches all agent configs
referenced in the graph, and performs connectivity validation. Returns an
AgentGraphDefinition whose Enabled property indicates whether
all validation steps passed.
Declaration
public AgentGraphDefinition AgentGraph(string graphKey, Context context, IReadOnlyDictionary<string, object> variables = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | graphKey | the LaunchDarkly flag key for the agent graph |
| Context | context | the context |
| IReadOnlyDictionary<string, object> | variables | optional variables interpolated into each node's agent instructions |
Returns
| Type | Description |
|---|---|
| AgentGraphDefinition | an agent graph definition |
CompletionConfig(string, Context, LdAiCompletionConfigDefault, IReadOnlyDictionary<string, object>)
Retrieves a LaunchDarkly AI Completion Config identified by the given key. The return value
is an LdAiCompletionConfig, which makes the configuration available and
provides a CreateTracker method (inherited from LdAiConfig) for
generating a tracker that emits events related to model usage.
Any variables provided will be interpolated into the prompt's messages. Additionally, the current LaunchDarkly context will be available as 'ldctx' within a prompt message.
Declaration
public LdAiCompletionConfig CompletionConfig(string key, Context context, LdAiCompletionConfigDefault defaultValue = null, IReadOnlyDictionary<string, object> variables = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | the AI Completion Config key |
| Context | context | the context |
| LdAiCompletionConfigDefault | defaultValue | the default config, if unable to retrieve from LaunchDarkly. When not provided, a disabled config is used as the fallback. |
| IReadOnlyDictionary<string, object> | variables | the list of variables used when interpolating the prompt |
Returns
| Type | Description |
|---|---|
| LdAiCompletionConfig | an AI Completion Config |
CompletionConfigTemplate(string, Context, LdAiCompletionConfigDefault)
Retrieves a LaunchDarkly AI Completion Config with Mustache placeholders left intact (no interpolation). Useful for displaying prompt previews or storing templates for later rendering.
Declaration
public LdAiCompletionConfig CompletionConfigTemplate(string key, Context context, LdAiCompletionConfigDefault defaultValue = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | the AI Completion Config key |
| Context | context | the context |
| LdAiCompletionConfigDefault | defaultValue | the default config, if unable to retrieve from LaunchDarkly. When not provided, a disabled config is used as the fallback. |
Returns
| Type | Description |
|---|---|
| LdAiCompletionConfig | an AI Completion Config with raw (non-interpolated) message content |
Config(string, Context, LdAiCompletionConfigDefault, IReadOnlyDictionary<string, object>)
Retrieves a LaunchDarkly AI Completion Config identified by the given key.
Declaration
[Obsolete("Use CompletionConfig instead.")]
public LdAiCompletionConfig Config(string key, Context context, LdAiCompletionConfigDefault defaultValue = null, IReadOnlyDictionary<string, object> variables = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | the AI Completion Config key |
| Context | context | the context |
| LdAiCompletionConfigDefault | defaultValue | the default config, if unable to retrieve from LaunchDarkly |
| IReadOnlyDictionary<string, object> | variables | the list of variables used when interpolating the prompt |
Returns
| Type | Description |
|---|---|
| LdAiCompletionConfig | an AI Completion Config |
CreateGraphTracker(string, Context)
Reconstructs a graph tracker from a resumption token. This enables cross-process continuation of graph-level metrics.
Declaration
public AiGraphTracker CreateGraphTracker(string resumptionToken, Context context)
Parameters
| Type | Name | Description |
|---|---|---|
| string | resumptionToken | the token obtained from ResumptionToken |
| Context | context | the context to use for track events |
Returns
| Type | Description |
|---|---|
| AiGraphTracker | a graph tracker associated with the original run |
CreateTracker(string, Context)
Reconstructs a tracker from a resumption token. This enables cross-process scenarios such as deferred feedback, where a tracker's runId needs to be reused in a different process or at a later time.
The reconstructed tracker will have empty model and provider names, as these are not included in the resumption token.
Declaration
public ILdAiConfigTracker CreateTracker(string resumptionToken, Context context)
Parameters
| Type | Name | Description |
|---|---|---|
| string | resumptionToken | the resumption token obtained from ResumptionToken |
| Context | context | the context to use for track events |
Returns
| Type | Description |
|---|---|
| ILdAiConfigTracker | a tracker associated with the original runId |
JudgeConfig(string, Context, LdAiJudgeConfigDefault, IReadOnlyDictionary<string, object>)
Retrieves a LaunchDarkly AI Judge Config identified by the given key. The return value
is an LdAiJudgeConfig, which provides Messages, EvaluationMetricKey,
and a CreateTracker method for generating a tracker that emits model usage events.
Any variables provided will be interpolated into the judge's prompt messages. Additionally, the current LaunchDarkly context will be available as 'ldctx' within the message templates.
Declaration
public LdAiJudgeConfig JudgeConfig(string key, Context context, LdAiJudgeConfigDefault defaultValue = null, IReadOnlyDictionary<string, object> variables = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | the AI Judge Config key |
| Context | context | the context |
| LdAiJudgeConfigDefault | defaultValue | the default config, if unable to retrieve from LaunchDarkly. When not provided, a disabled config is used as the fallback. |
| IReadOnlyDictionary<string, object> | variables | the list of variables used when interpolating the messages |
Returns
| Type | Description |
|---|---|
| LdAiJudgeConfig | an AI Judge Config |
JudgeConfigTemplate(string, Context, LdAiJudgeConfigDefault)
Retrieves a LaunchDarkly AI Judge Config with Mustache placeholders left intact (no interpolation). Useful for auditing judge prompt templates.
Declaration
public LdAiJudgeConfig JudgeConfigTemplate(string key, Context context, LdAiJudgeConfigDefault defaultValue = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | the AI Judge Config key |
| Context | context | the context |
| LdAiJudgeConfigDefault | defaultValue | the default config, if unable to retrieve from LaunchDarkly. When not provided, a disabled config is used as the fallback. |
Returns
| Type | Description |
|---|---|
| LdAiJudgeConfig | an AI Judge Config with raw (non-interpolated) message content |