Skip to content

Commit 9c40c62

Browse files
jsell-rhclaude
andcommitted
fix(api-server): correct test assertions, symmetric sentinel for max_tokens
Fix TestAgentPostLlmDefaults to assert 0.7/4000 (the actual defaults applied by BeforeCreate), not 0.0/0. Add unsetMaxTokens sentinel (-1) mirroring the temperature approach so POST max_tokens=0 behaves the same as POST temperature=0 — both preserve explicit zero via PATCH while applying defaults on omitted POST. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 98aabf4 commit 9c40c62

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

components/ambient-api-server/plugins/agents/integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ func TestAgentPostLlmDefaults(t *testing.T) {
145145
Expect(agentOutput.LlmModel).NotTo(BeNil(), "llm_model should be defaulted")
146146
Expect(*agentOutput.LlmModel).To(Equal("claude-sonnet-4-6"))
147147
Expect(agentOutput.LlmTemperature).NotTo(BeNil(), "llm_temperature should be present")
148-
Expect(*agentOutput.LlmTemperature).To(BeNumerically("~", 0.0, 0.001))
148+
Expect(*agentOutput.LlmTemperature).To(BeNumerically("~", 0.7, 0.001))
149149
Expect(agentOutput.LlmMaxTokens).NotTo(BeNil(), "llm_max_tokens should be present")
150-
Expect(*agentOutput.LlmMaxTokens).To(Equal(int32(0)))
150+
Expect(*agentOutput.LlmMaxTokens).To(Equal(int32(4000)))
151151
}
152152

153153
func TestAgentPatch(t *testing.T) {

components/ambient-api-server/plugins/agents/model.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ func (l AgentList) Index() AgentIndex {
3838
return index
3939
}
4040

41-
// unsetTemperature is a sentinel value indicating the caller did not provide a temperature.
42-
// Valid temperatures are 0.0–2.0, so -1 is unambiguously "unset".
43-
const unsetTemperature = -1.0
41+
// Sentinel values indicating the caller did not provide a value.
42+
// Valid temperatures are 0.0–2.0 and valid max_tokens are > 0,
43+
// so negative values are unambiguously "unset".
44+
const (
45+
unsetTemperature float64 = -1.0
46+
unsetMaxTokens int32 = -1
47+
)
4448

4549
func (d *Agent) BeforeCreate(tx *gorm.DB) error {
4650
d.ID = api.NewID()
@@ -50,7 +54,7 @@ func (d *Agent) BeforeCreate(tx *gorm.DB) error {
5054
if d.LlmTemperature == unsetTemperature {
5155
d.LlmTemperature = 0.7
5256
}
53-
if d.LlmMaxTokens <= 0 {
57+
if d.LlmMaxTokens == unsetMaxTokens {
5458
d.LlmMaxTokens = 4000
5559
}
5660
return nil

components/ambient-api-server/plugins/agents/presenter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func ConvertAgent(agent openapi.Agent) *Agent {
3232
}
3333
if agent.LlmMaxTokens != nil {
3434
c.LlmMaxTokens = *agent.LlmMaxTokens
35+
} else {
36+
c.LlmMaxTokens = unsetMaxTokens
3537
}
3638
c.BotAccountName = agent.BotAccountName
3739
c.ResourceOverrides = agent.ResourceOverrides

0 commit comments

Comments
 (0)