-
Notifications
You must be signed in to change notification settings - Fork 124
Support "provider-defined" tools in DurableAgent
#434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Support "provider-defined" tools in DurableAgent
#434
Conversation
🦋 Changeset detectedLatest commit: 47cfc5d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
af9867f to
316cc78
Compare
a09b829 to
fff103f
Compare
|
|
||
| // Get client tool results by yielding only the client tool calls | ||
| let clientToolResults: LanguageModelV2ToolResultPart[] = []; | ||
| if (clientToolCalls.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provider-defined tool results are not being written to the UI stream, which means they won't be visible to users even though they're being added to the conversation.
View Details
📝 Patch Details
diff --git a/packages/ai/src/agent/stream-text-iterator.ts b/packages/ai/src/agent/stream-text-iterator.ts
index e1220a7..334ff96 100644
--- a/packages/ai/src/agent/stream-text-iterator.ts
+++ b/packages/ai/src/agent/stream-text-iterator.ts
@@ -120,6 +120,11 @@ export async function* streamTextIterator({
await writeToolOutputToUI(writable, clientToolResults);
}
+ // Write provider tool results to UI
+ if (providerToolResults.length > 0) {
+ await writeToolOutputToUI(writable, providerToolResults);
+ }
+
// Merge provider tool results with client tool results
const allToolResults = [...providerToolResults, ...clientToolResults];
Analysis
Provider-defined tool results not written to UI stream
What fails: In streamTextIterator(), provider-executed tool results (captured in providerToolResults from doStreamStep()) are added to the conversation but never written to the UI stream via writeToolOutputToUI(), while client-executed tool results are properly written. This means the UI does not receive tool-output-available messages for provider-executed tools.
How to reproduce: Use a model provider that supports provider-executed tools (e.g., Anthropic's computer use tools):
const agent = new DurableAgent({
model: 'claude-opus',
tools: {
// Provider-defined tools (marked with providerExecuted: true)
// E.g., Anthropic computer use tools
},
writable: getWritable<UIMessageChunk>(),
});
await agent.stream({ role: 'user', content: 'Use provider tool' });
// Monitor the writable stream for tool-output-available messages
// Result: No tool-output-available messages received for provider tool resultsResult: Provider tool results are silently added to conversation without UI notification. The writable stream does not receive tool-output-available messages for provider-executed tools.
Expected: Both client and provider tool results should generate tool-output-available messages in the UI stream, maintaining consistency with client tool result handling (line 120).
Fix: Added await writeToolOutputToUI(writable, providerToolResults) call after client results are written (after line 120), ensuring provider tool results are communicated to the UI stream before being merged into the conversation.

This PR adds support for provider-defined tools in the
DurableAgentclass, allowing tools to be executed directly by the model provider (e.g., Anthropic's computer use tools) rather than client-side.Key changes:
ProviderDefinedToolinterface withtype: 'provider-defined'DurableAgentToolSetto support both user-defined and provider-defined toolsCloses #433.