Commit a744d60
authored
chore: Add LdAiAgentConfig and LdAiJudgeConfig types with ConfigFactory build methods (2 of 6) (#280)
## Summary
Adds the **typed config shapes and factory build methods** for agents
and judges. With this change, `ConfigFactory` can produce
fully-evaluated `LdAiAgentConfig` and `LdAiJudgeConfig` objects from a
flag's JSON.
Four new public types slot into the existing `LdAiConfigBase` /
`LdAiConfigDefaultBase` parallel hierarchy:
- **`LdAiAgentConfig`** extends `LdAiConfigBase`. Adds `Instructions`
(interpolated) and `Tools`. Internal constructor — SDK-built only.
- **`LdAiAgentConfigDefault`** extends `LdAiConfigDefaultBase`. Public
`Builder` with `SetInstructions`, `SetModelParam`,
`SetCustomModelParam`, `SetModelName`, `SetModelProviderName`, `Enable`
/ `Disable`. `New()` factory and `Disabled` helper. `ToLdValue()`
serializes to the `_ldMeta { enabled, mode }` envelope that the SDK
reads, so a caller default round-trips through `JsonVariation`'s
fallback path correctly.
- **`LdAiJudgeConfig`** extends `LdAiConfigBase`. Adds `Messages` and
`EvaluationMetricKey`.
- **`LdAiJudgeConfigDefault`** mirrors the agent default, but the
builder takes `AddMessage(content, role)` instead of `SetInstructions`.
Each config type carries a `Mode` constant (`"agent"` / `"judge"`) used
by its build method to validate `_ldMeta.mode` and fall back to the
caller's default on mismatch.
### Factory build methods
`ConfigFactory.BuildAgentConfig` and `BuildJudgeConfig` follow the same
shape as the existing `BuildCompletionConfig`:
1. Merge user variables with the LD context (the `ldctx` key).
2. Synthesize a tracker factory bound to that context.
3. Reject non-object variations → log error, return caller's default.
4. Reject mode mismatch → log warning, return caller's default.
5. Otherwise parse model/provider plus the type-specific fields
(`instructions` + `tools` for agents; `messages` + `evaluationMetricKey`
for judges) and interpolate Mustache templates.
A new private `InterpolateInstructions` helper mirrors the per-field
tolerance of the existing `InterpolateMessages`: a malformed template in
`instructions` keeps the raw string and logs a warning rather than
dropping the whole config.
### Defaults
Both new default builders set `_enabled = true` initially. The base
type's `Enabled` is `bool?` so the round-trip through `ToLdValue()` →
`JsonVariation` fallback can distinguish "unset" from "explicitly
disabled".
## Test plan
- [ ] `dotnet build` succeeds across `netstandard2.0`, `net462`,
`net8.0`
- [ ] `dotnet test --framework net8.0` passes
- [ ] `LdAiAgentConfigTest` covers happy path, mode mismatch, non-object
variation, instructions interpolation, and
`LdAiAgentConfigDefault.ToLdValue` round-trip
- [ ] `LdAiJudgeConfigTest` covers the same matrix for judges plus
default-type behavior
- [ ] Reviewer confirms parallel hierarchy lines up with the cross-SDK
pattern (python, ruby) and that builder method names match the
Completion side
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Additive SDK surface and factory logic parallel to existing completion
handling; extensive tests and safe fallbacks on bad variations.
>
> **Overview**
> Adds **agent** and **judge** AI config types to the server-ai SDK,
mirroring the existing completion config pattern.
>
> **`ConfigFactory`** gains `BuildAgentConfig` and `BuildJudgeConfig`,
which parse flag JSON (`_ldMeta.mode` of `agent` / `judge`), merge
Mustache variables with LD context, attach trackers, and fall back to
caller defaults on non-object variations or mode mismatch. Agents get
interpolated **instructions**, **tools**, and optional
**judgeConfiguration**; judges get **messages** and
**evaluationMetricKey**. **`InterpolateInstructions`** applies the same
malformed-template tolerance as message interpolation.
>
> New public types: **`LdAiAgentConfig`** / **`LdAiAgentConfigDefault`**
(builder with `SetInstructions`, `SetJudgeConfiguration`, model fields;
`ToLdValue()` for `JsonVariation` fallback) and **`LdAiJudgeConfig`** /
**`LdAiJudgeConfigDefault`** (builder with `AddMessage`, metric key).
Unit tests cover happy paths, fallbacks, interpolation, judge config
round-trip, and default serialization.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
daaa648. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 12c0b7a commit a744d60
7 files changed
Lines changed: 1187 additions & 4 deletions
File tree
- pkgs/sdk/server-ai
- src/Config
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 13 | + | |
| 14 | + | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
| |||
93 | 91 | | |
94 | 92 | | |
95 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
96 | 243 | | |
97 | 244 | | |
98 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
0 commit comments