Description
streamText accepts the streaming lifecycle callbacks onError, onChunk, and onAbort. However, ToolLoopAgent.stream() does not expose or forward these callbacks.
This is particularly problematic for onError, because streamText defaults to calling console.error(error) when no callback is provided. Applications using ToolLoopAgent cannot replace this behavior with their own structured logger. Depending on the log collection provider, the resulting output can be noisy or difficult to search and correlate.
For example, the following works with streamText:
const result = streamText({
model,
prompt: 'Hello',
onError: ({ error }) => {
logger.error({ error }, 'AI stream failed');
},
onChunk: ({ chunk }) => {
logger.debug({ chunk }, 'AI stream chunk');
},
onAbort: ({ steps }) => {
logger.info({ steps }, 'AI stream aborted');
},
});
The equivalent configuration is not accepted by ToolLoopAgent:
const agent = new ToolLoopAgent({
model,
});
const result = await agent.stream({
prompt: 'Hello',
// These options are not supported:
onError: ({ error }) => {
logger.error({ error }, 'AI stream failed');
},
onChunk: ({ chunk }) => {
logger.debug({ chunk }, 'AI stream chunk');
},
onAbort: ({ steps }) => {
logger.info({ steps }, 'AI stream aborted');
},
});
AgentStreamParameters only adds experimental_transform to the common agent call parameters. ToolLoopAgent.stream() also does not extract or forward onError, onChunk, or onAbort to its internal streamText call.
Telemetry integrations can observe errors and aborts, and experimental_transform can observe chunks to some extent. However, a telemetry onError integration does not replace streamText's default console.error handler, so it does not solve the logging issue.
It would be useful for ToolLoopAgent.stream() to support these callbacks:
- Add
onError, onChunk, and onAbort to AgentStreamParameters.
- Allow them to be configured in
ToolLoopAgentSettings, consistent with the other lifecycle callbacks.
- Merge callbacks configured on the agent and on individual
stream() calls.
- Forward the resulting callbacks to the internal
streamText call.
AI SDK Version
6.0.197
This is also reproducible on 7.0.0-canary.165.
Code of Conduct
Description
streamTextaccepts the streaming lifecycle callbacksonError,onChunk, andonAbort. However,ToolLoopAgent.stream()does not expose or forward these callbacks.This is particularly problematic for
onError, becausestreamTextdefaults to callingconsole.error(error)when no callback is provided. Applications usingToolLoopAgentcannot replace this behavior with their own structured logger. Depending on the log collection provider, the resulting output can be noisy or difficult to search and correlate.For example, the following works with
streamText:The equivalent configuration is not accepted by
ToolLoopAgent:AgentStreamParametersonly addsexperimental_transformto the common agent call parameters.ToolLoopAgent.stream()also does not extract or forwardonError,onChunk, oronAbortto its internalstreamTextcall.Telemetry integrations can observe errors and aborts, and
experimental_transformcan observe chunks to some extent. However, a telemetryonErrorintegration does not replacestreamText's defaultconsole.errorhandler, so it does not solve the logging issue.It would be useful for
ToolLoopAgent.stream()to support these callbacks:onError,onChunk, andonAborttoAgentStreamParameters.ToolLoopAgentSettings, consistent with the other lifecycle callbacks.stream()calls.streamTextcall.AI SDK Version
6.0.197This is also reproducible on
7.0.0-canary.165.Code of Conduct