|
1 | 1 | import { |
2 | 2 | ActionCacheOutput, |
| 3 | + AgentOutput, |
3 | 4 | AgentStep, |
4 | 5 | AgentTaskOutput, |
5 | 6 | } from "@/types/agent/types"; |
@@ -227,6 +228,28 @@ function normalizeActionOutput( |
227 | 228 | }; |
228 | 229 | } |
229 | 230 |
|
| 231 | +function normalizeAgentOutput(value: unknown): AgentOutput { |
| 232 | + const thoughts = formatDiagnosticText( |
| 233 | + safeReadRecordField(value, "thoughts"), |
| 234 | + MAX_RUNTIME_ACTION_MESSAGE_CHARS, |
| 235 | + "" |
| 236 | + ); |
| 237 | + const memory = formatDiagnosticText( |
| 238 | + safeReadRecordField(value, "memory"), |
| 239 | + MAX_RUNTIME_ACTION_MESSAGE_CHARS, |
| 240 | + "" |
| 241 | + ); |
| 242 | + const action = safeReadRecordField(value, "action"); |
| 243 | + return { |
| 244 | + thoughts, |
| 245 | + memory, |
| 246 | + action: { |
| 247 | + type: normalizeRuntimeActionType(safeReadRecordField(action, "type")), |
| 248 | + params: safeReadRecordField(action, "params"), |
| 249 | + }, |
| 250 | + }; |
| 251 | +} |
| 252 | + |
230 | 253 | function resolveCompleteActionFormatter( |
231 | 254 | actions: Array<AgentActionDefinition> |
232 | 255 | ): |
@@ -855,7 +878,7 @@ export const runAgentTask = async ( |
855 | 878 | } |
856 | 879 |
|
857 | 880 | // Invoke LLM with structured output |
858 | | - const agentOutput = await (async () => { |
| 881 | + const rawAgentOutput = await (async () => { |
859 | 882 | const maxAttempts = 3; |
860 | 883 | let currentMsgs = msgs; |
861 | 884 |
|
@@ -1004,6 +1027,7 @@ export const runAgentTask = async ( |
1004 | 1027 | } |
1005 | 1028 | throw new Error("Failed to get structured output from LLM"); |
1006 | 1029 | })(); |
| 1030 | + const agentOutput = normalizeAgentOutput(rawAgentOutput); |
1007 | 1031 |
|
1008 | 1032 | params?.debugOnAgentOutput?.(agentOutput); |
1009 | 1033 |
|
|
0 commit comments