Skip to content

feat: Add template config methods to AI SDK#184

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

feat: Add template config methods to AI SDK#184
mattrmc1 wants to merge 1 commit 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 with existing interpolation paths explicitly unchanged; custom LDAIClient test doubles must implement three new methods.

Overview
Adds completionConfigTemplate, agentConfigTemplate, and judgeConfigTemplate on LDAIClient so callers can fetch flag-evaluated configs (model, enabled state, etc.) while leaving {{variable}} and {{ldctx.*}} placeholders in messages/instructions unchanged—no variables argument.

LDAIClientImpl threads a boolean interpolate through evaluate, buildConfig, and buildConfigFromDefault. Existing completionConfig / agentConfig / judgeConfig paths pass true (behavior unchanged). Template entry points pass null variables and false, skipping Interpolator for parsed flag content and caller defaults.

Template calls emit -template usage metrics ($ld:ai:usage:*-config-template) instead of the standard usage events. Tests cover tracking, placeholder preservation, ldctx non-substitution, null-default disabled configs, and non-null trackers.

Reviewed by Cursor Bugbot for commit b5c9cdf. 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