Skip to content

Commit 55047d8

Browse files
committed
clean up planner_agent
1 parent be3f7f4 commit 55047d8

File tree

2 files changed

+62
-47
lines changed

2 files changed

+62
-47
lines changed

src/backend/app_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ async def create_azure_ai_agent(
219219
tool_definitions = tools
220220

221221
# Create the agent using the project client
222-
logging.info("Creating agent '%s' with model '%s'", agent_name, self.AZURE_OPENAI_DEPLOYMENT_NAME)
222+
if response_format is not None:
223+
logging.info("Response format provided: %s", response_format)
224+
225+
223226
agent_definition = await project_client.agents.create_agent(
224227
model=self.AZURE_OPENAI_DEPLOYMENT_NAME,
225228
name=agent_name,

src/backend/kernel_agents/planner_agent.py

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,7 @@ async def handle_input_task(self, input_task: InputTask) -> str:
128128
# Parse the input task
129129
logging.info("Handling input task")
130130

131-
logging.info(f"Parsed input task: {input_task}")
132-
133-
# Generate a structured plan with steps
134-
135-
logging.info(f"Received input task: {input_task.description}")
136-
logging.info(f"Session ID: {input_task.session_id}, User ID: {self._user_id}")
131+
137132
plan, steps = await self._create_structured_plan(input_task)
138133

139134
logging.info(f"Plan created: {plan}")
@@ -268,16 +263,9 @@ async def _create_structured_plan(self, input_task: InputTask) -> Tuple[Plan, Li
268263
"""
269264
try:
270265
# Generate the instruction for the LLM
271-
logging.info("Generating instruction for the LLM")
272-
logging.debug(f"Input: {input_task}")
273-
logging.debug(f"Available agents: {self._available_agents}")
274266

275267
instruction = self._generate_instruction(input_task.description)
276268

277-
logging.info(f"Generated instruction: {instruction}")
278-
# Log the input task for debugging
279-
logging.info(f"Creating plan for task: '{input_task.description}'")
280-
logging.info(f"Using available agents: {self._available_agents}")
281269

282270
# Use the Azure AI Agent instead of direct function invocation
283271
if self._azure_ai_agent is None:
@@ -587,47 +575,71 @@ def _generate_instruction(self, objective: str) -> str:
587575
# Create a list of available agents
588576
agents_str = ", ".join(self._available_agents)
589577

590-
# Create list of available tools
591-
# If _agent_tools_list is empty but we have agent instances available elsewhere,
592-
# we should retrieve tools directly from agent instances
593-
tools_str = ""
578+
# Create list of available tools in JSON-like format
579+
tools_list = []
580+
581+
# Check if we have agent instances to extract tools from
594582
if hasattr(self, '_agent_instances') and self._agent_instances:
595-
# Extract tools from agent instances
596-
agent_tools_sections = []
597-
598583
# Process each agent to get their tools
599584
for agent_name, agent in self._agent_instances.items():
600585
if hasattr(agent, '_tools') and agent._tools:
601-
# Create a section header for this agent
602-
agent_tools_sections.append(f"### {agent_name} Tools ###")
603-
604586
# Add each tool from this agent
605587
for tool in agent._tools:
606588
if hasattr(tool, 'name') and hasattr(tool, 'description'):
607-
tool_desc = f"Agent: {agent_name} - Function: {tool.name} - {tool.description}"
608-
agent_tools_sections.append(tool_desc)
609-
610-
# Add a blank line after each agent's tools
611-
agent_tools_sections.append("")
589+
# Extract function parameters/arguments
590+
args_dict = {}
591+
if hasattr(tool, 'parameters'):
592+
for param in tool.parameters:
593+
param_type = "string" # Default type
594+
if hasattr(param, 'type'):
595+
param_type = param.type
596+
597+
args_dict[param.name] = {
598+
'description': param.description,
599+
'title': param.name.replace('_', ' ').title(),
600+
'type': param_type
601+
}
602+
603+
# Create tool entry
604+
tool_entry = {
605+
'agent': agent_name,
606+
'function': tool.name,
607+
'description': tool.description,
608+
'arguments': str(args_dict)
609+
}
610+
611+
tools_list.append(tool_entry)
612612

613-
# Join all sections
614-
if agent_tools_sections:
615-
tools_str = "\n".join(agent_tools_sections)
616-
# Log the tools for debugging
617-
logging.debug(f"Generated tools list from agent instances with {len(agent_tools_sections)} entries")
618-
else:
619-
tools_str = "Various specialized tools (No tool details available from agent instances)"
620-
logging.warning("No tools found in agent instances")
621-
elif self._agent_tools_list:
622-
# Fall back to the existing tools list if available
623-
tools_str = "\n".join(self._agent_tools_list)
624-
logging.debug(f"Using existing agent_tools_list with {len(self._agent_tools_list)} entries")
625-
else:
626-
# Default fallback
627-
tools_str = "Various specialized tools"
628-
logging.warning("No tools information available for planner instruction")
629-
630-
# Build the instruction, avoiding backslashes in f-string expressions
613+
logging.debug(f"Generated {len(tools_list)} tools from agent instances")
614+
615+
# If we couldn't extract tools from agent instances, create a simplified format
616+
if not tools_list:
617+
logging.warning("No tool details extracted from agent instances, creating simplified format")
618+
if self._agent_tools_list:
619+
# Create dummy entries from the existing tool list strings
620+
for tool_str in self._agent_tools_list:
621+
if ":" in tool_str:
622+
parts = tool_str.split(":")
623+
if len(parts) >= 2:
624+
agent_part = parts[0].strip()
625+
function_part = parts[1].strip()
626+
627+
# Extract agent name if format is "Agent: AgentName"
628+
agent_name = agent_part.replace("Agent", "").strip()
629+
if not agent_name:
630+
agent_name = "GenericAgent"
631+
632+
tools_list.append({
633+
'agent': agent_name,
634+
'function': function_part,
635+
'description': f"Function {function_part} from {agent_name}",
636+
'arguments': "{}"
637+
})
638+
639+
# Convert the tools list to a string representation
640+
tools_str = str(tools_list)
641+
642+
# Build the instruction, avoiding backslashes in f-string expressions
631643
objective_part = f"Your objective is:\n{objective}" if objective else "When given an objective, analyze it and create a plan to accomplish it."
632644

633645
return f"""

0 commit comments

Comments
 (0)