Skip to content

Commit b174f96

Browse files
committed
Fix tests
1 parent c41d592 commit b174f96

File tree

3 files changed

+42
-48
lines changed

3 files changed

+42
-48
lines changed

.agents/agent-template.d.ts

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ export interface AgentConfig {
4343
// Prompts
4444
// ============================================================================
4545

46-
/** Prompt for when to spawn this agent as a subagent. Include the main purpose and use cases. */
46+
/** Prompt for when to spawn this agent as a subagent. Include the main purpose and use cases.
47+
* This field is key if the agent is a subagent and intended to be spawned. */
4748
parentPrompt?: string
4849

49-
/** Background information for the agent. Prefer using instructionsPrompt for agent instructions. */
50+
/** Background information for the agent. Fairly optional. Prefer using instructionsPrompt for agent instructions. */
5051
systemPrompt?: string
5152

5253
/** Instructions for the agent.
@@ -55,29 +56,33 @@ export interface AgentConfig {
5556
instructionsPrompt?: string
5657

5758
/** Prompt inserted at each agent step. Powerful for changing the agent's behavior,
58-
* but prefer instructionsPrompt for most instructions. */
59+
* but usually not necessary for smart models. Prefer instructionsPrompt for most instructions. */
5960
stepPrompt: string
6061

61-
/** Instructions for specific parent agents on when to spawn this agent as a subagent. */
62-
parentInstructions?: Record<SubagentName, string>
63-
6462
// ============================================================================
6563
// Input and Output
6664
// ============================================================================
6765

68-
/** The input schema required to spawn the agent. Provide a prompt string and/or a params object. */
66+
/** The input schema required to spawn the agent. Provide a prompt string and/or a params object or none.
67+
* 80% of the time you want just a prompt string with a description:
68+
* inputSchema: {
69+
* prompt: { type: 'string', description: 'A description of what info would be helpful to the agent' }
70+
* }
71+
*/
6972
inputSchema?: {
7073
prompt?: { type: 'string'; description?: string }
7174
params?: JsonSchema
7275
}
7376

74-
/** Whether to include conversation history (defaults to true) */
77+
/** Whether to include conversation history. Defaults to false.
78+
* Use this if the agent needs to know all the previous messages in the conversation.
79+
*/
7580
includeMessageHistory?: boolean
7681

7782
/** How the agent should output a response to its parent (defaults to 'last_message')
7883
* last_message: The last message from the agent, typcically after using tools.
7984
* all_messages: All messages from the agent, including tool calls and results.
80-
* json: Make the agent output a structured JSON object. Can be used with outputSchema or without if you want freeform json output.
85+
* json: Make the agent output a JSON object. Can be used with outputSchema or without if you want freeform json output.
8186
*/
8287
outputMode?: 'last_message' | 'all_messages' | 'json'
8388

@@ -97,14 +102,35 @@ export interface AgentConfig {
97102
*
98103
* Or use 'return' to end the turn.
99104
*
100-
* Example:
105+
* Example 1:
101106
* function* handleSteps({ agentStep, prompt, params}) {
102107
* const { toolResult } = yield {
103108
* toolName: 'read_files',
104109
* args: { paths: ['file1.txt', 'file2.txt'] }
105110
* }
106111
* yield 'STEP_ALL'
107112
* }
113+
*
114+
* Example 2:
115+
* handleSteps: function* ({ agentState, prompt, params }) {
116+
* while (true) {
117+
* yield {
118+
* toolName: 'spawn_agents',
119+
* args: {
120+
* agents: [
121+
* {
122+
* agent_type: 'thinker',
123+
* prompt: 'Think deeply about the user request',
124+
* },
125+
* ],
126+
* },
127+
* }
128+
* const { toolResult: thinkResult } = yield 'STEP'
129+
* if (thinkResult?.toolName === 'end_turn') {
130+
* break
131+
* }
132+
* }
133+
* }
108134
*/
109135
handleSteps?: (
110136
context: AgentStepContext
@@ -148,8 +174,8 @@ export interface ToolResult {
148174
*/
149175
export interface AgentStepContext {
150176
agentState: AgentState
151-
prompt: string | undefined
152-
params: Record<string, any> | undefined
177+
prompt?: string
178+
params?: Record<string, any>
153179
}
154180

155181
/**
@@ -257,7 +283,7 @@ export type ModelName =
257283
| 'google/gemini-2.5-pro'
258284
| 'google/gemini-2.5-flash'
259285
| 'x-ai/grok-4-07-09'
260-
| string
286+
| (string & {})
261287

262288
// ============================================================================
263289
// Spawnable Agents
@@ -272,7 +298,7 @@ export type SubagentName =
272298
| 'researcher'
273299
| 'thinker'
274300
| 'reviewer'
275-
| string
301+
| (string & {})
276302

277303
// ============================================================================
278304
// Utility Types

common/src/__tests__/dynamic-agent-template-schema.test.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ describe('DynamicAgentConfigSchema', () => {
1212
const validBaseTemplate = {
1313
id: 'test_agent',
1414
version: '1.0.0',
15-
override: false,
1615
displayName: 'Test Agent',
1716
parentPrompt: 'A test agent',
1817
model: 'anthropic/claude-4-sonnet-20250522',
@@ -115,25 +114,13 @@ describe('DynamicAgentConfigSchema', () => {
115114
expect(result.success).toBe(true)
116115
})
117116

118-
it('should validate template with path references', () => {
119-
const template = {
120-
...validBaseTemplate,
121-
systemPrompt: { path: './system-prompt.md' },
122-
instructionsPrompt: { path: './user-input-prompt.md' },
123-
stepPrompt: { path: './agent-step-prompt.md' },
124-
}
125-
126-
const result = DynamicAgentConfigSchema.safeParse(template)
127-
expect(result.success).toBe(true)
128-
})
129-
130117
it('should apply default values', () => {
131118
const result = DynamicAgentConfigSchema.safeParse(validBaseTemplate)
132119
expect(result.success).toBe(true)
133120
if (result.success) {
134121
expect(result.data.outputMode).toBe('last_message')
135122
expect(result.data.includeMessageHistory).toBe(true)
136-
expect(result.data.toolNames).toEqual(['end_turn'])
123+
expect(result.data.toolNames).toEqual([])
137124
expect(result.data.subagents).toEqual([])
138125
}
139126
})
@@ -164,16 +151,6 @@ describe('DynamicAgentConfigSchema', () => {
164151
expect(result.success).toBe(false)
165152
})
166153

167-
it('should reject template with override: true', () => {
168-
const template = {
169-
...validBaseTemplate,
170-
override: true,
171-
}
172-
173-
const result = DynamicAgentConfigSchema.safeParse(template)
174-
expect(result.success).toBe(false)
175-
})
176-
177154
it('should reject template with invalid outputMode', () => {
178155
const template = {
179156
...validBaseTemplate,
@@ -217,7 +194,7 @@ describe('DynamicAgentConfigSchema', () => {
217194
it('should reject template with invalid prompt field structure', () => {
218195
const template = {
219196
...validBaseTemplate,
220-
systemPrompt: { invalidField: 'value' }, // Should be { path: string }
197+
systemPrompt: { invalidField: 'value' }, // Should be string only
221198
}
222199

223200
const result = DynamicAgentConfigSchema.safeParse(template)

common/src/types/dynamic-agent-template.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ const HandleStepsSchema = z
7474
})
7575
)
7676
.returns(z.any())
77-
.refine(
78-
(fn) => {
79-
// Check if it's a generator function
80-
return fn.constructor.name === 'GeneratorFunction'
81-
},
82-
{
83-
message: 'handleSteps must be a generator function',
84-
}
85-
)
8677
.optional()
8778

8879
// Validates the Typescript template file.

0 commit comments

Comments
 (0)