Skip to content

Commit 151b008

Browse files
committed
fix: fix reasoning metadata
fix: fix reasoning content
1 parent 7a2644d commit 151b008

3 files changed

Lines changed: 29 additions & 15 deletions

File tree

ai/agent.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,11 @@ func (a *agent) processStepStream(ctx context.Context, stream StreamResponse, op
10681068

10691069
activeToolCalls := make(map[string]*ToolCallContent)
10701070
activeTextContent := make(map[string]string)
1071+
type reasoningContent struct {
1072+
content string
1073+
options ProviderMetadata
1074+
}
1075+
activeReasoningContent := make(map[string]reasoningContent)
10711076

10721077
// Process stream parts
10731078
for part := range stream {
@@ -1125,7 +1130,7 @@ func (a *agent) processStepStream(ctx context.Context, stream StreamResponse, op
11251130
}
11261131

11271132
case StreamPartTypeReasoningStart:
1128-
activeTextContent[part.ID] = ""
1133+
activeReasoningContent[part.ID] = reasoningContent{content: ""}
11291134
if opts.OnReasoningStart != nil {
11301135
err := opts.OnReasoningStart(part.ID)
11311136
if err != nil {
@@ -1134,8 +1139,10 @@ func (a *agent) processStepStream(ctx context.Context, stream StreamResponse, op
11341139
}
11351140

11361141
case StreamPartTypeReasoningDelta:
1137-
if _, exists := activeTextContent[part.ID]; exists {
1138-
activeTextContent[part.ID] += part.Delta
1142+
if active, exists := activeReasoningContent[part.ID]; exists {
1143+
active.content += part.Delta
1144+
active.options = part.ProviderMetadata
1145+
activeReasoningContent[part.ID] = active
11391146
}
11401147
if opts.OnReasoningDelta != nil {
11411148
err := opts.OnReasoningDelta(part.ID, part.Delta)
@@ -1145,21 +1152,19 @@ func (a *agent) processStepStream(ctx context.Context, stream StreamResponse, op
11451152
}
11461153

11471154
case StreamPartTypeReasoningEnd:
1148-
if text, exists := activeTextContent[part.ID]; exists {
1149-
stepContent = append(stepContent, ReasoningContent{
1150-
Text: text,
1151-
ProviderMetadata: part.ProviderMetadata,
1152-
})
1155+
if active, exists := activeReasoningContent[part.ID]; exists {
1156+
content := ReasoningContent{
1157+
Text: active.content,
1158+
ProviderMetadata: active.options,
1159+
}
1160+
stepContent = append(stepContent, content)
11531161
if opts.OnReasoningEnd != nil {
1154-
err := opts.OnReasoningEnd(part.ID, ReasoningContent{
1155-
Text: text,
1156-
ProviderMetadata: part.ProviderMetadata,
1157-
})
1162+
err := opts.OnReasoningEnd(part.ID, content)
11581163
if err != nil {
11591164
return StepResult{}, false, err
11601165
}
11611166
}
1162-
delete(activeTextContent, part.ID)
1167+
delete(activeReasoningContent, part.ID)
11631168
}
11641169

11651170
case StreamPartTypeToolInputStart:

anthropic/provider_options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package anthropic
33
type ProviderOptions struct {
44
SendReasoning *bool `mapstructure:"send_reasoning,omitempty"`
55
Thinking *ThinkingProviderOption `mapstructure:"thinking,omitempty"`
6-
DisableParallelToolUse *bool `mapstructure"disable_parallel_tool_use,omitempty"`
6+
DisableParallelToolUse *bool `mapstructure:"disable_parallel_tool_use,omitempty"`
77
}
88

99
type ThinkingProviderOption struct {
1010
BudgetTokens int64 `mapstructure:"budget_tokens"`
1111
}
1212

1313
type ReasoningMetadata struct {
14-
Signature string `mapstructure"signature"`
14+
Signature string `mapstructure:"signature"`
1515
RedactedData string `mapstructure:"redacted_data"`
1616
}
1717

cspell.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"language": "en",
3+
"version": "0.2",
4+
"flagWords": [],
5+
"words": [
6+
"mapstructure",
7+
"mapstructure"
8+
]
9+
}

0 commit comments

Comments
 (0)