Skip to content

Conversation

AstraBert
Copy link
Member

Adding a tool call block and support for it in:

  • OpenAI
  • Anthropic
  • Google GenAI
  • Bedrock Converse
  • Mistral
  • Ollama

@AstraBert AstraBert marked this pull request as ready for review September 29, 2025 14:40
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Sep 29, 2025
@logan-markewich logan-markewich changed the title wip: add tool call block add unified tool call block Sep 29, 2025
blocks=content,
blocks=[
*content,
*_anthropic_tool_call_to_tool_call_block(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this assumes that tool calls always come after content (I think this is true? just flagging)

Copy link
Member Author

@AstraBert AstraBert Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that was my assumption: first there is the "explanation" of the tool call and then we have the tool call itself

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be safe, it might be best to just match the order that the content came in, rather than assuming 👍🏻

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Sep 30, 2025
@AstraBert
Copy link
Member Author

@logan-markewich implemented all changes as you said, I tried to make OpenAI as backward compatible as possible to avoid breakages in the sense

@AstraBert
Copy link
Member Author

I most probably messed something up with the merge 😬, will be fixing with the next commit

type="tool_use",
)
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to add back this handling (in each LLM), just to ensure that old chat histories don't suddenly stop working. No harm in keeping this here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bedrock is missing the code to take ToolCallBlock -> bedrock format

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(when you add this, lets keep the old way too to avoid breaking old convo histories?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gemini seems a little broken.

Testing with an agent, I get this

Chat turn one

[ChatMessage(role=<MessageRole.USER: 'user'>, additional_kwargs={}, blocks=[TextBlock(block_type='text', text='Hello! I am a new user!')]), ChatMessage(role=<MessageRole.ASSISTANT: 'assistant'>, additional_kwargs={'thought_signatures': []}, blocks=[ToolCallBlock(block_type='tool_call', tool_call_id=None, tool_name='get_the_greeting', tool_kwargs={}), TextBlock(block_type='text', text=''), ThinkingBlock(block_type='thinking', content='', num_tokens=None, additional_information={})]), ChatMessage(role=<MessageRole.TOOL: 'tool'>, additional_kwargs={'tool_call_id': ''}, blocks=[TextBlock(block_type='text', text='Good day sir, top of the morning to ye.')])]

Lots of empty blocks? And from here, it kind of goes into a tail-spin calling the same tool over and over again. Seems sus. This is using the agent script I linked in slack

Comment on lines -120 to +132
new_messages.append(AssistantMessage(content=chunks, tool_calls=tool_calls))
new_messages.append(AssistantMessage(content=chunks))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at mistral docs, I don't think this works. content can't include tool calls, it has to be attached separately

https://github.com/mistralai/client-python/blob/992b0cbd3f86cef54e74a03cfd488f123cec4203/packages/mistralai_azure/src/mistralai_azure/models/contentchunk.py#L19

@AstraBert AstraBert closed this Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants