@@ -59,20 +59,42 @@ const PromptFieldSchema = z.union([
5959] )
6060export type PromptField = z . infer < typeof PromptFieldSchema >
6161
62+ // Schema for validating handleSteps function signature
63+ const HandleStepsSchema = z
64+ . function ( )
65+ . args (
66+ z . object ( {
67+ agentState : z . object ( {
68+ agentId : z . string ( ) ,
69+ parentId : z . string ( ) ,
70+ messageHistory : z . array ( z . any ( ) ) ,
71+ } ) ,
72+ prompt : z . string ( ) . optional ( ) ,
73+ params : z . any ( ) . optional ( ) ,
74+ } )
75+ )
76+ . 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+ )
86+ . optional ( )
87+
6288// Validates the Typescript template file.
6389export const DynamicAgentConfigSchema = z . object ( {
6490 id : z . string ( ) , // The unique identifier for this agent
6591 version : z . string ( ) . optional ( ) ,
66- override : z . literal ( false ) . optional ( ) . default ( false ) , // Must be false for new agents, defaults to false if missing
6792
6893 // Required fields for new agents
6994 displayName : z . string ( ) ,
7095 model : z . string ( ) ,
71- outputMode : z
72- . enum ( [ 'last_message' , 'all_messages' , 'json' ] )
73- . default ( 'last_message' ) , // Will be overridden to 'json' if outputSchema is present
74- outputSchema : JsonSchemaSchema . optional ( ) , // Optional JSON schema for output validation
75- includeMessageHistory : z . boolean ( ) . default ( true ) ,
96+
97+ // Tools and subagents
7698 toolNames : z
7799 . array ( z . enum ( toolNames ) )
78100 . optional ( )
@@ -98,35 +120,32 @@ export const DynamicAgentConfigSchema = z.object({
98120 }
99121 ) ,
100122 subagents : z . array ( z . string ( ) ) . optional ( ) . default ( [ ] ) ,
123+
124+ // Input and output
101125 inputSchema : InputSchemaObjectSchema ,
102- parentInstructions : z . record ( z . string ( ) , z . string ( ) ) . optional ( ) ,
126+ includeMessageHistory : z . boolean ( ) . default ( true ) ,
127+ outputMode : z
128+ . enum ( [ 'last_message' , 'all_messages' , 'json' ] )
129+ . default ( 'last_message' ) , // Will be overridden to 'json' if outputSchema is present
130+ outputSchema : JsonSchemaSchema . optional ( ) , // Optional JSON schema for output validation
103131
104132 // Prompts
105133 parentPrompt : z . string ( ) . optional ( ) ,
106134 systemPrompt : z . string ( ) . optional ( ) ,
107135 instructionsPrompt : z . string ( ) . optional ( ) ,
108136 stepPrompt : z . string ( ) ,
137+ parentInstructions : z . record ( z . string ( ) , z . string ( ) ) . optional ( ) ,
109138
110139 // Optional generator function for programmatic agents
111- handleSteps : z
112- . function (
113- z . tuple ( [
114- z . object ( {
115- agentState : z . any ( ) ,
116- prompt : z . string ( ) . optional ( ) ,
117- params : z . any ( ) ,
118- } ) ,
119- ] ) ,
120- z . any ( )
121- )
122- . optional ( ) ,
140+ handleSteps : HandleStepsSchema ,
123141} )
124142export type DynamicAgentConfig = z . input < typeof DynamicAgentConfigSchema >
125143export type DynamicAgentConfigParsed = z . infer < typeof DynamicAgentConfigSchema >
126144
127145// Checks that the AgentConfig and DynamicAgentConfig types are compatible
128- // NOTE TO LLM: Don't remove this line !
146+ // NOTE TO LLM: Don't remove these lines !
129147const _typecheck : AgentConfig = { } as DynamicAgentConfig
148+ const _typecheck2 : DynamicAgentConfig = { } as AgentConfig
130149
131150export const DynamicAgentTemplateSchema = DynamicAgentConfigSchema . extend ( {
132151 systemPrompt : z . string ( ) ,
0 commit comments