@@ -109,15 +109,22 @@ impl AgentLoop {
109109 }
110110 }
111111
112- pub ( super ) fn delegated_prompt_for_step (
112+ pub ( super ) fn delegated_prompt_for_step_with_goal (
113+ plan_goal : Option < & str > ,
113114 step : & Task ,
114115 step_number : usize ,
115116 total_steps : usize ,
116117 ) -> String {
117- let mut prompt = format ! (
118+ let mut prompt = String :: new ( ) ;
119+ if let Some ( goal) = plan_goal. map ( str:: trim) . filter ( |goal| !goal. is_empty ( ) ) {
120+ prompt. push_str ( "Plan goal/context:\n " ) ;
121+ prompt. push_str ( goal) ;
122+ prompt. push_str ( "\n \n " ) ;
123+ }
124+ prompt. push_str ( & format ! (
118125 "Execute plan step {}/{}.\n \n Task:\n {}\n " ,
119126 step_number, total_steps, step. content
120- ) ;
127+ ) ) ;
121128 if let Some ( criteria) = step
122129 . success_criteria
123130 . as_deref ( )
@@ -131,25 +138,29 @@ impl AgentLoop {
131138 prompt
132139 }
133140
134- pub ( super ) fn delegated_task_args (
141+ pub ( super ) fn delegated_task_args_with_goal (
142+ plan_goal : Option < & str > ,
135143 step : & Task ,
136144 step_number : usize ,
137145 total_steps : usize ,
138146 ) -> Value {
139147 json ! ( {
140148 "agent" : Self :: delegated_agent_for_step( step) ,
141149 "description" : step. content,
142- "prompt" : Self :: delegated_prompt_for_step ( step, step_number, total_steps) ,
150+ "prompt" : Self :: delegated_prompt_for_step_with_goal ( plan_goal , step, step_number, total_steps) ,
143151 } )
144152 }
145153
146- pub ( super ) fn parallel_delegated_task_args (
154+ pub ( super ) fn parallel_delegated_task_args_with_goal (
155+ plan_goal : Option < & str > ,
147156 steps : & [ ( Task , usize ) ] ,
148157 total_steps : usize ,
149158 ) -> Value {
150159 let tasks = steps
151160 . iter ( )
152- . map ( |( step, step_number) | Self :: delegated_task_args ( step, * step_number, total_steps) )
161+ . map ( |( step, step_number) | {
162+ Self :: delegated_task_args_with_goal ( plan_goal, step, * step_number, total_steps)
163+ } )
153164 . collect :: < Vec < _ > > ( ) ;
154165 json ! ( { "tasks" : tasks } )
155166 }
@@ -275,9 +286,14 @@ impl AgentLoop {
275286 _ => "task" ,
276287 } ;
277288 let args = if tool_name == "parallel_task" {
278- json ! ( { "tasks" : [ Self :: delegated_task_args ( & step, step_number, total_steps) ] } )
289+ json ! ( { "tasks" : [ Self :: delegated_task_args_with_goal ( Some ( & plan . goal ) , & step, step_number, total_steps) ] } )
279290 } else {
280- Self :: delegated_task_args ( & step, step_number, total_steps)
291+ Self :: delegated_task_args_with_goal (
292+ Some ( & plan. goal ) ,
293+ & step,
294+ step_number,
295+ total_steps,
296+ )
281297 } ;
282298 let ( output, _exit_code, is_error, _metadata) = self
283299 . execute_delegated_plan_tool ( tool_name, & args, session_id, & event_tx)
@@ -429,7 +445,11 @@ impl AgentLoop {
429445 . iter ( )
430446 . all ( |( step, _) | Self :: should_delegate_plan_step ( step) )
431447 {
432- let args = Self :: parallel_delegated_task_args ( & ready_steps, total_steps) ;
448+ let args = Self :: parallel_delegated_task_args_with_goal (
449+ Some ( & plan. goal ) ,
450+ & ready_steps,
451+ total_steps,
452+ ) ;
433453 let ( output, _exit_code, is_error, metadata) = self
434454 . execute_delegated_plan_tool ( "parallel_task" , & args, session_id, & event_tx)
435455 . await ;
0 commit comments