Skip to content

Commit 91f8e36

Browse files
fix: agent output
1 parent 2585b1f commit 91f8e36

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/auto.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,31 @@ export async function auto(
133133
// Create and invoke the agent
134134
console.log(`[Auto] Creating agent for instruction`);
135135
const { agent } = initializeAgent();
136-
const result = await agent.invoke({
136+
const response = await agent.invoke({
137137
messages: [new HumanMessage(instruction)],
138138
});
139-
140-
//console.log('Agent result:', result);
139+
const result = response.structuredResponse;
141140
// Process agent result
142-
const response = result.messages?.[-1]?.content;
143-
console.log(`[Auto] Agent response:`, response);
144-
145-
if (typeof response === 'string')
141+
try
146142
{
147-
// If it's a success message, return null to match original behavior
148-
if (response.startsWith('Successfully'))
143+
console.log(`[Auto] Agent response:`, result);
144+
145+
// Parse and validate the response
146+
const validatedResponse = AutoResponseSchema.parse(result);
147+
148+
console.log(`[Auto] Action: ${validatedResponse.action}`);
149+
if (validatedResponse.error)
149150
{
150-
console.log(`[Auto] Detected success message, returning null`);
151-
return null;
151+
console.log(`[Auto] Error: ${validatedResponse.error}`);
152152
}
153-
console.log(`[Auto] Returning response string`);
154-
return response;
155-
}
156153

157-
console.log(`[Auto] No string response, returning null`);
158-
return null;
154+
// Return the output or null if successful with no output
155+
return validatedResponse.output || null;
156+
} catch (error)
157+
{
158+
console.log(`[Auto] Error processing response:`, error);
159+
return null;
160+
}
159161
}
160162

161163
// Export everything needed for the package

0 commit comments

Comments
 (0)