@@ -60,56 +60,57 @@ async def handle_input_task(self, message: InputTask, ctx: MessageContext) -> Pl
6060 [UserMessage (content = instruction , source = "PlannerAgent" )]
6161 )
6262
63- await self ._memory .add_item (
64- AgentMessage (
65- session_id = message .session_id ,
66- user_id = self ._user_id ,
67- plan_id = plan .id ,
68- content = f"Generated a plan with { len (steps )} steps. Click the blue check box beside each step to complete it, click the x to remove this step." ,
69- source = "PlannerAgent" ,
70- step_id = "" ,
71- )
72- )
73- logging .info (f"Plan generated: { plan .summary } " )
74-
75- track_event (
76- f"Planner - Generated a plan with { len (steps )} steps and added plan into the cosmos" ,
77- {
78- "session_id" : message .session_id ,
79- "user_id" : self ._user_id ,
80- "plan_id" : plan .id ,
81- "content" : f"Generated a plan with { len (steps )} steps. Click the blue check box beside each step to complete it, click the x to remove this step." ,
82- "source" : "PlannerAgent" ,
83- },
84- )
85-
86- if plan .human_clarification_request is not None :
87- # if the plan identified that user information was required, send a message asking the user for it
63+ if steps :
8864 await self ._memory .add_item (
8965 AgentMessage (
9066 session_id = message .session_id ,
9167 user_id = self ._user_id ,
9268 plan_id = plan .id ,
93- content = f"I require additional information before we can proceed: { plan . human_clarification_request } " ,
69+ content = f"Generated a plan with { len ( steps ) } steps. Click the blue check box beside each step to complete it, click the x to remove this step. " ,
9470 source = "PlannerAgent" ,
9571 step_id = "" ,
9672 )
9773 )
98- logging .info (
99- f"Additional information requested: { plan .human_clarification_request } "
100- )
74+ logging .info (f"Plan generated: { plan .summary } " )
10175
10276 track_event (
103- "Planner - Additional information requested and added into the cosmos" ,
77+ f "Planner - Generated a plan with { len ( steps ) } steps and added plan into the cosmos" ,
10478 {
10579 "session_id" : message .session_id ,
10680 "user_id" : self ._user_id ,
10781 "plan_id" : plan .id ,
108- "content" : f"I require additional information before we can proceed: { plan . human_clarification_request } " ,
82+ "content" : f"Generated a plan with { len ( steps ) } steps. Click the blue check box beside each step to complete it, click the x to remove this step. " ,
10983 "source" : "PlannerAgent" ,
11084 },
11185 )
11286
87+ if plan .human_clarification_request is not None :
88+ # if the plan identified that user information was required, send a message asking the user for it
89+ await self ._memory .add_item (
90+ AgentMessage (
91+ session_id = message .session_id ,
92+ user_id = self ._user_id ,
93+ plan_id = plan .id ,
94+ content = f"I require additional information before we can proceed: { plan .human_clarification_request } " ,
95+ source = "PlannerAgent" ,
96+ step_id = "" ,
97+ )
98+ )
99+ logging .info (
100+ f"Additional information requested: { plan .human_clarification_request } "
101+ )
102+
103+ track_event (
104+ "Planner - Additional information requested and added into the cosmos" ,
105+ {
106+ "session_id" : message .session_id ,
107+ "user_id" : self ._user_id ,
108+ "plan_id" : plan .id ,
109+ "content" : f"I require additional information before we can proceed: { plan .human_clarification_request } " ,
110+ "source" : "PlannerAgent" ,
111+ },
112+ )
113+
113114 return plan
114115
115116 @message_handler
@@ -251,6 +252,21 @@ class StructuredOutputPlan(BaseModel):
251252 # Parse the LLM response
252253 parsed_result = json .loads (content )
253254 structured_plan = StructuredOutputPlan (** parsed_result )
255+
256+ if not structured_plan .steps :
257+ track_event (
258+ "Planner agent - No steps found" ,
259+ {
260+ "session_id" :self ._session_id ,
261+ "user_id" :self ._user_id ,
262+ "initial_goal" :structured_plan .initial_goal ,
263+ "overall_status" :"No steps found" ,
264+ "source" :"PlannerAgent" ,
265+ "summary" :structured_plan .summary_plan_and_steps ,
266+ "human_clarification_request" :structured_plan .human_clarification_request
267+ },
268+ )
269+ raise ValueError ("No steps found" )
254270
255271 # Create the Plan instance
256272 plan = Plan (
@@ -318,17 +334,17 @@ class StructuredOutputPlan(BaseModel):
318334 "initial_goal" : "Error generating plan" ,
319335 "overall_status" : PlanStatus .failed ,
320336 "source" : "PlannerAgent" ,
321- "summary" : "Error generating plan" ,
337+ "summary" : f "Error generating plan: { e } " ,
322338 },
323339 )
324340 # Handle the error, possibly by creating a plan with an error step
325341 plan = Plan (
326- id = str ( uuid . uuid4 ()),
342+ id = "" , # No need of plan id as the steps are not getting created
327343 session_id = self ._session_id ,
328344 user_id = self ._user_id ,
329345 initial_goal = "Error generating plan" ,
330346 overall_status = PlanStatus .failed ,
331347 source = "PlannerAgent" ,
332- summary = "Error generating plan" ,
348+ summary = f "Error generating plan: { e } " ,
333349 )
334350 return plan , []
0 commit comments