Skip to content

Fix duplicate AI messages for parallel tool calls (#1463)#1475

Open
VishnuVV27 wants to merge 1 commit into
tmc:mainfrom
VishnuVV27:fix-parallel-tool-calls
Open

Fix duplicate AI messages for parallel tool calls (#1463)#1475
VishnuVV27 wants to merge 1 commit into
tmc:mainfrom
VishnuVV27:fix-parallel-tool-calls

Conversation

@VishnuVV27
Copy link
Copy Markdown

PR Checklist

Description

This PR resolves issue #1463 where the OpenAIFunctionsAgent generated multiple duplicate AI messages in the conversation history (scratchpad) when the LLM returned multiple tool calls in a single response turn.

The Fix:
The constructScratchPad function groups sequential tool calls into a single AIChatMessage only if they share the same Log string. Previously, ParseOutput generated a unique Log for every tool call (stating only one tool at a time), which caused the grouping logic to fail and create multiple AI message turns.

I refactored ParseOutput to generate a sharedLog string that summarizes all tools being invoked in that response. By making the Log identical for all actions in a choice, constructScratchPad now correctly collapses them into a single message with multiple ToolCalls.

Verification:

  • Added a targeted reproduction test case TestConstructScratchPadGrouping in agents/reproduce_1463_test.go (verified that 2 parallel tool calls result in 1 AI message + 2 Tool responses).
  • Verified that existing tests in openai_functions_agent_test.go (including TestOpenAIFunctionsAgent_ParseOutput_MultipleToolCalls) still pass.

Fixes #1463

Signed-off-by: vishnuvv27 <vardhanvishnu520@gmail.com>
@VishnuVV27 VishnuVV27 force-pushed the fix-parallel-tool-calls branch from 59f2cd3 to 1fc09d0 Compare February 9, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How Should Parallel Tool Calls Be Grouped in OpenAIFunctionsAgent?

1 participant