Skip to content

Streamable tool calls with Anthropic Models - #176

Open
ActuallyTaylor wants to merge 11 commits into
huggingface:mainfrom
impel-intelligence:fix/stream-stop-from-tool-call
Open

Streamable tool calls with Anthropic Models#176
ActuallyTaylor wants to merge 11 commits into
huggingface:mainfrom
impel-intelligence:fix/stream-stop-from-tool-call

Conversation

@ActuallyTaylor

@ActuallyTaylor ActuallyTaylor commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This PR introduces a streaming transcript object that allows the streaming endpoints to stream tool calls back to the user as the model works.

Features

  • Session.transcript automatically updates as content is streamed.
  • The Anthropic stream function has been updated with an infinite loop until there are no tool calls.
    • This was mirrored from the OpenAI endpoint.
  • (Breaking) Updated Anthropic Thinking structures to match new APIs
    • Changed Thinking.init to take a specified type, budget tokens, and display type instead of a static type.
    • Added two static connivence methods .adaptive(display:) and .enabled(budgetTokens:,display:) to easily create thinking structures configured to match the Anthropic APIs.
  • Updated AnthropicLanguageModel tests to reflect the streamable transcripts.

Other Approaches

I first attempted to stream the transcript through a second API named streamTranscript. I decided not to go down this route since it would require duplicated streaming code in the model, as well as the need to make every transcript structure conform to Generable and PartiallyGenerated.

Support

Currently only supported on the Anthropic Provider.

Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Previously, tool use would cancel the response. This meant that the model would never get to use the result of its tools. This fix adds an infinite loop similair to the OpenAI implementation

Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
This also brings tool support in the streaming endpoint for anthropic models

Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
Signed-off-by: Taylor Lineman <git@actuallytaylor.com>
@mattt

mattt commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Hi @ActuallyTaylor. Thanks for this, and sorry for not reviewing it sooner.

This and #181 each add a way to observe transcript entries during streaming, for Anthropic and MLX respectively, which is what I asked for in #103. Rather than land two shapes, I'd like to settle on one in #103 and then have both PRs adopt it. I've posted a proposal there; would you take a look?

Separately, the change to Thinking.init is source-breaking. Could you split that into its own PR so it can go in with the next minor?

@ActuallyTaylor

ActuallyTaylor commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@mattt I have split this pr into #211 which adds just the thinking and effort changes required to get an anthropic model to think! Also I am happy you are back! No worries about the long review period

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.

2 participants