Skip to content

Commit e1d55d9

Browse files
committed
minor refactor in agent.go
1 parent 90330e4 commit e1d55d9

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

llm/agent.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func (agent *Agent) resetHistory() {
5151
}
5252
}
5353

54-
5554
func (agent *Agent) Input(input string) {
5655
agent.mu.Lock()
5756
if agent.inProgress {
@@ -200,16 +199,14 @@ func (agent *Agent) doStream(ctx context.Context, req *ChatRequest) (
200199
err = agent.client.Stream(ctx, req, func(chunk *ChatCompletionChunk) error {
201200
return agent.handleStreamChunk(chunk, &contentBuilder, &reasoningBuilder, &toolCallsMap, &inThink)
202201
})
203-
204202
if err != nil {
205203
return
206204
}
207205

208-
// Convert map to slice
209-
for i := 0; i < len(toolCallsMap); i++ {
210-
if tc, ok := toolCallsMap[i]; ok {
211-
toolCalls = append(toolCalls, *tc)
212-
}
206+
// Convert map to slice (requires contiguous indices)
207+
toolCalls = make([]ToolCall, len(toolCallsMap))
208+
for i := range toolCalls {
209+
toolCalls[i] = *toolCallsMap[i]
213210
}
214211
return contentBuilder.String(), reasoningBuilder.String(), toolCalls, nil
215212
}

0 commit comments

Comments
 (0)