Enhance agent streaming and logging in Analyst and Think and Prep steps

- Added consumption of text streams in both `runAnalystAgentStep` and `runThinkAndPrepAgentStep` to ensure continuous processing of agent responses.
- Introduced detailed logging at various stages of the agent's execution to improve traceability and debugging.
- These changes enhance the robustness of the agent workflow and provide better insights during execution.
This commit is contained in:
dal 2025-08-12 21:47:09 -06:00
parent 855e7b1a55
commit 5d2631b848
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
2 changed files with 38 additions and 0 deletions

View File

@ -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)) {

View File

@ -23,10 +23,39 @@ export async function runThinkAndPrepAgentStep({
streamOptions,
}: RunThinkAndPrepAgentStepInput): Promise<RunThinkAndPrepAgentStepOutput> {
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(