Skip to content

Commit 2a48a2e

Browse files
AdditionalChanges
1 parent 095340a commit 2a48a2e

File tree

2 files changed

+74
-7
lines changed

2 files changed

+74
-7
lines changed

src/backend/kernel_agents/generic_agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,16 @@ def plugins(self):
124124
return GenericTools.get_all_kernel_functions()
125125

126126
# Explicitly inherit handle_action_request from the parent class
127-
async def handle_action_request(self, action_request_json: str) -> str:
127+
async def handle_action_request(self, action_request_json: str, **kwargs) -> str:
128128
"""Handle an action request from another agent or the system.
129129
130130
This method is inherited from BaseAgent but explicitly included here for clarity.
131131
132132
Args:
133133
action_request_json: The action request as a JSON string
134+
**kwargs: Additional keyword arguments (e.g., user_locale)
134135
135136
Returns:
136137
A JSON string containing the action response
137138
"""
138-
return await super().handle_action_request(action_request_json)
139+
return await super().handle_action_request(action_request_json, **kwargs)

src/backend/kernel_agents/planner_agent.py

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,39 @@ async def create(
140140
try:
141141
logging.info("Initializing PlannerAgent from async init azure AI Agent")
142142

143+
# Prepare template variables
144+
default_available_agents = [
145+
AgentType.HUMAN.value,
146+
AgentType.HR.value,
147+
AgentType.MARKETING.value,
148+
AgentType.PRODUCT.value,
149+
AgentType.PROCUREMENT.value,
150+
AgentType.TECH_SUPPORT.value,
151+
AgentType.GENERIC.value,
152+
]
153+
154+
agents_list = available_agents or default_available_agents
155+
agents_str = ", ".join(agents_list)
156+
157+
agent_tools_list = {
158+
AgentType.HR: HrTools.generate_tools_json_doc(),
159+
AgentType.MARKETING: MarketingTools.generate_tools_json_doc(),
160+
AgentType.PRODUCT: ProductTools.generate_tools_json_doc(),
161+
AgentType.PROCUREMENT: ProcurementTools.generate_tools_json_doc(),
162+
AgentType.TECH_SUPPORT: TechSupportTools.generate_tools_json_doc(),
163+
AgentType.GENERIC: GenericTools.generate_tools_json_doc(),
164+
}
165+
166+
tools_str = str(agent_tools_list)
167+
143168
# Create the Azure AI Agent using AppConfig with string instructions
144169
agent_definition = await cls._create_azure_ai_agent_definition(
145170
agent_name=agent_name,
146-
instructions=cls._get_template(), # Pass the formatted string, not an object
171+
instructions=cls._get_template().format(
172+
objective="undefined task", # This will be replaced during plan creation
173+
agents_str=agents_str,
174+
tools_str=tools_str
175+
),
147176
temperature=0.0,
148177
response_format=ResponseFormatJsonSchemaType(
149178
json_schema=ResponseFormatJsonSchema(
@@ -352,9 +381,16 @@ async def _create_structured_plan(
352381
if not response_content or response_content.isspace():
353382
raise ValueError("Received empty response from Azure AI Agent")
354383

384+
# Defensive check: If parsing gives a plan but no steps, fallback to dummy plan
385+
if '"steps": []' in response_content or '"steps":[]' in response_content:
386+
raise ValueError("Parsed response contains empty steps")
387+
355388
# Parse the JSON response directly to PlannerResponsePlan
356389
parsed_result = None
357390

391+
# Add logging before parsing
392+
logging.info(f"Planner raw response: {response_content}")
393+
358394
# Try various parsing approaches in sequence
359395
try:
360396
# 1. First attempt: Try to parse the raw response directly
@@ -378,6 +414,34 @@ async def _create_structured_plan(
378414
summary = parsed_result.summary_plan_and_steps
379415
human_clarification_request = parsed_result.human_clarification_request
380416

417+
# Fallback: If no steps were generated, create default steps
418+
if not steps_data:
419+
logging.warning("Planner returned no steps; falling back to default 2-step plan.")
420+
# Create default step data for roaming plan
421+
from models.messages_kernel import AgentType
422+
423+
class DefaultStep:
424+
def __init__(self, action, agent):
425+
self.action = action
426+
self.agent = agent
427+
428+
steps_data = [
429+
DefaultStep(
430+
action="Get information about available roaming packs and plans. Function: get_product_info",
431+
agent=AgentType.PRODUCT.value
432+
),
433+
DefaultStep(
434+
action="Add a roaming plan to the mobile service starting next week. Function: add_mobile_extras_pack",
435+
agent=AgentType.PRODUCT.value
436+
)
437+
]
438+
439+
# Update plan details for the default case
440+
if not initial_goal:
441+
initial_goal = "Enable roaming on mobile plan, starting next week."
442+
if not summary:
443+
summary = "Get roaming information and add roaming pack to mobile plan."
444+
381445
# Create the Plan instance
382446
plan = Plan(
383447
id=str(uuid.uuid4()),
@@ -387,6 +451,7 @@ async def _create_structured_plan(
387451
overall_status=PlanStatus.in_progress,
388452
summary=summary,
389453
human_clarification_request=human_clarification_request,
454+
user_locale=input_task.user_locale,
390455
)
391456

392457
# Store the plan
@@ -460,6 +525,7 @@ async def _create_structured_plan(
460525
overall_status=PlanStatus.in_progress,
461526
summary=f"Plan created for: {input_task.description}",
462527
human_clarification_request=None,
528+
user_locale=input_task.user_locale,
463529
timestamp=datetime.datetime.utcnow().isoformat(),
464530
)
465531

@@ -560,13 +626,13 @@ def _get_template():
560626
These actions are passed to the specific agent. Make sure the action contains all the information required for the agent to execute the task.
561627
562628
Your objective is:
563-
{{$objective}}
629+
{objective}
564630
565631
The agents you have access to are:
566-
{{$agents_str}}
632+
{agents_str}
567633
568634
These agents have access to the following functions:
569-
{{$tools_str}}
635+
{tools_str}
570636
571637
The first step of your plan should be to ask the user for any additional information required to progress the rest of steps planned.
572638
@@ -599,7 +665,7 @@ def _get_template():
599665
600666
Limit the plan to 6 steps or less.
601667
602-
Choose from {{$agents_str}} ONLY for planning your steps.
668+
Choose from {agents_str} ONLY for planning your steps.
603669
604670
"""
605671
return instruction_template

0 commit comments

Comments
 (0)