Skip to content

feat: Add template config methods to AI SDK#299

Merged
mattrmc1 merged 3 commits into
mainfrom
mmccarthy/AIC-2853/net-enable-raw-prompt
Jun 29, 2026
Merged

feat: Add template config methods to AI SDK#299
mattrmc1 merged 3 commits into
mainfrom
mmccarthy/AIC-2853/net-enable-raw-prompt

Conversation

@mattrmc1

@mattrmc1 mattrmc1 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds CompletionConfigTemplate, AgentConfigTemplate, and JudgeConfigTemplate to LaunchDarkly.ServerSdk.Ai. These methods return the same config types as their non-template counterparts but skip Mustache interpolation, preserving {{variable}} and {{ldctx.key}} placeholders verbatim. Useful for displaying prompt previews, storing templates for later rendering, or auditing prompt content without variable substitution.

Template methods on ILdAiClient

public LdAiCompletionConfig CompletionConfigTemplate(string key, Context context,
    LdAiCompletionConfigDefault defaultValue = null);

public LdAiAgentConfig AgentConfigTemplate(string key, Context context,
    LdAiAgentConfigDefault defaultValue = null);

public LdAiJudgeConfig JudgeConfigTemplate(string key, Context context,
    LdAiJudgeConfigDefault defaultValue = null);

Each template method fires a -template suffixed usage event ($ld:ai:usage:completion-config-template, $ld:ai:usage:agent-config-template, $ld:ai:usage:judge-config-template) and does not fire the standard usage event. The variables parameter is omitted since interpolation is skipped.

Shared evaluator helpers in LdAiClient

To avoid duplicating the defaultValue ??= + JsonVariation + factory call pattern between non-template and template methods, private BuildCompletionConfig and BuildJudgeConfig helpers were introduced, matching the pre-existing BuildAgentConfig pattern. Both the standard and template public methods delegate through these helpers:

// Standard path
public LdAiCompletionConfig CompletionConfig(string key, Context context, ...)
{
    _client.Track(TrackUsageCompletionConfig, context, LdValue.Of(key), 1);
    return BuildCompletionConfig(key, context, defaultValue, variables);
}

// Template path
public LdAiCompletionConfig CompletionConfigTemplate(string key, Context context, ...)
{
    _client.Track(TrackUsageCompletionConfigTemplate, context, LdValue.Of(key), 1);
    return BuildCompletionConfig(key, context, defaultValue, variables: null, interpolate: false);
}

ConfigFactory changes

BuildCompletionConfig, BuildAgentConfig, BuildJudgeConfig and their Build*FromDefault counterparts (6 methods total) accept a new bool interpolate = true parameter. When false, MergeVariables() is skipped and messages/instructions are parsed but not interpolated. All existing call sites are unchanged (default true).

Migration

None required. ILdAiClient gains three new members — this is additive only. Existing consumers that call the SDK through the concrete LdAiClient class are unaffected. Consumers that implement ILdAiClient in test doubles will need to add stub implementations for the three new methods.

Test plan

  • dotnet test pkgs/sdk/server-ai/test/LaunchDarkly.ServerSdk.Ai.Tests.csproj --framework net8.0 passes
  • CompletionConfigTemplate tests cover placeholder preservation, ldctx non-interpolation, template tracking event (with negative verification that the standard event is not fired), disabled default fallback, and CreateTracker non-null
  • AgentConfigTemplate tests cover the same scenarios for agent configs (instructions rather than messages)
  • JudgeConfigTemplate tests cover the same scenarios for judge configs

Note

Low Risk
Additive API with default-on interpolation preserved for existing callers; risk is limited to consumers relying on template methods for production prompts without rendering variables themselves.

Overview
Adds template fetch APIs on the server AI SDK so completion, agent, and judge configs can be loaded without Mustache interpolation—placeholders like {{name}} and {{ldctx.key}} stay in the returned messages or instructions for previews, auditing, or deferred rendering.

ConfigFactory now accepts an optional interpolate flag (default true) on all three build paths; when false it skips variable merging and returns parsed prompt text as-is. Existing CompletionConfig / AgentConfig / JudgeConfig behavior is unchanged. LdAiClient exposes CompletionConfigTemplate, AgentConfigTemplate, and JudgeConfigTemplate on ILdAiClient, each emitting a dedicated usage track event ($ld:ai:usage:*-config-template) instead of the normal config usage events.

Reviewed by Cursor Bugbot for commit 93bd420. Bugbot is set up for automated code reviews on this repo. Configure here.

@mattrmc1 mattrmc1 marked this pull request as ready for review June 29, 2026 15:11
@mattrmc1 mattrmc1 requested a review from a team as a code owner June 29, 2026 15:11
@mattrmc1 mattrmc1 marked this pull request as draft June 29, 2026 15:11
@mattrmc1 mattrmc1 changed the title feat: implements template methods for fetching non-interpolated config feat: Add template config methods to AI SDK Jun 29, 2026
@mattrmc1 mattrmc1 marked this pull request as ready for review June 29, 2026 15:21
@andrewklatzke

Copy link
Copy Markdown

Not any kind of expert with .net but the code seems straightforward and the API matches the expectation 👍

@mattrmc1 mattrmc1 requested a review from tanderson-ld June 29, 2026 18:59
@mattrmc1 mattrmc1 merged commit 1b96e4a into main Jun 29, 2026
18 of 19 checks passed
@mattrmc1 mattrmc1 deleted the mmccarthy/AIC-2853/net-enable-raw-prompt branch June 29, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants