Skip to content

Commit 67c7b0a

Browse files
committed
fix how to create planner agent
1 parent c8a0fb8 commit 67c7b0a

File tree

4 files changed

+31
-35
lines changed

4 files changed

+31
-35
lines changed

src/backend/app_kernel.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
# Local imports
2121
from middleware.health_check import HealthCheckMiddleware
2222
from auth.auth_utils import get_authenticated_user_details
23-
# Replace Config with our new AppConfig
24-
from app_config import config
23+
from config_kernel import Config
2524
from context.cosmos_memory_kernel import CosmosMemoryContext
2625
from models.messages_kernel import (
2726
HumanFeedback,
@@ -66,8 +65,7 @@
6665
# Initialize the FastAPI app
6766
app = FastAPI()
6867

69-
# Use the frontend URL from our AppConfig instance
70-
frontend_url = config.FRONTEND_SITE_NAME
68+
frontend_url = Config.FRONTEND_SITE_NAME
7169

7270
# Add this near the top of your app.py, after initializing the app
7371
app.add_middleware(

src/backend/kernel_agents/agent_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def get_tools_from_config(cls, kernel: sk.Kernel, agent_type: str, config_path:
301301
# Register the function with the kernel
302302
kernel.add_function(plugin_name, kernel_func)
303303
kernel_functions.append(kernel_func)
304-
logging.info(f"Successfully created dynamic tool '{function_name}' for {agent_type}")
304+
#logging.info(f"Successfully created dynamic tool '{function_name}' for {agent_type}")
305305
except Exception as e:
306306
logging.error(f"Failed to create tool '{tool.get('name', 'unknown')}': {str(e)}")
307307

src/backend/kernel_agents/agent_factory.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from semantic_kernel import Kernel
77
from semantic_kernel.functions import KernelFunction
88
from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent
9+
import inspect
910

1011
from models.agent_types import AgentType
1112
from kernel_agents.agent_base import BaseAgent
@@ -17,7 +18,6 @@
1718
from kernel_agents.human_agent import HumanAgent
1819
from kernel_agents.marketing_agent import MarketingAgent
1920
from kernel_agents.generic_agent import GenericAgent
20-
from kernel_agents.planner_agent import PlannerAgent
2121
from kernel_agents.tech_support_agent import TechSupportAgent
2222
from kernel_agents.procurement_agent import ProcurementAgent
2323
from kernel_agents.product_agent import ProductAgent
@@ -41,7 +41,6 @@ class AgentFactory:
4141
AgentType.TECH_SUPPORT: TechSupportAgent,
4242
AgentType.GENERIC: GenericAgent,
4343
AgentType.HUMAN: HumanAgent,
44-
AgentType.PLANNER: PlannerAgent,
4544
AgentType.GROUP_CHAT_MANAGER: GroupChatManager,
4645
}
4746

@@ -54,7 +53,6 @@ class AgentFactory:
5453
AgentType.TECH_SUPPORT: "tech_support",
5554
AgentType.GENERIC: "generic",
5655
AgentType.HUMAN: "human",
57-
AgentType.PLANNER: "planner",
5856
AgentType.GROUP_CHAT_MANAGER: "group_chat_manager",
5957
}
6058

@@ -67,7 +65,6 @@ class AgentFactory:
6765
AgentType.TECH_SUPPORT: "You are a technical support expert helping with technical issues.",
6866
AgentType.GENERIC: "You are a helpful assistant ready to help with various tasks.",
6967
AgentType.HUMAN: "You are representing a human user in the conversation.",
70-
AgentType.PLANNER: "You are a planner agent responsible for creating and managing plans.",
7168
AgentType.GROUP_CHAT_MANAGER: "You are a group chat manager coordinating the conversation between different agents.",
7269
}
7370

@@ -128,7 +125,7 @@ async def create_agent(
128125
# Check if we already have an agent in the cache
129126
if session_id in cls._agent_cache and agent_type in cls._agent_cache[session_id]:
130127
return cls._agent_cache[session_id][agent_type]
131-
128+
132129
# Get the agent class
133130
agent_class = cls._agent_classes.get(agent_type)
134131
if not agent_class:
@@ -177,27 +174,31 @@ async def create_agent(
177174

178175
# Create the agent instance using the project-based pattern
179176
try:
180-
agent = agent_class(
181-
agent_name=agent_type_str,
182-
kernel=kernel,
183-
session_id=session_id,
184-
user_id=user_id,
185-
memory_store=memory_store,
186-
tools=tools,
187-
system_message=system_message,
188-
client=client,
189-
definition=definition,
177+
# Filter kwargs to only those accepted by the agent's __init__
178+
agent_init_params = inspect.signature(agent_class.__init__).parameters
179+
valid_keys = set(agent_init_params.keys()) - {"self"}
180+
filtered_kwargs = {k: v for k, v in {
181+
"agent_name": agent_type_str,
182+
"kernel": kernel,
183+
"session_id": session_id,
184+
"user_id": user_id,
185+
"memory_store": memory_store,
186+
"tools": tools,
187+
"system_message": system_message,
188+
"client": client,
189+
"definition": definition,
190190
**kwargs
191-
)
191+
}.items() if k in valid_keys}
192+
agent = agent_class(**filtered_kwargs)
192193
logger.debug(f"[DEBUG] Agent object after instantiation: {agent}")
193-
# Initialize the agent asynchronously
194-
init_result = await agent.async_init()
195-
logger.debug(f"[DEBUG] Result of agent.async_init(): {init_result}")
194+
# Initialize the agent asynchronously if it has async_init
195+
if hasattr(agent, 'async_init') and inspect.iscoroutinefunction(agent.async_init):
196+
init_result = await agent.async_init()
197+
logger.debug(f"[DEBUG] Result of agent.async_init(): {init_result}")
196198
# Register tools with Azure AI Agent for LLM function calls
197-
if hasattr(agent._agent, 'add_function') and tools:
199+
if hasattr(agent, '_agent') and hasattr(agent._agent, 'add_function') and tools:
198200
for fn in tools:
199201
agent._agent.add_function(fn)
200-
201202
except Exception as e:
202203
logger.error(
203204
f"Error creating agent of type {agent_type} with parameters: {e}"

src/backend/kernel_agents/planner_agent.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def __init__(
4646
session_id: str,
4747
user_id: str,
4848
memory_store: CosmosMemoryContext,
49-
config_path: Optional[str] = None,
5049
available_agents: List[str] = None,
5150
agent_tools_list: List[str] = None
5251
) -> None:
@@ -73,17 +72,15 @@ def __init__(
7372
"TechSupportAgent", "GenericAgent"]
7473
self._agent_tools_list = agent_tools_list or []
7574

76-
# Load configuration
77-
config = BaseAgent.load_tools_config("planner", config_path)
78-
self._system_message = config.get(
79-
"system_message",
80-
"You are a Planner agent responsible for creating and managing plans. You analyze tasks, break them down into steps, and assign them to the appropriate specialized agents."
81-
)
75+
76+
self._system_message = "You are a Planner agent responsible for creating and managing plans. You analyze tasks, break them down into steps, and assign them to the appropriate specialized agents."
77+
8278

8379
# Create the agent
84-
self._agent = kernel.create_semantic_function(
80+
self._agent = KernelFunction.from_prompt(
8581
function_name="PlannerFunction",
86-
prompt=self._system_message,
82+
plugin_name="planner_plugin",
83+
prompt_template=self._system_message,
8784
description="Creates and manages execution plans"
8885
)
8986

0 commit comments

Comments
 (0)