Skip to content

Commit f3573dc

Browse files
committed
set_output: include optional data field to appease openai
1 parent 833a7d7 commit f3573dc

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

common/src/tools/params/tool/set-output.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ import type { $ToolParams } from '../../constants'
77
const toolName = 'set_output'
88
const endsAgentStep = false
99
const inputSchema = z
10-
.looseObject({})
10+
.looseObject({
11+
data: z.record(z.string(), z.any()).optional(),
12+
})
1113
.describe(
1214
'JSON object to set as the agent output. This completely replaces any previous output. If the agent was spawned, this value will be passed back to its parent. If the agent has an outputSchema defined, the output will be validated against it.',
1315
)
1416
const description = `
1517
Subagents must use this tool as it is the only way to report any findings. Nothing else you write will be visible to the user/parent agent.
1618
19+
Note that the output schema is provided dynamically in a user prompt further down in the conversation. Be sure to follow what the latest output schema is when using this tool.
20+
1721
Please set the output with all the information and analysis you want to pass on. If you just want to send a simple message, use an object with the key "message" and value of the message you want to send.
1822
Example:
1923
${$getNativeToolCallExampleString({

packages/agent-runtime/src/tools/handlers/tool/set-output.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const handleSetOutput = (async (params: {
2828
}): Promise<{ output: CodebuffToolOutput<ToolName> }> => {
2929
const { previousToolCallFinished, toolCall, agentState, logger } = params
3030
const output = toolCall.input
31+
let { data } = output ?? {}
3132

3233
await previousToolCallFinished
3334

@@ -42,23 +43,29 @@ export const handleSetOutput = (async (params: {
4243
if (agentTemplate?.outputSchema) {
4344
try {
4445
agentTemplate.outputSchema.parse(output)
46+
data = output
4547
} catch (error) {
46-
const errorMessage = `Output validation error: Output failed to match the output schema and was ignored. You might want to try again! Issues: ${error}`
47-
logger.error(
48-
{
49-
output,
50-
agentType: agentState.agentType,
51-
agentId: agentState.agentId,
52-
error,
53-
},
54-
'set_output validation error',
55-
)
56-
return { output: jsonToolResult({ message: errorMessage }) }
48+
try {
49+
// Fallback to the 'data' field if the whole output object is not valid
50+
agentTemplate.outputSchema.parse(data)
51+
} catch (error2) {
52+
const errorMessage = `Output validation error: Output failed to match the output schema and was ignored. You might want to try again! Issues: ${error}`
53+
logger.error(
54+
{
55+
output,
56+
agentType: agentState.agentType,
57+
agentId: agentState.agentId,
58+
error,
59+
},
60+
'set_output validation error',
61+
)
62+
return { output: jsonToolResult({ message: errorMessage }) }
63+
}
5764
}
5865
}
5966

6067
// Set the output (completely replaces previous output)
61-
agentState.output = output
68+
agentState.output = data
6269

6370
return { output: jsonToolResult({ message: 'Output set' }) }
6471
}) satisfies CodebuffToolHandlerFunction<ToolName>

0 commit comments

Comments
 (0)