Skip to content

Conversation

@TooTallNate
Copy link
Member

@TooTallNate TooTallNate commented Nov 26, 2025

This PR adds support for provider-defined tools in the DurableAgent class, allowing tools to be executed directly by the model provider (e.g., Anthropic's computer use tools) rather than client-side.

Key changes:

  • Added a new ProviderDefinedTool interface with type: 'provider-defined'
  • Extended DurableAgentToolSet to support both user-defined and provider-defined tools
  • Modified the tool execution flow to handle provider-executed tool results
  • Added logic to merge provider tool results with client tool results

Closes #433.

@changeset-bot
Copy link

changeset-bot bot commented Nov 26, 2025

🦋 Changeset detected

Latest commit: 47cfc5d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@workflow/ai Patch

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

@vercel
Copy link
Contributor

vercel bot commented Nov 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview Comment Nov 27, 2025 7:55am
example-nextjs-workflow-webpack Ready Ready Preview Comment Nov 27, 2025 7:55am
example-workflow Ready Ready Preview Comment Nov 27, 2025 7:55am
workbench-express-workflow Ready Ready Preview Comment Nov 27, 2025 7:55am
workbench-fastify-workflow Error Error Nov 27, 2025 7:55am
workbench-hono-workflow Ready Ready Preview Comment Nov 27, 2025 7:55am
workbench-nitro-workflow Ready Ready Preview Comment Nov 27, 2025 7:55am
workbench-nuxt-workflow Ready Ready Preview Comment Nov 27, 2025 7:55am
workbench-sveltekit-workflow Ready Ready Preview Comment Nov 27, 2025 7:55am
workbench-vite-workflow Ready Ready Preview Comment Nov 27, 2025 7:55am
workflow-docs Ready Ready Preview Comment Nov 27, 2025 7:55am

Copy link
Member Author

TooTallNate commented Nov 26, 2025

@TooTallNate TooTallNate marked this pull request as ready for review November 26, 2025 23:20
@TooTallNate TooTallNate force-pushed the 11-25-add_ai_provider_step_wrapper_functions branch from af9867f to 316cc78 Compare November 27, 2025 07:38
Base automatically changed from 11-25-add_ai_provider_step_wrapper_functions to main November 27, 2025 07:51
@TooTallNate TooTallNate force-pushed the 11-26-support_provider-defined_tools_in_durableagent_ branch from a09b829 to fff103f Compare November 27, 2025 07:52

// Get client tool results by yielding only the client tool calls
let clientToolResults: LanguageModelV2ToolResultPart[] = [];
if (clientToolCalls.length > 0) {
Copy link
Contributor

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 results

Result: 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.

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.

DurableAgent: Tool googleSearch does not have an execute function

2 participants