@@ -54,6 +54,7 @@ def __init__(
5454 config_path : Optional [str ] = None ,
5555 available_agents : List [str ] = None ,
5656 agent_tools_list : List [str ] = None ,
57+ agent_instances : Optional [Dict [str , BaseAgent ]] = None ,
5758 client = None ,
5859 definition = None ,
5960 ) -> None :
@@ -70,6 +71,7 @@ def __init__(
7071 config_path: Optional path to the configuration file
7172 available_agents: List of available agent names for creating steps
7273 agent_tools_list: List of available tools across all agents
74+ agent_instances: Dictionary of agent instances available to the planner
7375 client: Optional client instance (passed to BaseAgent)
7476 definition: Optional definition instance (passed to BaseAgent)
7577 """
@@ -96,6 +98,7 @@ def __init__(
9698 "ProductAgent" , "ProcurementAgent" ,
9799 "TechSupportAgent" , "GenericAgent" ]
98100 self ._agent_tools_list = agent_tools_list or []
101+ self ._agent_instances = agent_instances or {}
99102
100103 # Create the Azure AI Agent for planning operations
101104 # This will be initialized in async_init
@@ -138,6 +141,11 @@ async def handle_input_task(self, kernel_arguments: KernelArguments) -> str:
138141
139142 # Generate a structured plan with steps
140143 plan , steps = await self ._create_structured_plan (input_task )
144+
145+ print (f"Plan created: { plan } " )
146+
147+ print (f"Steps created: { steps } " )
148+
141149
142150 if steps :
143151 # Add a message about the created plan
@@ -280,26 +288,34 @@ async def _create_structured_plan(self, input_task: InputTask) -> Tuple[Plan, Li
280288 if self ._azure_ai_agent is None :
281289 raise RuntimeError ("Failed to initialize Azure AI Agent for planning" )
282290
283- # Get response from the Azure AI Agent
284- # Based on the method signature, invoke takes only named arguments, not positional ones
291+ # Log detailed information about the instruction being sent
285292 logging .info (f"Invoking PlannerAgent with instruction length: { len (instruction )} " )
286293
287- # Create kernel arguments
294+ # Create kernel arguments - make sure we explicitly emphasize the task
288295 kernel_args = KernelArguments ()
289- kernel_args ["input" ] = instruction
296+ kernel_args ["input" ] = f"TASK: { input_task . description } \n \n { instruction } "
290297
298+ print (f"Kernel arguments: { kernel_args } " )
299+
291300 # Call invoke with proper keyword arguments
292301 response_content = ""
293302
294303 # Use keyword arguments instead of positional arguments
295- # Based on the method signature, we need to pass 'arguments' and possibly 'kernel'
296- async_generator = self ._azure_ai_agent .invoke (arguments = kernel_args )
304+ # Set a lower temperature to ensure consistent results
305+ async_generator = self ._azure_ai_agent .invoke (
306+ arguments = kernel_args ,
307+ settings = {
308+ "temperature" : 0.0
309+ }
310+ )
297311
298312 # Collect the response from the async generator
299313 async for chunk in async_generator :
300314 if chunk is not None :
301315 response_content += str (chunk )
302316
317+ print (f"Response content: { response_content } " )
318+
303319 # Debug the response
304320 logging .info (f"Response content length: { len (response_content )} " )
305321 logging .debug (f"Response content first 500 chars: { response_content [:500 ]} " )
@@ -358,6 +374,10 @@ async def _create_structured_plan(self, input_task: InputTask) -> Tuple[Plan, Li
358374 summary = parsed_result .summary_plan_and_steps
359375 human_clarification_request = parsed_result .human_clarification_request
360376
377+ # Log potential mismatches between task and plan for debugging
378+ if "onboard" in input_task .description .lower () and "marketing" in initial_goal .lower ():
379+ logging .warning (f"Potential mismatch: Task was about onboarding but plan goal mentions marketing: { initial_goal } " )
380+
361381 # Log the steps and agent assignments for debugging
362382 for i , step in enumerate (steps_data ):
363383 logging .info (f"Step { i + 1 } - Agent: { step .agent } , Action: { step .action } " )
@@ -469,7 +489,7 @@ async def _create_structured_plan(self, input_task: InputTask) -> Tuple[Plan, Li
469489
470490 await self ._memory_store .add_plan (error_plan )
471491 return error_plan , []
472-
492+
473493 async def _create_fallback_plan_from_text (self , input_task : InputTask , text_content : str ) -> Tuple [Plan , List [Step ]]:
474494 """Create a plan from unstructured text when JSON parsing fails.
475495
@@ -574,7 +594,44 @@ def _generate_instruction(self, objective: str) -> str:
574594 agents_str = ", " .join (self ._available_agents )
575595
576596 # Create list of available tools
577- tools_str = "\n " .join (self ._agent_tools_list ) if self ._agent_tools_list else "Various specialized tools"
597+ # If _agent_tools_list is empty but we have agent instances available elsewhere,
598+ # we should retrieve tools directly from agent instances
599+ tools_str = ""
600+ if hasattr (self , '_agent_instances' ) and self ._agent_instances :
601+ # Extract tools from agent instances
602+ agent_tools_sections = []
603+
604+ # Process each agent to get their tools
605+ for agent_name , agent in self ._agent_instances .items ():
606+ if hasattr (agent , '_tools' ) and agent ._tools :
607+ # Create a section header for this agent
608+ agent_tools_sections .append (f"### { agent_name } Tools ###" )
609+
610+ # Add each tool from this agent
611+ for tool in agent ._tools :
612+ if hasattr (tool , 'name' ) and hasattr (tool , 'description' ):
613+ tool_desc = f"Agent: { agent_name } - Function: { tool .name } - { tool .description } "
614+ agent_tools_sections .append (tool_desc )
615+
616+ # Add a blank line after each agent's tools
617+ agent_tools_sections .append ("" )
618+
619+ # Join all sections
620+ if agent_tools_sections :
621+ tools_str = "\n " .join (agent_tools_sections )
622+ # Log the tools for debugging
623+ logging .debug (f"Generated tools list from agent instances with { len (agent_tools_sections )} entries" )
624+ else :
625+ tools_str = "Various specialized tools (No tool details available from agent instances)"
626+ logging .warning ("No tools found in agent instances" )
627+ elif self ._agent_tools_list :
628+ # Fall back to the existing tools list if available
629+ tools_str = "\n " .join (self ._agent_tools_list )
630+ logging .debug (f"Using existing agent_tools_list with { len (self ._agent_tools_list )} entries" )
631+ else :
632+ # Default fallback
633+ tools_str = "Various specialized tools"
634+ logging .warning ("No tools information available for planner instruction" )
578635
579636 # Build the instruction, avoiding backslashes in f-string expressions
580637 objective_part = f"Your objective is:\n { objective } " if objective else "When given an objective, analyze it and create a plan to accomplish it."
0 commit comments