Skip to content

Tool-call tests overwrite ToolResult on multi-tool-call first turn #220

Description

@maragubot

Description

The can use a tool / can use a tool with args integration tests in all three provider client packages (clients/openai, clients/anthropic, clients/google) accumulate parts from the first ChatComplete turn but overwrite the local result variable on every PartTypeToolCall. When a model emits more than one tool call on the first turn, the tests send back N tool_call_ids in the assistant message but only one matching tool_result, causing the second ChatComplete to fail.

Surfaced by qa during the review of #219 (which fixed #208). The OpenAI variant reproduced ~7% of the time over 15 iterations with GPT-5 Nano:

```
400: An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_s442BpDRuyhgmLiEjDi8pPba
```

Anthropic and Google share the same overwrite pattern but didn't reproduce in the qa run.

Affected files

  • `clients/openai/chat_complete_test.go` (`can use a tool with args`, ~lines 95-123)
  • `clients/anthropic/chat_complete_test.go` (`can use a tool`)
  • `clients/google/chat_complete_test.go` (`can use a tool`)

Suggested fix options

  • (a) Accumulate `result` into a slice and append every matching tool result to the second-turn message. Most correct; matches real protocol behavior when models emit parallel tool calls.
  • (b) Assert exactly one tool call was produced on turn 1, fail-fast otherwise. Simpler but pretends the multi-call case can't happen.

(a) is the right call — the underlying library already supports multiple tool calls, so the tests should too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions