diff --git a/packages/ai/src/steps/analyst-agent-steps/analyst-step/analyst-step.ts b/packages/ai/src/steps/analyst-agent-steps/analyst-step/analyst-step.ts index 39d1fc5ba..328dcecec 100644 --- a/packages/ai/src/steps/analyst-agent-steps/analyst-step/analyst-step.ts +++ b/packages/ai/src/steps/analyst-agent-steps/analyst-step/analyst-step.ts @@ -26,6 +26,15 @@ export async function runAnalystAgentStep({ const analystAgent = createAnalystAgent(options); const result = await analystAgent.stream(streamOptions); + + // Consume the text stream to ensure the agent continues processing + if (result.textStream) { + for await (const _ of result.textStream) { + // We don't need to do anything with the text chunks, + // just consume them to keep the stream flowing + } + } + const response = await result.response; if (!response || !Array.isArray(response.messages)) { diff --git a/packages/ai/src/steps/analyst-agent-steps/think-and-prep-step/think-and-prep-step.ts b/packages/ai/src/steps/analyst-agent-steps/think-and-prep-step/think-and-prep-step.ts index 744959c7f..5762a08af 100644 --- a/packages/ai/src/steps/analyst-agent-steps/think-and-prep-step/think-and-prep-step.ts +++ b/packages/ai/src/steps/analyst-agent-steps/think-and-prep-step/think-and-prep-step.ts @@ -23,10 +23,39 @@ export async function runThinkAndPrepAgentStep({ streamOptions, }: RunThinkAndPrepAgentStepInput): Promise { try { + console.info('[runThinkAndPrepAgentStep] Starting agent stream', { + messageId: options?.messageId, + messageCount: streamOptions.messages.length, + }); + const thinkAndPrepAgent = createThinkAndPrepAgent(options); const result = await thinkAndPrepAgent.stream(streamOptions); + + console.info('[runThinkAndPrepAgentStep] Stream started, consuming stream', { + messageId: options?.messageId, + }); + + // Consume the text stream to ensure the agent continues processing + if (result.textStream) { + for await (const _ of result.textStream) { + // We don't need to do anything with the text chunks, + // just consume them to keep the stream flowing + } + } + + console.info('[runThinkAndPrepAgentStep] Stream consumed, awaiting response', { + messageId: options?.messageId, + }); + const response = await result.response; + + console.info('[runThinkAndPrepAgentStep] Response received', { + messageId: options?.messageId, + hasResponse: !!response, + hasMessages: !!response?.messages, + messageCount: response?.messages?.length, + }); if (!response || !Array.isArray(response.messages)) { throw new Error(