Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 2 additions & 78 deletions src/backend/kernel_agents/agent_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,51 +138,6 @@ async def async_init(self):
# Tools are registered with the kernel via get_tools_from_config
return self

async def invoke_async(self, *args, **kwargs):
"""Invoke this agent asynchronously.

This method is required for compatibility with AgentGroupChat.

Args:
*args: Positional arguments
**kwargs: Keyword arguments

Returns:
The agent's response
"""
# Ensure agent is initialized
if self._agent is None:
await self.async_init()

# Get the text input from args or kwargs
text = None
if args and isinstance(args[0], str):
text = args[0]
elif "text" in kwargs:
text = kwargs["text"]
elif "arguments" in kwargs and hasattr(kwargs["arguments"], "get"):
text = kwargs["arguments"].get("text") or kwargs["arguments"].get("input")

if not text:
settings = kwargs.get("settings", {})
if isinstance(settings, dict) and "input" in settings:
text = settings["input"]

# If text is still not found, create a default message
if not text:
text = "Hello, please assist with a task."

# Use the text to invoke the agent
try:
logging.info(f"Invoking {self._agent_name} with text: {text[:100]}...")
response = await self._agent.invoke(
self._kernel, text, settings=kwargs.get("settings", {})
)
return response
except Exception as e:
logging.error(f"Error invoking {self._agent_name}: {e}")
return f"Error: {str(e)}"

def _register_functions(self):
"""Register this agent's functions with the kernel."""
# Use the kernel function decorator approach instead of from_native_method
Expand All @@ -204,37 +159,6 @@ async def handle_action_request_wrapper(*args, **kwargs):
self._kernel.add_function(self._agent_name, kernel_func)

# Required method for AgentGroupChat compatibility
async def send_message_async(
self, message_content: ChatMessageContent, chat_history: ChatHistory
):
"""Send a message to the agent asynchronously, adding it to chat history.

Args:
message_content: The content of the message
chat_history: The chat history

Returns:
None
"""
# Convert message to format expected by the agent
if hasattr(message_content, "role") and hasattr(message_content, "content"):
self._chat_history.append(
{"role": message_content.role, "content": message_content.content}
)

# If chat history is provided, update our internal history
if chat_history and hasattr(chat_history, "messages"):
# Update with the latest messages from chat history
for msg in chat_history.messages[
-5:
]: # Only use last 5 messages to avoid history getting too long
if msg not in self._chat_history:
self._chat_history.append(
{"role": msg.role, "content": msg.content}
)

# No need to return anything as we're just updating state
return None

async def handle_action_request(self, action_request: ActionRequest) -> str:
"""Handle an action request from another agent or the system.
Expand Down Expand Up @@ -274,11 +198,11 @@ async def handle_action_request(self, action_request: ActionRequest) -> str:

try:
# Use the agent to process the action
chat_history = self._chat_history.copy()
# chat_history = self._chat_history.copy()

# Call the agent to handle the action
async_generator = self._agent.invoke(
self._kernel, f"{action_request.action}\n\nPlease perform this action"
f"{action_request.action}\n\nPlease perform this action"
)

response_content = ""
Expand Down
13 changes: 6 additions & 7 deletions src/backend/kernel_agents/group_chat_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Dict, List, Optional, Any, Tuple

import semantic_kernel as sk
from semantic_kernel.functions.kernel_arguments import KernelArguments
from semantic_kernel.functions.kernel_function import KernelFunction
from semantic_kernel.agents import AgentGroupChat # pylint: disable=E0611

Expand Down Expand Up @@ -248,7 +247,7 @@ class Step(BaseDataModel):
step.human_approval_status = HumanFeedbackStatus.rejected
self._memory_store.update_step(step)
track_event_if_configured(
"Group Chat Manager - Step has been rejected and updated into the cosmos",
f"{AgentType.GROUP_CHAT_MANAGER.value} - Step has been rejected and updated into the cosmos",
{
"status": StepStatus.rejected,
"session_id": message.session_id,
Expand All @@ -273,7 +272,7 @@ async def _update_step_status(
step.status = StepStatus.completed
await self._memory_store.update_step(step)
track_event_if_configured(
"Group Chat Manager - Received human feedback, Updating step and updated into the cosmos",
f"{AgentType.GROUP_CHAT_MANAGER.value} - Received human feedback, Updating step and updated into the cosmos",
{
"status": StepStatus.completed,
"session_id": step.session_id,
Expand All @@ -291,7 +290,7 @@ async def _execute_step(self, session_id: str, step: Step):
step.status = StepStatus.action_requested
await self._memory_store.update_step(step)
track_event_if_configured(
"Group Chat Manager - Update step to action_requested and updated into the cosmos",
f"{AgentType.GROUP_CHAT_MANAGER.value} - Update step to action_requested and updated into the cosmos",
{
"status": StepStatus.action_requested,
"session_id": step.session_id,
Expand All @@ -318,7 +317,7 @@ async def _execute_step(self, session_id: str, step: Step):
if step.id == current_step_id:
break
formatted_string += f"Step {i}\n"
formatted_string += f"Group chat manager: {step.action}\n"
formatted_string += f"{AgentType.GROUP_CHAT_MANAGER.value}: {step.action}\n"
formatted_string += f"{step.agent.name}: {step.agent_reply}\n"
formatted_string += "<conversation_history \\>"

Expand Down Expand Up @@ -354,13 +353,13 @@ async def _execute_step(self, session_id: str, step: Step):
)

track_event_if_configured(
f"Group Chat Manager - Requesting {formatted_agent} to perform the action and added into the cosmos",
f"{AgentType.GROUP_CHAT_MANAGER.value} - Requesting {formatted_agent} to perform the action and added into the cosmos",
{
"session_id": session_id,
"user_id": self._user_id,
"plan_id": step.plan_id,
"content": f"Requesting {formatted_agent} to perform action: {step.action}",
"source": "GroupChatManager",
"source": AgentType.GROUP_CHAT_MANAGER.value,
"step_id": step.id,
},
)
Expand Down
Loading