Skip to content

Merged streams don't get a tool-result step from client side tools #7111

@s0rta

Description

@s0rta

Description

If I have an orchestrator agent that has a tool that can spawn child agents, and those child agents have client side tools with data coming back from onToolCall, they never get a tool-result step. The result I would expect would be a tool-result step for any tool called by a stream that has been merged. onToolCall is called, and the result is sent.

pipeDataStreamToResponse(res, {
  status: 200,
  headers: { 'Content-Type': 'text/plain' },
  execute: async (dataStream) => {
    // Initial message to client
    dataStream.writeData({ message: 'Processing started...' });

    // Primary streamText call
    const primaryStream = streamText({
      model: openai('gpt-4o'),
      prompt: 'Spawn child agent.',
      tools: {
        spawnAgent: {
          parameters: {
            type: 'object',
            properties: {
              instructions: { type: 'string' },
            },
          },
          execute: async () => {
            const toolResultStream = streamText({
              model: openai('gpt-4o'),
              tools: {
                // WILL NEVER GET BACK RESULT
                clientSideTool: {
                  parameters: {
                    type: 'object',
                    properties: {
                      instructions: { type: 'string' },
                    },
                  },
                },
              },
              prompt: `SPAWNED AGENT`,
            });

            // Merge the new stream into the existing data stream
            toolResultStream.mergeIntoDataStream(dataStream);
            return 'Agent spawned';
          },
        },
        // Define your tools here
      },
      toolCallStreaming: true,
      onToolCall: async (toolCall) => {
        // Handle the tool call
      },
    });

    // Merge the primary stream into the data stream
    primaryStream.mergeIntoDataStream(dataStream);
  },
  onError: (error) => `Error occurred: ${error instanceof Error ? error.message : String(error)}`,
});

AI SDK Version

  • ai: 4.3.16
  • "@ai-sdk/openai": "1.3.1",

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy