Skip to content

Commit ce6b819

Browse files
authored
Merge pull request #156 from Fr4nc3/main
feat: pass variables values
2 parents 78fe2c2 + fe8fe5b commit ce6b819

File tree

12 files changed

+706
-407
lines changed

12 files changed

+706
-407
lines changed

src/backend/app_config.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ async def create_azure_ai_agent(
194194
agent_name: str,
195195
instructions: str,
196196
tools: Optional[List[KernelFunction]] = None,
197+
client=None,
197198
response_format=None,
198199
temperature: float = 0.0,
199200
):
@@ -216,15 +217,16 @@ async def create_azure_ai_agent(
216217
"""
217218
try:
218219
# Get the AIProjectClient
219-
project_client = self.get_ai_project_client()
220+
if client is None:
221+
client = self.get_ai_project_client()
220222

221223
# First try to get an existing agent with this name as assistant_id
222224
try:
223225

224-
existing_definition = await project_client.agents.get_agent(agent_name)
226+
existing_definition = await client.agents.get_agent(agent_name)
225227
# Create the agent instance directly with project_client and existing definition
226228
agent = AzureAIAgent(
227-
client=project_client,
229+
client=client,
228230
definition=existing_definition,
229231
plugins=tools,
230232
)
@@ -244,7 +246,7 @@ async def create_azure_ai_agent(
244246
)
245247

246248
# Create the agent using the project client with the agent_name as both name and assistantId
247-
agent_definition = await project_client.agents.create_agent(
249+
agent_definition = await client.agents.create_agent(
248250
model=self.AZURE_OPENAI_DEPLOYMENT_NAME,
249251
name=agent_name,
250252
instructions=instructions,
@@ -254,7 +256,7 @@ async def create_azure_ai_agent(
254256

255257
# Create the agent instance directly with project_client and definition
256258
agent = AzureAIAgent(
257-
client=project_client,
259+
client=client,
258260
definition=agent_definition,
259261
plugins=tools,
260262
)

src/backend/kernel_agents/agent_factory.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ async def create_agent(
9393
memory_store: Optional[CosmosMemoryContext] = None,
9494
system_message: Optional[str] = None,
9595
response_format: Optional[Any] = None,
96+
client: Optional[Any] = None,
9697
**kwargs,
9798
) -> BaseAgent:
9899
"""Create an agent of the specified type.
@@ -160,7 +161,10 @@ async def create_agent(
160161
client = None
161162

162163
try:
163-
client = config.get_ai_project_client()
164+
if client is None:
165+
# Create the AIProjectClient instance using the config
166+
# This is a placeholder; replace with actual client creation logic
167+
client = config.get_ai_project_client()
164168
except Exception as client_exc:
165169
logger.error(f"Error creating AIProjectClient: {client_exc}")
166170
raise

src/backend/kernel_agents/group_chat_manager.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ def __init__(
5454
"""Initialize the GroupChatManager Agent.
5555
5656
Args:
57-
kernel: The semantic kernel instance
5857
session_id: The current session identifier
5958
user_id: The user identifier
6059
memory_store: The Cosmos memory context
61-
tools: Optional list of tools for this agent
6260
system_message: Optional system message for the agent
6361
agent_name: Optional name for the agent (defaults to "GroupChatManagerAgent")
6462
config_path: Optional path to the configuration file

src/backend/kernel_agents/human_agent.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from context.cosmos_memory_kernel import CosmosMemoryContext
66
from event_utils import track_event_if_configured
77
from kernel_agents.agent_base import BaseAgent
8-
from kernel_tools.human_tools import HumanTools
98
from models.messages_kernel import (
109
ActionRequest,
1110
AgentMessage,
@@ -40,7 +39,6 @@ def __init__(
4039
"""Initialize the Human Agent.
4140
4241
Args:
43-
kernel: The semantic kernel instance
4442
session_id: The current session identifier
4543
user_id: The user identifier
4644
memory_store: The Cosmos memory context
@@ -51,15 +49,10 @@ def __init__(
5149
client: Optional client instance
5250
definition: Optional definition instance
5351
"""
54-
# Load configuration if tools not provided
55-
if not tools:
56-
# Get tools directly from HumanTools class
57-
tools_dict = HumanTools.get_all_kernel_functions()
58-
tools = [KernelFunction.from_method(func) for func in tools_dict.values()]
5952

60-
# Use system message from config if not explicitly provided
61-
if not system_message:
62-
system_message = self.default_system_message(agent_name)
53+
# Use system message from config if not explicitly provided
54+
if not system_message:
55+
system_message = self.default_system_message(agent_name)
6356

6457
# Use agent name from config if available
6558
agent_name = AgentType.HUMAN.value
@@ -75,11 +68,6 @@ def __init__(
7568
definition=definition,
7669
)
7770

78-
@property
79-
def plugins(self):
80-
"""Get the plugins for the human agent."""
81-
return HumanTools.get_all_kernel_functions()
82-
8371
@staticmethod
8472
def default_system_message(agent_name=None) -> str:
8573
"""Get the default system message for the agent.

src/backend/kernel_agents/planner_agent.py

Lines changed: 18 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
)
3333
from event_utils import track_event_if_configured
3434
from app_config import config
35+
from kernel_tools.hr_tools import HrTools
36+
from kernel_tools.generic_tools import GenericTools
37+
from kernel_tools.marketing_tools import MarketingTools
38+
from kernel_tools.procurement_tools import ProcurementTools
39+
from kernel_tools.product_tools import ProductTools
40+
from kernel_tools.tech_support_tools import TechSupportTools
3541

3642

3743
class PlannerAgent(BaseAgent):
@@ -50,7 +56,6 @@ def __init__(
5056
system_message: Optional[str] = None,
5157
agent_name: str = AgentType.PLANNER.value,
5258
available_agents: List[str] = None,
53-
agent_tools_list: List[str] = None,
5459
agent_instances: Optional[Dict[str, BaseAgent]] = None,
5560
client=None,
5661
definition=None,
@@ -97,7 +102,15 @@ def __init__(
97102
AgentType.TECH_SUPPORT.value,
98103
AgentType.GENERIC.value,
99104
]
100-
self._agent_tools_list = agent_tools_list or []
105+
self._agent_tools_list = {
106+
AgentType.HR: HrTools.generate_tools_json_doc(),
107+
AgentType.MARKETING: MarketingTools.generate_tools_json_doc(),
108+
AgentType.PRODUCT: ProductTools.generate_tools_json_doc(),
109+
AgentType.PROCUREMENT: ProcurementTools.generate_tools_json_doc(),
110+
AgentType.TECH_SUPPORT: TechSupportTools.generate_tools_json_doc(),
111+
AgentType.GENERIC: GenericTools.generate_tools_json_doc(),
112+
}
113+
101114
self._agent_instances = agent_instances or {}
102115

103116
@staticmethod
@@ -311,8 +324,6 @@ async def _create_structured_plan(
311324
kernel_args = KernelArguments(**args)
312325
# kernel_args["input"] = f"TASK: {input_task.description}\n\n{instruction}"
313326

314-
logging.info(f"Kernel arguments: {kernel_args}")
315-
316327
# Get the schema for our expected response format
317328

318329
# Ensure we're using the right pattern for Azure AI agents with semantic kernel
@@ -522,177 +533,9 @@ def _generate_args(self, objective: str) -> any:
522533
# Create list of available tools in JSON-like format
523534
tools_list = []
524535

525-
# Check if we have agent instances to extract tools from
526-
if hasattr(self, "_agent_instances") and self._agent_instances:
527-
# Process each agent to get their tools
528-
for agent_name, agent in self._agent_instances.items():
529-
# First try to get tools directly from the agent's corresponding tool class
530-
tools_dict = None
531-
532-
# Try to access plugins property which returns the get_all_kernel_functions result
533-
if hasattr(agent, "plugins"):
534-
try:
535-
# Access plugins as a property, not a method
536-
tools_dict = agent.plugins
537-
logging.info(
538-
f"Got tools dictionary from {agent_name}'s plugins property"
539-
)
540-
541-
# Check if tools_dict is a list or a dictionary
542-
if isinstance(tools_dict, list):
543-
# Convert list to dictionary if needed
544-
tools_dict_converted = {}
545-
for i, func in enumerate(tools_dict):
546-
func_name = getattr(func, "__name__", f"function_{i}")
547-
tools_dict_converted[func_name] = func
548-
tools_dict = tools_dict_converted
549-
logging.info(
550-
f"Converted tools list to dictionary for {agent_name}"
551-
)
552-
553-
except Exception as e:
554-
logging.warning(
555-
f"Error accessing plugins property for {agent_name}: {e}"
556-
)
557-
558-
# Process tools from tools_dict if available
559-
if tools_dict:
560-
for func_name, func in tools_dict.items():
561-
# Check if the function has necessary attributes
562-
if hasattr(func, "__name__") and hasattr(func, "__doc__"):
563-
description = func.__doc__ or f"Function {func_name}"
564-
565-
# Create tool entry
566-
tool_entry = {
567-
"agent": agent_name,
568-
"function": func_name,
569-
"description": description,
570-
"arguments": "{}", # Default empty dict
571-
}
572-
573-
tools_list.append(tool_entry)
574-
575-
# Fall back to the previous approach if no tools_dict found
576-
elif hasattr(agent, "_tools") and agent._tools:
577-
# Add each tool from this agent
578-
for tool in agent._tools:
579-
if hasattr(tool, "name") and hasattr(tool, "description"):
580-
# Extract function parameters/arguments
581-
args_dict = {}
582-
if hasattr(tool, "parameters"):
583-
# Check if we have kernel_arguments that need to be processed
584-
has_kernel_args = any(
585-
param.name == "kernel_arguments"
586-
for param in tool.parameters
587-
)
588-
has_kwargs = any(
589-
param.name == "kwargs" for param in tool.parameters
590-
)
591-
592-
# Process regular parameters first
593-
for param in tool.parameters:
594-
# Skip kernel_arguments and kwargs as we'll handle them specially
595-
if param.name in ["kernel_arguments", "kwargs"]:
596-
continue
597-
598-
param_type = "string" # Default type
599-
if hasattr(param, "type"):
600-
param_type = param.type
601-
602-
args_dict[param.name] = {
603-
"description": (
604-
param.description
605-
if param.description
606-
else param.name
607-
),
608-
"title": param.name.replace("_", " ").title(),
609-
"type": param_type,
610-
}
611-
612-
# If we have a kernel_arguments parameter, introspect it to extract its values
613-
# This is a special case handling for kernel_arguments to include its fields in the arguments
614-
if has_kernel_args:
615-
# Check if we have kernel_parameter_descriptions
616-
if hasattr(tool, "kernel_parameter_descriptions"):
617-
# Extract parameter descriptions from the kernel
618-
for (
619-
key,
620-
description,
621-
) in tool.kernel_parameter_descriptions.items():
622-
if (
623-
key not in args_dict
624-
): # Only add if not already added
625-
args_dict[key] = {
626-
"description": (
627-
description
628-
if description
629-
else key
630-
),
631-
"title": key.replace(
632-
"_", " "
633-
).title(),
634-
"type": "string", # Default to string type
635-
}
636-
# Fall back to function's description if no specific descriptions
637-
elif hasattr(tool, "description") and not args_dict:
638-
# Add a generic parameter with the function's description
639-
args_dict["input"] = {
640-
"description": f"Input for {tool.name}: {tool.description}",
641-
"title": "Input",
642-
"type": "string",
643-
}
644-
645-
# If after all processing, arguments are still empty, add a dummy input parameter
646-
if not args_dict:
647-
args_dict["input"] = {
648-
"description": f"Input for {tool.name}",
649-
"title": "Input",
650-
"type": "string",
651-
}
652-
653-
# Create tool entry
654-
tool_entry = {
655-
"agent": agent_name,
656-
"function": tool.name,
657-
"description": tool.description,
658-
"arguments": str(args_dict),
659-
}
660-
661-
tools_list.append(tool_entry)
662-
663-
logging.info(f"Generated {len(tools_list)} tools from agent instances")
664-
665-
# If we couldn't extract tools from agent instances, create a simplified format
666-
if not tools_list:
667-
logging.warning(
668-
"No tool details extracted from agent instances, creating simplified format"
669-
)
670-
if self._agent_tools_list:
671-
# Create dummy entries from the existing tool list strings
672-
for tool_str in self._agent_tools_list:
673-
if ":" in tool_str:
674-
parts = tool_str.split(":")
675-
if len(parts) >= 2:
676-
agent_part = parts[0].strip()
677-
function_part = parts[1].strip()
678-
679-
# Extract agent name if format is "Agent: AgentName"
680-
agent_name = agent_part.replace("Agent", "").strip()
681-
if not agent_name:
682-
agent_name = AgentType.GENERIC.value
683-
684-
tools_list.append(
685-
{
686-
"agent": agent_name,
687-
"function": function_part,
688-
"description": f"Function {function_part} from {agent_name}",
689-
"arguments": "{}",
690-
}
691-
)
692-
693-
# Convert the tools list to a string representation
694-
logging.info(f"Tools list: {len(tools_list)}")
695-
logging
536+
for agent_name, tools in self._agent_tools_list.items():
537+
if agent_name in self._available_agents:
538+
tools_list.append(tools)
696539

697540
tools_str = str(tools_list)
698541

0 commit comments

Comments
 (0)