| 24 | * @returns True if processing resulted in an action |
| 25 | */ |
| 26 | export async function processOutput(agentId: string, text: string): Promise<boolean> { |
| 27 | // Get the processor (or use a default logger if none exists) |
| 28 | const processor = processors.get(agentId) || ((response: string) => { |
| 29 | Logger.info(agentId, `Agent output: ${response.length > 100 ? |
| 30 | response.substring(0, 100) + '...' : response}`); |
| 31 | return false; |
| 32 | }); |
| 33 | |
| 34 | // Filter out content inside <think>...</think> tags if needed |
| 35 | //if (excludeThink) { |
| 36 | // filteredText = text.replace(/<think>[\s\S]*?<\/think>/g, ''); |
| 37 | // Logger.debug(agentId, `Filtered out <think> blocks from agent output`); |
| 38 | //} |
| 39 | |
| 40 | try { |
| 41 | // Process the entire response at once |
| 42 | const result = await processor(text, utilities, agentId); |
| 43 | return !!result; // Convert to boolean |
| 44 | } catch (error) { |
| 45 | Logger.error(agentId, `Error processing response: ${error}`); |
| 46 | return false; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Clear the processor for an agent |