feat: Add template config methods to AI SDK#299
Merged
Conversation
|
Not any kind of expert with .net but the code seems straightforward and the API matches the expectation 👍 |
andrewklatzke
approved these changes
Jun 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
CompletionConfigTemplate,AgentConfigTemplate, andJudgeConfigTemplatetoLaunchDarkly.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
ILdAiClientEach template method fires a
-templatesuffixed 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. Thevariablesparameter is omitted since interpolation is skipped.Shared evaluator helpers in
LdAiClientTo avoid duplicating the
defaultValue ??=+JsonVariation+ factory call pattern between non-template and template methods, privateBuildCompletionConfigandBuildJudgeConfighelpers were introduced, matching the pre-existingBuildAgentConfigpattern. Both the standard and template public methods delegate through these helpers:ConfigFactorychangesBuildCompletionConfig,BuildAgentConfig,BuildJudgeConfigand theirBuild*FromDefaultcounterparts (6 methods total) accept a newbool interpolate = trueparameter. Whenfalse,MergeVariables()is skipped and messages/instructions are parsed but not interpolated. All existing call sites are unchanged (defaulttrue).Migration
None required.
ILdAiClientgains three new members — this is additive only. Existing consumers that call the SDK through the concreteLdAiClientclass are unaffected. Consumers that implementILdAiClientin 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.0passesCompletionConfigTemplatetests cover placeholder preservation,ldctxnon-interpolation, template tracking event (with negative verification that the standard event is not fired), disabled default fallback, andCreateTrackernon-nullAgentConfigTemplatetests cover the same scenarios for agent configs (instructions rather than messages)JudgeConfigTemplatetests cover the same scenarios for judge configsNote
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.ConfigFactorynow accepts an optionalinterpolateflag (default true) on all three build paths; when false it skips variable merging and returns parsed prompt text as-is. ExistingCompletionConfig/AgentConfig/JudgeConfigbehavior is unchanged.LdAiClientexposesCompletionConfigTemplate,AgentConfigTemplate, andJudgeConfigTemplateonILdAiClient, 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.