fix(chat): preserve provider tool-call metadata
This commit is contained in:
+10
-8
@@ -317,9 +317,10 @@ func (e *AgentEngine) runToolCall(
|
||||
if repairErr := json.Unmarshal([]byte(repaired), &args); repairErr != nil {
|
||||
logger.Errorf(ctx, "%s Failed to parse arguments (repair failed): %v", toolTag, err)
|
||||
return types.ToolCall{
|
||||
ID: tc.ID,
|
||||
Name: tc.Function.Name,
|
||||
Args: map[string]any{"_raw": argsStr},
|
||||
ID: tc.ID,
|
||||
Name: tc.Function.Name,
|
||||
Args: map[string]any{"_raw": argsStr},
|
||||
ProviderMetadata: tc.ProviderMetadata,
|
||||
Result: &types.ToolResult{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf(
|
||||
@@ -413,11 +414,12 @@ func (e *AgentEngine) runToolCall(
|
||||
duration := time.Since(toolCallStartTime).Milliseconds()
|
||||
|
||||
toolCall := types.ToolCall{
|
||||
ID: tc.ID,
|
||||
Name: tc.Function.Name,
|
||||
Args: args,
|
||||
Result: result,
|
||||
Duration: duration,
|
||||
ID: tc.ID,
|
||||
Name: tc.Function.Name,
|
||||
Args: args,
|
||||
Result: result,
|
||||
Duration: duration,
|
||||
ProviderMetadata: tc.ProviderMetadata,
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -326,8 +326,9 @@ func (e *AgentEngine) appendToolResults(
|
||||
argsJSON, _ := json.Marshal(tc.Args)
|
||||
|
||||
assistantMsg.ToolCalls = append(assistantMsg.ToolCalls, chat.ToolCall{
|
||||
ID: tc.ID,
|
||||
Type: "function",
|
||||
ID: tc.ID,
|
||||
Type: "function",
|
||||
ProviderMetadata: tc.ProviderMetadata,
|
||||
Function: chat.FunctionCall{
|
||||
Name: tc.Name,
|
||||
Arguments: string(argsJSON),
|
||||
|
||||
@@ -2,6 +2,7 @@ package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -73,9 +74,10 @@ func TestAppendToolResults_PreservesReasoningContent(t *testing.T) {
|
||||
Thought: "I will call search.",
|
||||
ReasoningContent: "Detailed chain of thought from MiMo/DeepSeek.",
|
||||
ToolCalls: []types.ToolCall{{
|
||||
ID: "call_1",
|
||||
Name: "knowledge_search",
|
||||
Args: map[string]interface{}{"query": "hi"},
|
||||
ID: "call_1",
|
||||
Name: "knowledge_search",
|
||||
Args: map[string]interface{}{"query": "hi"},
|
||||
ProviderMetadata: types.ToolCallMetadata{"google": json.RawMessage(`{"thought_signature":"gemini-thought-signature"}`)},
|
||||
Result: &types.ToolResult{
|
||||
Success: true,
|
||||
Output: "result text",
|
||||
@@ -94,6 +96,8 @@ func TestAppendToolResults_PreservesReasoningContent(t *testing.T) {
|
||||
"and DeepSeek thinking-mode see it on the next round (issue #1302)")
|
||||
require.Len(t, out[0].ToolCalls, 1)
|
||||
assert.Equal(t, "call_1", out[0].ToolCalls[0].ID)
|
||||
assert.JSONEq(t, `{"thought_signature":"gemini-thought-signature"}`,
|
||||
string(out[0].ToolCalls[0].ProviderMetadata["google"]))
|
||||
|
||||
assert.Equal(t, "tool", out[1].Role)
|
||||
assert.Equal(t, "result text", out[1].Content)
|
||||
|
||||
Reference in New Issue
Block a user