From 230f977719ba9ffb53d50e4ab0e0350054268df2 Mon Sep 17 00:00:00 2001 From: Francia Riesco Date: Sun, 27 Apr 2025 17:01:01 -0400 Subject: [PATCH 1/2] Update group_chat_manager.py --- src/backend/kernel_agents/group_chat_manager.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/kernel_agents/group_chat_manager.py b/src/backend/kernel_agents/group_chat_manager.py index 39e65142b..ca1a9119d 100644 --- a/src/backend/kernel_agents/group_chat_manager.py +++ b/src/backend/kernel_agents/group_chat_manager.py @@ -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 From e6f9a471e82120ea4e97d85fd1aef4be82e9ae50 Mon Sep 17 00:00:00 2001 From: Francia Riesco Date: Mon, 28 Apr 2025 17:51:55 -0400 Subject: [PATCH 2/2] agent invoke parameter no working --- src/backend/kernel_agents/agent_base.py | 80 +------------------ .../kernel_agents/group_chat_manager.py | 12 +-- 2 files changed, 8 insertions(+), 84 deletions(-) diff --git a/src/backend/kernel_agents/agent_base.py b/src/backend/kernel_agents/agent_base.py index 4547c4eb7..0354882b9 100644 --- a/src/backend/kernel_agents/agent_base.py +++ b/src/backend/kernel_agents/agent_base.py @@ -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 @@ -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. @@ -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 = "" diff --git a/src/backend/kernel_agents/group_chat_manager.py b/src/backend/kernel_agents/group_chat_manager.py index ca1a9119d..4394047d7 100644 --- a/src/backend/kernel_agents/group_chat_manager.py +++ b/src/backend/kernel_agents/group_chat_manager.py @@ -247,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, @@ -272,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, @@ -290,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, @@ -317,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 += "" @@ -353,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, }, )