Skip to content

Commit ced399c

Browse files
committed
agent action handle fix
1 parent eefd17a commit ced399c

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/backend/kernel_agents/agent_base.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,27 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:
277277
chat_history = self._chat_history.copy()
278278

279279
# Call the agent to handle the action
280-
agent_response = self._agent.invoke(
280+
async_generator = self._agent.invoke(
281281
self._kernel, f"{action_request.action}\n\nPlease perform this action"
282282
)
283-
result = str(agent_response)
283+
284+
response_content = ""
285+
286+
# Collect the response from the async generator
287+
async for chunk in async_generator:
288+
if chunk is not None:
289+
response_content += str(chunk)
290+
291+
logging.info(f"Response content length: {len(response_content)}")
292+
logging.info(f"Response content: {response_content}")
284293

285294
# Store agent message in cosmos memory
286295
await self._memory_store.add_item(
287296
AgentMessage(
288297
session_id=action_request.session_id,
289298
user_id=self._user_id,
290299
plan_id=action_request.plan_id,
291-
content=f"{result}",
300+
content=f"{response_content}",
292301
source=self._agent_name,
293302
step_id=action_request.step_id,
294303
)
@@ -301,7 +310,7 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:
301310
"session_id": action_request.session_id,
302311
"user_id": self._user_id,
303312
"plan_id": action_request.plan_id,
304-
"content": f"{result}",
313+
"content": f"{response_content}",
305314
"source": self._agent_name,
306315
"step_id": action_request.step_id,
307316
},
@@ -333,11 +342,11 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:
333342
)
334343
return response.json()
335344

336-
logging.info(f"Task completed: {result}")
345+
logging.info(f"Task completed: {response_content}")
337346

338347
# Update step status
339348
step.status = StepStatus.completed
340-
step.agent_reply = result
349+
step.agent_reply = response_content
341350
await self._memory_store.update_step(step)
342351

343352
# Track step completion in telemetry
@@ -346,10 +355,10 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:
346355
{
347356
"status": StepStatus.completed,
348357
"session_id": action_request.session_id,
349-
"agent_reply": f"{result}",
358+
"agent_reply": f"{response_content}",
350359
"user_id": self._user_id,
351360
"plan_id": action_request.plan_id,
352-
"content": f"{result}",
361+
"content": f"{response_content}",
353362
"source": self._agent_name,
354363
"step_id": action_request.step_id,
355364
},
@@ -360,7 +369,7 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:
360369
step_id=step.id,
361370
plan_id=step.plan_id,
362371
session_id=action_request.session_id,
363-
result=result,
372+
result=response_content,
364373
status=StepStatus.completed,
365374
)
366375

src/backend/kernel_agents/planner_agent.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ async def async_init(self) -> None:
126126
instructions=instructions, # Pass the formatted string, not an object
127127
temperature=0.0,
128128
response_format=ResponseFormatJsonSchemaType(
129-
json_schema=ResponseFormatJsonSchema(
130-
name=PlannerResponsePlan.__name__,
131-
description=f"respond with {PlannerResponsePlan.__name__.lower()}",
132-
schema=PlannerResponsePlan.model_json_schema(),
133-
)
134-
),
129+
json_schema=ResponseFormatJsonSchema(
130+
name=PlannerResponsePlan.__name__,
131+
description=f"respond with {PlannerResponsePlan.__name__.lower()}",
132+
schema=PlannerResponsePlan.model_json_schema(),
133+
)
134+
),
135135
)
136136
logging.info("Successfully created Azure AI Agent for PlannerAgent")
137137
return True
@@ -316,7 +316,6 @@ async def _create_structured_plan(
316316
logging.info(f"Kernel arguments: {kernel_args}")
317317

318318
# Get the schema for our expected response format
319-
320319

321320
# Ensure we're using the right pattern for Azure AI agents with semantic kernel
322321
# Properly handle async generation
@@ -336,9 +335,7 @@ async def _create_structured_plan(
336335
if chunk is not None:
337336
response_content += str(chunk)
338337

339-
logging.info(f"\n\n\n\n")
340338
logging.info(f"Response content length: {len(response_content)}")
341-
logging.info(f"\n\n\n\n")
342339

343340
# Check if response is empty or whitespace
344341
if not response_content or response_content.isspace():

0 commit comments

Comments
 (0)