feat: Add template config methods to AI SDK#184
Open
mattrmc1 wants to merge 1 commit into
Open
Conversation
…figTemplate methods
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, andjudgeConfigTemplatetoLDAIClient. 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
LDAIClientEach 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.LDAIClientImplchangesThe private
evaluate,buildConfig, andbuildConfigFromDefaultmethods accept a newboolean interpolateparameter. Whenfalse,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 passtrue— behavior is unchanged.Migration
None required.
LDAIClientgains three new members — this is additive only. Existing consumers that call the SDK through the concreteLDAIClientImplclass are unaffected. Consumers that implementLDAIClientin test doubles will need to add stub implementations for the three new methods.Test plan
./gradlew :lib:sdk:server-ai:testpassescompletionConfigTemplateFiresTemplateUsageEvent— verifies the correct-templatetracking event is emittedcompletionConfigTemplatePreservesPlaceholders—{{name}}survives in message contentcompletionConfigTemplateDoesNotInterpolateLdctx—{{ldctx.key}}is not substituted with the context keycompletionConfigTemplateNullDefaultYieldsDisabled— absent flag with null default returns disabled configcompletionConfigTemplateHasTracker—createTracker()returns non-nullagentConfigTemplate*— same five scenarios for agent configs (instructions rather than messages)judgeConfigTemplate*— same five scenarios for judge configsNote
Low Risk
Additive API with existing interpolation paths explicitly unchanged; custom
LDAIClienttest doubles must implement three new methods.Overview
Adds
completionConfigTemplate,agentConfigTemplate, andjudgeConfigTemplateonLDAIClientso callers can fetch flag-evaluated configs (model, enabled state, etc.) while leaving{{variable}}and{{ldctx.*}}placeholders in messages/instructions unchanged—novariablesargument.LDAIClientImplthreads aboolean interpolatethroughevaluate,buildConfig, andbuildConfigFromDefault. ExistingcompletionConfig/agentConfig/judgeConfigpaths passtrue(behavior unchanged). Template entry points passnullvariables andfalse, skippingInterpolatorfor parsed flag content and caller defaults.Template calls emit
-templateusage metrics ($ld:ai:usage:*-config-template) instead of the standard usage events. Tests cover tracking, placeholder preservation,ldctxnon-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.