Skip to content

Commit 57181f6

Browse files
committed
Merge branch 'azd-semantickernel-marktayl'
2 parents 72dd384 + 9856d01 commit 57181f6

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

src/backend/kernel_agents/planner_agent.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,8 @@ async def async_init(self) -> None:
148148
try:
149149
logging.info("Initializing PlannerAgent from async init azure AI Agent")
150150

151-
# Generate instructions as a string rather than returning an object
152-
# We'll use a blank input since this is just for initialization
153-
instruction_args = self._generate_instruction("")
154-
instructions = self._get_template().format(**instruction_args)
151+
# Get the agent template - defined in function to allow for easy updates
152+
instructions = self._get_template()
155153

156154
# Create the Azure AI Agent using AppConfig with string instructions
157155
self._azure_ai_agent = await config.create_azure_ai_agent(
@@ -318,12 +316,8 @@ async def _create_structured_plan(self, input_task: InputTask) -> Tuple[Plan, Li
318316
logging.debug(f"Available agents: {self._available_agents}")
319317

320318
# Get template variables as a dictionary
321-
args = self._generate_instruction(input_task.description)
319+
args = self._generate_args(input_task.description)
322320

323-
# Format the template with the arguments
324-
instruction = self._get_template().format(**args)
325-
logging.info(f"Generated instruction: {instruction}")
326-
# Log the input task for debugging
327321
logging.info(f"Creating plan for task: '{input_task.description}'")
328322
logging.info(f"Using available agents: {self._available_agents}")
329323

@@ -336,20 +330,17 @@ async def _create_structured_plan(self, input_task: InputTask) -> Tuple[Plan, Li
336330
raise RuntimeError("Failed to initialize Azure AI Agent for planning")
337331

338332
# Log detailed information about the instruction being sent
339-
logging.info(f"Invoking PlannerAgent with instruction length: {len(instruction)}")
333+
#logging.info(f"Invoking PlannerAgent with instruction length: {len(instruction)}")
340334

341335
# Create kernel arguments - make sure we explicitly emphasize the task
342-
kernel_args = KernelArguments()
343-
kernel_args["input"] = f"TASK: {input_task.description}\n\n{instruction}"
336+
kernel_args = KernelArguments(**args)
337+
#kernel_args["input"] = f"TASK: {input_task.description}\n\n{instruction}"
344338

345339
logging.debug(f"Kernel arguments: {kernel_args}")
346340

347341
# Get the schema for our expected response format
348342
response_format_schema = self._get_response_format_schema()
349343

350-
# Call invoke with proper keyword arguments and JSON response schema
351-
response_content = ""
352-
353344
# Ensure we're using the right pattern for Azure AI agents with semantic kernel
354345
# Properly handle async generation
355346
async_generator = self._azure_ai_agent.invoke(
@@ -363,6 +354,9 @@ async def _create_structured_plan(self, input_task: InputTask) -> Tuple[Plan, Li
363354
}
364355
}
365356
)
357+
358+
# Call invoke with proper keyword arguments and JSON response schema
359+
response_content = ""
366360

367361
# Collect the response from the async generator
368362
async for chunk in async_generator:
@@ -660,7 +654,7 @@ async def _create_fallback_plan_from_text(self, input_task: InputTask, text_cont
660654

661655
return plan, steps
662656

663-
def _generate_instruction(self, objective: str) -> any:
657+
def _generate_args(self, objective: str) -> any:
664658
"""Generate instruction for the LLM to create a plan.
665659
666660
Args:
@@ -796,13 +790,13 @@ def _get_template(self):
796790
These actions are passed to the specific agent. Make sure the action contains all the information required for the agent to execute the task.
797791
798792
Your objective is:
799-
{objective}
793+
{{$objective}}
800794
801795
The agents you have access to are:
802-
{agents_str}
796+
{{$agents_str}}
803797
804798
These agents have access to the following functions:
805-
{tools_str}
799+
{{$tools_str}}
806800
807801
IMPORTANT AGENT SELECTION GUIDANCE:
808802
- HrAgent: ALWAYS use for ALL employee-related tasks like onboarding, hiring, benefits, payroll, training, employee records, ID cards, mentoring, background checks, etc.
@@ -830,7 +824,7 @@ def _get_template(self):
830824
831825
Limit the plan to 6 steps or less.
832826
833-
Choose from {agents_str} ONLY for planning your steps.
827+
Choose from {{$agents_str}} ONLY for planning your steps.
834828
835829
"""
836830
return instruction_template

0 commit comments

Comments
 (0)