Skip to content

Commit b443cd9

Browse files
fix(schema): add missing json tag for ToolArgument.Text field (#766)
1 parent 32fc2fb commit b443cd9

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

components/tool/callback_extra.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func ConvCallbackInput(src callbacks.CallbackInput) *CallbackInput {
4848
case string:
4949
return &CallbackInput{ArgumentsInJSON: t}
5050
case *schema.ToolArgument:
51-
return &CallbackInput{ArgumentsInJSON: t.TextArgument}
51+
return &CallbackInput{ArgumentsInJSON: t.Text}
5252
default:
5353
return nil
5454
}

components/tool/utils/invokable_func.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func (e *enhancedInvokableTool[T]) InvokableRun(ctx context.Context, toolArgumen
263263

264264
if e.um != nil {
265265
var val any
266-
val, err = e.um(ctx, toolArgument.TextArgument)
266+
val, err = e.um(ctx, toolArgument.Text)
267267
if err != nil {
268268
return nil, fmt.Errorf("[EnhancedLocalFunc] failed to unmarshal arguments, toolName=%s, err=%w", e.getToolName(), err)
269269
}
@@ -275,7 +275,7 @@ func (e *enhancedInvokableTool[T]) InvokableRun(ctx context.Context, toolArgumen
275275
} else {
276276
inst = generic.NewInstance[T]()
277277

278-
err = sonic.UnmarshalString(toolArgument.TextArgument, &inst)
278+
err = sonic.UnmarshalString(toolArgument.Text, &inst)
279279
if err != nil {
280280
return nil, fmt.Errorf("[EnhancedLocalFunc] failed to unmarshal arguments in json, toolName=%s, err=%w", e.getToolName(), err)
281281
}

components/tool/utils/streamable_func.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (s *enhancedStreamableTool[T]) StreamableRun(ctx context.Context, toolArgum
220220
var inst T
221221
if s.um != nil {
222222
var val any
223-
val, err = s.um(ctx, toolArgument.TextArgument)
223+
val, err = s.um(ctx, toolArgument.Text)
224224
if err != nil {
225225
return nil, fmt.Errorf("[EnhancedLocalStreamFunc] failed to unmarshal arguments, toolName=%s, err=%w", s.getToolName(), err)
226226
}
@@ -233,7 +233,7 @@ func (s *enhancedStreamableTool[T]) StreamableRun(ctx context.Context, toolArgum
233233
} else {
234234
inst = generic.NewInstance[T]()
235235

236-
err = sonic.UnmarshalString(toolArgument.TextArgument, &inst)
236+
err = sonic.UnmarshalString(toolArgument.Text, &inst)
237237
if err != nil {
238238
return nil, fmt.Errorf("[EnhancedLocalStreamFunc] failed to unmarshal arguments in json, toolName=%s, err=%w", s.getToolName(), err)
239239
}

components/tool/utils/streamable_func_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func TestNewEnhancedStreamTool(t *testing.T) {
209209
assert.NoError(t, err)
210210
assert.Equal(t, "enhanced_stream_search", info.Name)
211211

212-
sr, err := tl.StreamableRun(ctx, &schema.ToolArgument{TextArgument: `{"query":"test"}`})
212+
sr, err := tl.StreamableRun(ctx, &schema.ToolArgument{Text: `{"query":"test"}`})
213213
assert.NoError(t, err)
214214
defer sr.Close()
215215

@@ -281,7 +281,7 @@ func TestInferEnhancedStreamTool(t *testing.T) {
281281
assert.NoError(t, err)
282282
assert.Equal(t, "infer_enhanced_stream", info.Name)
283283

284-
sr, err := tl.StreamableRun(ctx, &schema.ToolArgument{TextArgument: `{"query":"hello"}`})
284+
sr, err := tl.StreamableRun(ctx, &schema.ToolArgument{Text: `{"query":"hello"}`})
285285
assert.NoError(t, err)
286286
defer sr.Close()
287287

@@ -303,7 +303,7 @@ func TestInferOptionableEnhancedStreamTool(t *testing.T) {
303303
assert.NoError(t, err)
304304
assert.Equal(t, "infer_optionable_enhanced_stream", info.Name)
305305

306-
sr, err := tl.StreamableRun(ctx, &schema.ToolArgument{TextArgument: `{"query":"world"}`}, FakeWithEnhancedStreamOption("custom"))
306+
sr, err := tl.StreamableRun(ctx, &schema.ToolArgument{Text: `{"query":"world"}`}, FakeWithEnhancedStreamOption("custom"))
307307
assert.NoError(t, err)
308308
defer sr.Close()
309309

@@ -317,7 +317,7 @@ func TestInferOptionableEnhancedStreamTool(t *testing.T) {
317317
tl, err := InferOptionableEnhancedStreamTool("infer_optionable_enhanced_stream", "test infer optionable enhanced stream tool", fakeOptionableEnhancedStreamFunc)
318318
assert.NoError(t, err)
319319

320-
sr, err := tl.StreamableRun(ctx, &schema.ToolArgument{TextArgument: `{"query":"test"}`})
320+
sr, err := tl.StreamableRun(ctx, &schema.ToolArgument{Text: `{"query":"test"}`})
321321
assert.NoError(t, err)
322322
defer sr.Close()
323323

compose/tool_node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func wrapEnhancedInvokableToolCall(eiTool tool.EnhancedInvokableTool, middleware
401401
eiTool = &enhancedInvokableToolWithCallback{eiTool: eiTool}
402402
}
403403
return middleware(func(ctx context.Context, input *ToolInput) (*EnhancedInvokableToolOutput, error) {
404-
result, err := eiTool.InvokableRun(ctx, &schema.ToolArgument{TextArgument: input.Arguments}, input.CallOptions...)
404+
result, err := eiTool.InvokableRun(ctx, &schema.ToolArgument{Text: input.Arguments}, input.CallOptions...)
405405
if err != nil {
406406
return nil, err
407407
}
@@ -420,7 +420,7 @@ func wrapEnhancedStreamableToolCall(est tool.EnhancedStreamableTool, middlewares
420420
est = &enhancedStreamableToolWithCallback{est: est}
421421
}
422422
return middleware(func(ctx context.Context, input *ToolInput) (*EnhancedStreamableToolOutput, error) {
423-
result, err := est.StreamableRun(ctx, &schema.ToolArgument{TextArgument: input.Arguments}, input.CallOptions...)
423+
result, err := est.StreamableRun(ctx, &schema.ToolArgument{Text: input.Arguments}, input.CallOptions...)
424424
if err != nil {
425425
return nil, err
426426
}

compose/tool_node_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ func TestEnhancedToolNode(t *testing.T) {
10581058
fn: func(ctx context.Context, input *schema.ToolArgument) (*schema.ToolResult, error) {
10591059
return &schema.ToolResult{
10601060
Parts: []schema.ToolOutputPart{
1061-
{Type: schema.ToolPartTypeText, Text: "invokable result: " + input.TextArgument},
1061+
{Type: schema.ToolPartTypeText, Text: "invokable result: " + input.Text},
10621062
},
10631063
}, nil
10641064
},
@@ -1071,7 +1071,7 @@ func TestEnhancedToolNode(t *testing.T) {
10711071
},
10721072
fn: func(ctx context.Context, input *schema.ToolArgument) (*schema.StreamReader[*schema.ToolResult], error) {
10731073
results := []*schema.ToolResult{
1074-
{Parts: []schema.ToolOutputPart{{Type: schema.ToolPartTypeText, Text: "stream part 1: " + input.TextArgument}}},
1074+
{Parts: []schema.ToolOutputPart{{Type: schema.ToolPartTypeText, Text: "stream part 1: " + input.Text}}},
10751075
{Parts: []schema.ToolOutputPart{{Type: schema.ToolPartTypeText, Text: " stream part 2"}}},
10761076
}
10771077
return schema.StreamReaderFromArray(results), nil
@@ -1147,7 +1147,7 @@ func TestEnhancedToolConversion(t *testing.T) {
11471147
fn: func(ctx context.Context, input *schema.ToolArgument) (*schema.ToolResult, error) {
11481148
return &schema.ToolResult{
11491149
Parts: []schema.ToolOutputPart{
1150-
{Type: schema.ToolPartTypeText, Text: "enhanced: " + input.TextArgument},
1150+
{Type: schema.ToolPartTypeText, Text: "enhanced: " + input.Text},
11511151
},
11521152
}, nil
11531153
},

schema/message.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ type ToolOutputPart struct {
328328
// ToolArgument contains the input information for a tool call.
329329
// It is used to pass tool call arguments to enhanced tools.
330330
type ToolArgument struct {
331-
// TextArgument contains the arguments for the tool call in JSON format.
332-
TextArgument string
331+
// Text contains the arguments for the tool call in JSON format.
332+
Text string `json:"text,omitempty"`
333333
}
334334

335335
// ToolResult represents the structured multimodal output from a tool execution.

0 commit comments

Comments
 (0)