-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
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",