Retrieves and processes a single AI Config agent based on the provided key, LaunchDarkly context, and variables. This includes the model configuration and the customized instructions.
The key of the AI Config agent.
The LaunchDarkly context object that contains relevant information about the current environment, user, or session. This context may influence how the configuration is processed or personalized.
Optional defaultValue: LDAIAgentConfigDefaultOptional fallback when the configuration is not available from LaunchDarkly. When omitted or null, a disabled default is used.
Optional Optional variables: Record<string, unknown>A map of key-value pairs representing dynamic variables to be injected into the instructions. The keys correspond to placeholders within the template, and the values are the corresponding replacements.
Optional Optional defaultAiProvider: "openai" | "langchain" | "vercel"Optional An LDAIAgentConfig with customized instructions, model,
provider, and a createTracker() factory. Call createTracker() on the
returned config to obtain a tracker for each AI run. If the configuration
cannot be accessed from LaunchDarkly, the return value will include
information from the defaultValue.
const key = "research_agent";
const context = {...};
const variables = { topic: 'climate change' };
const agentConfig = await client.agentConfig(key, context, {
enabled: true,
model: { name: 'gpt-4' },
provider: { name: 'openai' },
instructions: 'You are a research assistant.',
}, variables);
if (agentConfig.enabled) {
const tracker = agentConfig.createTracker();
const researchResult = agentConfig.instructions; // Interpolated instructions
tracker.trackSuccess();
}
Retrieves and processes multiple AI Config agents based on the provided agent configurations and LaunchDarkly context. This includes the model configuration and the customized instructions.
An array of agent configurations, each containing the agent key, optional default configuration (when omitted or null, a disabled default is used), and variables for instructions interpolation.
The LaunchDarkly context object that contains relevant information about the current environment, user, or session. This context may influence how the configuration is processed or personalized.
A map of agent keys to their respective LDAIAgentConfigs,
each with customized instructions and a createTracker() factory. Call
createTracker() on a returned config to obtain a tracker for each AI run.
If a configuration cannot be accessed from LaunchDarkly, the return value
will include information from the respective defaultValue.
const agentConfigsList = [
{
key: 'research_agent',
defaultValue: {
enabled: true,
model: { name: 'gpt-4' },
provider: { name: 'openai' },
instructions: 'You are a research assistant.'
},
variables: { topic: 'climate change' }
},
{
key: 'writing_agent',
defaultValue: {
enabled: true,
model: { name: 'gpt-4' },
provider: { name: 'openai' },
instructions: 'You are a writing assistant.'
},
variables: { style: 'academic' }
}
] as const;
const context = {...};
const configs = await client.agentConfigs(agentConfigsList, context);
if (configs["research_agent"].enabled) {
const tracker = configs["research_agent"].createTracker();
const researchResult = configs["research_agent"].instructions; // Interpolated instructions
tracker.trackSuccess();
}
Fetches an agent graph configuration from LaunchDarkly and returns an AgentGraphDefinition.
When the graph is enabled the method validates that:
If any validation check fails, the returned definition has
enabled set to false with an empty
node collection. When the logger level is DEBUG, a message describing the
failure is emitted.
The LaunchDarkly flag key for the agent graph configuration.
The LaunchDarkly context used for flag evaluation and tracking.
Optional variables: Record<string, unknown>Optional key-value pairs used for Mustache template interpolation in each node's agent config instructions. Applied uniformly to all nodes.
Optional A promise that resolves to an AgentGraphDefinition. Check enabled before traversing.
const graph = await aiClient.agentGraph('my-agent-graph', context, { userName: 'Sandy' });
if (graph.enabled) {
graph.traverse((node, ctx) => {
// build your provider-specific node here
});
}
Retrieves and processes a completion AI Config based on the provided key, LaunchDarkly context, and variables. This includes the model configuration and the customized messages.
The key of the AI Config.
The LaunchDarkly context object that contains relevant information about the current environment, user, or session. This context may influence how the configuration is processed or personalized.
Optional defaultValue: LDAICompletionConfigDefaultOptional fallback when the configuration is not available from LaunchDarkly. When omitted or null, a disabled default is used.
Optional Optional variables: Record<string, unknown>A map of key-value pairs representing dynamic variables to be injected into the message content. The keys correspond to placeholders within the template, and the values are the corresponding replacements.
Optional Optional defaultAiProvider: "openai" | "langchain" | "vercel"Optional An LDAICompletionConfig with enabled, model, provider,
messages, and a createTracker() factory. Call createTracker() on the
returned config to obtain a tracker for each AI run. If the configuration
cannot be accessed from LaunchDarkly, the return value will include
information from the defaultValue.
const key = "welcome_prompt";
const context = {...};
const variables = {username: 'john'};
const defaultValue = {
enabled: true,
model: { name: 'gpt-4' },
provider: { name: 'openai' },
};
const completionConfig = await client.completionConfig(key, context, defaultValue, variables);
if (completionConfig.enabled) {
const tracker = completionConfig.createTracker();
// Use completionConfig.messages and completionConfig.model with your LLM,
// then record metrics with tracker.trackSuccess(), tracker.trackTokens(), etc.
}
Creates and returns a new ManagedAgent instance for agent interactions. Evaluations are wired automatically and exposed on ManagedResult.evaluations.
The key identifying the agent AI config to use.
The standard LDContext used when evaluating flags.
Optional defaultValue: LDAIAgentConfigDefaultOptional fallback when the configuration is not available from LaunchDarkly.
Optional Optional variables: Record<string, unknown>Dictionary of values for instruction interpolation.
Optional Optional defaultAiProvider: "openai" | "langchain" | "vercel"Optional default AI provider to use.
Optional A promise that resolves to the ManagedAgent instance, or undefined if disabled.
Reconstructs an LDGraphTracker from a resumption token, preserving
the original runId so events from a resumed session are correlated correctly.
Security note: The token encodes the flag variation key and version. Keep it server-side; do not expose it to untrusted clients.
URL-safe Base64-encoded token from LDGraphTracker.resumptionToken.
LDContext to associate with the reconstructed tracker.
Creates and returns a new Judge instance for AI evaluation.
The key identifying the AI judge configuration to use
Standard LDContext used when evaluating flags
Optional defaultValue: LDAIJudgeConfigDefaultOptional fallback when the configuration is not available from LaunchDarkly. When omitted or null, a disabled default is used.
Optional Optional variables: Record<string, unknown>Dictionary of values for instruction interpolation.
The variables message_history and response_to_evaluate are reserved for the judge and will be ignored.
Optional Optional defaultAiProvider: "openai" | "langchain" | "vercel"Optional default AI provider to use.
Optional Optional sampleRate: numberOptional default sampling rate (0-1) baked into the Judge.
Used by Judge.evaluate() when no per-call rate is supplied. Defaults to 1.0.
Optional Promise that resolves to a Judge instance or undefined if disabled/unsupported
const judge = await client.createJudge(
"relevance-judge",
context,
{
enabled: true,
model: { name: "gpt-4" },
provider: { name: "openai" },
evaluationMetricKey: '$ld:ai:judge:relevance',
messages: [{ role: 'system', content: 'You are a relevance judge.' }]
},
{ metric: "relevance" }
);
if (judge) {
const result = await judge.evaluate("User question", "AI response");
console.log('Relevance score:', result.evals.relevance?.score);
}
Creates and returns a new ManagedModel instance for LLM model interactions.
The key identifying the AI completion configuration to use.
The standard LDContext used when evaluating flags.
Optional defaultValue: LDAICompletionConfigDefaultOptional fallback when the configuration is not available from LaunchDarkly. When omitted or null, a disabled default is used.
Optional Optional variables: Record<string, unknown>Dictionary of values for instruction interpolation.
The variables will also be used for judge evaluation. For the judge only, the variables
message_history and response_to_evaluate are reserved and will be ignored.
Optional Optional defaultAiProvider: "openai" | "langchain" | "vercel"Optional default AI provider to use.
Optional A promise that resolves to the ManagedModel instance, or undefined if the configuration is disabled.
const key = "customer_support_chat";
const context = {...};
const defaultValue = {
enabled: true,
model: { name: "gpt-4" },
provider: { name: "openai" },
messages: [
{ role: "system", content: "You are a helpful customer support agent." }
]
};
const variables = { customerName: 'John' };
const model = await client.createModel(key, context, defaultValue, variables);
if (model) {
const result = await model.run("I need help with my order");
console.log(result.content);
}
Reconstructs an AIConfigTracker from a resumption token string previously
obtained from a tracker's resumptionToken property. Use this to associate
deferred events (such as user feedback) with the original tracker's runId.
A URL-safe Base64-encoded resumption token string.
The evaluation context to use for subsequent track calls.
A reconstructed AIConfigTracker with the original runId preserved.
Retrieves and processes a Judge AI Config based on the provided key, LaunchDarkly context, and variables. This includes the model configuration and the customized messages for evaluation.
The key of the Judge AI Config.
The LaunchDarkly context object that contains relevant information about the current environment, user, or session. This context may influence how the configuration is processed or personalized.
Optional defaultValue: LDAIJudgeConfigDefaultOptional fallback when the configuration is not available from LaunchDarkly. When omitted or null, a disabled default is used.
Optional Optional variables: Record<string, unknown>Optional variables for template interpolation in messages and instructions.
Optional A promise that resolves to an LDAIJudgeConfig with enabled,
model, provider, messages, evaluationMetricKey, and a createTracker()
factory. Call createTracker() on the returned config to obtain a tracker for
each AI run.
const judgeConf = await client.judgeConfig(key, context, {
enabled: true,
model: { name: 'gpt-4' },
provider: { name: 'openai' },
evaluationMetricKey: '$ld:ai:judge:relevance',
messages: [{ role: 'system', content: 'You are a relevance judge.' }]
}, variables);
if (judgeConf.enabled) {
const tracker = judgeConf.createTracker();
// Use judgeConf.messages and judgeConf.model with your LLM,
// then record metrics with tracker.trackSuccess(), tracker.trackJudgeResult(), etc.
}
Generated using TypeDoc
Interface for performing AI operations using LaunchDarkly.