|
| 1 | +import { z } from 'zod/v4' |
1 | 2 | import { CodebuffConfigSchema } from '@codebuff/common/json-config/constants' |
2 | 3 | import { stringifySchema } from '@codebuff/common/json-config/stringify-schema' |
3 | 4 | import { |
@@ -146,24 +147,46 @@ export async function getAgentPrompt<T extends StringField | RequirePrompt>( |
146 | 147 |
|
147 | 148 | // Add parent instructions for userInputPrompt |
148 | 149 | if (promptType.type === 'userInputPrompt' && agentState.agentType) { |
149 | | - const parentInstructions = await collectParentInstructions( |
150 | | - agentState.agentType, |
151 | | - agentRegistry |
152 | | - ) |
153 | | - |
154 | 150 | addendum += |
155 | 151 | '\n\n' + |
156 | 152 | getShortToolInstructions( |
157 | 153 | agentTemplate.toolNames, |
158 | 154 | agentTemplate.spawnableAgents |
159 | 155 | ) |
160 | 156 |
|
| 157 | + const parentInstructions = await collectParentInstructions( |
| 158 | + agentState.agentType, |
| 159 | + agentRegistry |
| 160 | + ) |
| 161 | + |
161 | 162 | if (parentInstructions.length > 0) { |
162 | 163 | addendum += '\n\n## Additional Instructions for Spawning Agents\n\n' |
163 | 164 | addendum += parentInstructions |
164 | 165 | .map((instruction) => `- ${instruction}`) |
165 | 166 | .join('\n') |
166 | 167 | } |
| 168 | + |
| 169 | + // Add output schema information if defined |
| 170 | + if (agentTemplate.outputSchema) { |
| 171 | + addendum += '\n\n## Output Schema\n\n' |
| 172 | + addendum += |
| 173 | + 'When using the set_output tool, your output must conform to this schema:\n\n' |
| 174 | + addendum += '```json\n' |
| 175 | + try { |
| 176 | + // Convert Zod schema to JSON schema for display |
| 177 | + const jsonSchema = z.toJSONSchema(agentTemplate.outputSchema) |
| 178 | + delete jsonSchema['$schema'] // Remove the $schema field for cleaner display |
| 179 | + addendum += JSON.stringify(jsonSchema, null, 2) |
| 180 | + } catch { |
| 181 | + // Fallback to a simple description |
| 182 | + addendum += JSON.stringify( |
| 183 | + { type: 'object', description: 'Output schema validation enabled' }, |
| 184 | + null, |
| 185 | + 2 |
| 186 | + ) |
| 187 | + } |
| 188 | + addendum += '\n```' |
| 189 | + } |
167 | 190 | } |
168 | 191 |
|
169 | 192 | return prompt + addendum |
|
0 commit comments