Skip to content

feat: Add template config methods to AI SDK#184

Open
mattrmc1 wants to merge 3 commits into
mainfrom
mmccarthy/AIC-2854/java-enable-raw-prompt
Open

feat: Add template config methods to AI SDK#184
mattrmc1 wants to merge 3 commits into
mainfrom
mmccarthy/AIC-2854/java-enable-raw-prompt

Conversation

@mattrmc1

@mattrmc1 mattrmc1 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds completionConfigTemplate, agentConfigTemplate, and judgeConfigTemplate to LDAIClient. 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 LDAIClient

AICompletionConfig completionConfigTemplate(String key, LDContext context,
    AICompletionConfigDefault defaultValue);

AIAgentConfig agentConfigTemplate(String key, LDContext context,
    AIAgentConfigDefault defaultValue);

AIJudgeConfig judgeConfigTemplate(String key, LDContext context,
    AIJudgeConfigDefault defaultValue);

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.

LDAIClientImpl changes

The private evaluate, buildConfig, and buildConfigFromDefault methods accept a new boolean interpolate parameter. When false, interpolateMessages() / interpolate() calls are skipped and messages/instructions are passed through as-is from the parsed flag value or caller-supplied default. All existing call sites pass true — behavior is unchanged.

// Standard path
public AICompletionConfig completionConfig(String key, LDContext context, ...) {
    client.trackMetric(TRACK_USAGE_COMPLETION_CONFIG, context, LDValue.of(key), 1);
    return (AICompletionConfig) evaluate(key, context, effectiveDefault, Mode.COMPLETION, variables, true);
}

// Template path
public AICompletionConfig completionConfigTemplate(String key, LDContext context, ...) {
    client.trackMetric(TRACK_USAGE_COMPLETION_CONFIG_TEMPLATE, context, LDValue.of(key), 1);
    return (AICompletionConfig) evaluate(key, context, effectiveDefault, Mode.COMPLETION, null, false);
}

Migration

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

Test plan

  • ./gradlew :lib:sdk:server-ai:test passes
  • completionConfigTemplateFiresTemplateUsageEvent — verifies the correct -template tracking event is emitted
  • completionConfigTemplatePreservesPlaceholders{{name}} survives in message content
  • completionConfigTemplateDoesNotInterpolateLdctx{{ldctx.key}} is not substituted with the context key
  • completionConfigTemplateNullDefaultYieldsDisabled — absent flag with null default returns disabled config
  • completionConfigTemplateHasTrackercreateTracker() returns non-null
  • agentConfigTemplate* — same five scenarios for agent configs (instructions rather than messages)
  • judgeConfigTemplate* — same five scenarios for judge configs

Note

Low Risk
Additive API and a guarded code path; existing config retrieval still interpolates and is covered by existing plus new tests.

Overview
Adds completionConfigTemplate, agentConfigTemplate, and judgeConfigTemplate on LDAIClient so callers can evaluate flags and get the same typed configs while leaving Mustache placeholders (including {{ldctx.*}}) unchanged—intended for previews, auditing, and storing templates for later rendering.

LDAIClientImpl threads a new interpolate flag through evaluate / buildConfig / buildConfigFromDefault; existing *Config paths still pass true, while template methods pass false, omit variables, and emit -template usage metrics instead of the standard config usage events. Unit tests cover tracking, placeholder preservation, disabled defaults, and trackers.

Reviewed by Cursor Bugbot for commit 82dcf60. 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 22:57
@mattrmc1 mattrmc1 requested a review from a team as a code owner June 29, 2026 22: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.

1 participant