File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package v2
22
33import (
4+ "encoding/json"
45 "fmt"
56
67 "github.com/docker/cagent/pkg/config/types"
@@ -194,6 +195,37 @@ func (t *ThinkingBudget) UnmarshalYAML(unmarshal func(any) error) error {
194195 return nil
195196}
196197
198+ // MarshalJSON implements custom marshaling to output simple string or int format
199+ // This ensures JSON serialization during config upgrades preserves the value correctly
200+ func (t ThinkingBudget ) MarshalJSON () ([]byte , error ) {
201+ // If Effort string is set (non-empty), marshal as string
202+ if t .Effort != "" {
203+ return []byte (fmt .Sprintf ("%q" , t .Effort )), nil
204+ }
205+
206+ // Otherwise marshal as integer (includes 0, -1, and positive values)
207+ return []byte (fmt .Sprintf ("%d" , t .Tokens )), nil
208+ }
209+
210+ // UnmarshalJSON implements custom unmarshaling to accept simple string or int format
211+ func (t * ThinkingBudget ) UnmarshalJSON (data []byte ) error {
212+ // Try integer tokens first
213+ var n int
214+ if err := json .Unmarshal (data , & n ); err == nil {
215+ * t = ThinkingBudget {Tokens : n }
216+ return nil
217+ }
218+
219+ // Try string level
220+ var s string
221+ if err := json .Unmarshal (data , & s ); err == nil {
222+ * t = ThinkingBudget {Effort : s }
223+ return nil
224+ }
225+
226+ return nil
227+ }
228+
197229// StructuredOutput defines a JSON schema for structured output
198230type StructuredOutput struct {
199231 // Name is the name of the response format
You can’t perform that action at this time.
0 commit comments