Skip to content

Commit 27487a2

Browse files
committed
simple kernel functions
1 parent 9e46c46 commit 27487a2

15 files changed

+619
-4
lines changed

src/backend/kernel_agents/generic_agent.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,15 @@ def __init__(
4444
if tools is None:
4545
# Get tools directly from GenericTools class
4646
tools_dict = GenericTools.get_all_kernel_functions()
47+
logging.info(
48+
f"GenericAgent: Got tools_dict with {len(tools_dict)} functions: {list(tools_dict.keys())}"
49+
)
50+
4751
tools = [KernelFunction.from_method(func) for func in tools_dict.values()]
48-
52+
logging.info(
53+
f"GenericAgent: Created {len(tools)} KernelFunctions from tools_dict"
54+
)
55+
4956
# Load the generic tools configuration for system message
5057
config = self.load_tools_config("generic", config_path)
5158

@@ -74,8 +81,12 @@ def __init__(
7481
definition=definition,
7582
)
7683

84+
@property
85+
def plugins(self):
86+
"""Get the plugins for the generic agent."""
87+
return GenericTools.get_all_kernel_functions()
88+
7789
# Explicitly inherit handle_action_request from the parent class
78-
# This is not technically necessary but makes the inheritance explicit
7990
async def handle_action_request(self, action_request_json: str) -> str:
8091
"""Handle an action request from another agent or the system.
8192

src/backend/kernel_agents/hr_agent.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ def __init__(
7373
client=client,
7474
definition=definition,
7575
)
76+
77+
@property
78+
def plugins(self):
79+
"""Get the plugins for the HR agent."""
80+
return HrTools.get_all_kernel_functions()

src/backend/kernel_agents/human_agent.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def __init__(
8787
definition=definition,
8888
)
8989

90+
@property
91+
def plugins(self):
92+
"""Get the plugins for the human agent."""
93+
return HumanTools.get_all_kernel_functions()
94+
9095
async def handle_human_feedback(self, human_feedback: HumanFeedback) -> str:
9196
"""Handle human feedback on a step.
9297

src/backend/kernel_agents/marketing_agent.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ def __init__(
7272
client=client,
7373
definition=definition,
7474
)
75+
76+
@property
77+
def plugins(self):
78+
"""Get the plugins for the marketing agent."""
79+
return MarketingTools.get_all_kernel_functions()

src/backend/kernel_agents/planner_agent.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ async def _create_structured_plan(
527527
session_id=input_task.session_id,
528528
user_id=self._user_id,
529529
action="Analyze the task: " + input_task.description,
530-
agent="GenericAgent",
530+
agent=AgentType.GENERIC.value, # Using the correct value from AgentType enum
531531
status=StepStatus.planned,
532532
human_approval_status=HumanFeedbackStatus.requested,
533533
timestamp=datetime.datetime.utcnow().isoformat(),
@@ -692,8 +692,48 @@ def _generate_args(self, objective: str) -> any:
692692
if hasattr(self, "_agent_instances") and self._agent_instances:
693693
# Process each agent to get their tools
694694
for agent_name, agent in self._agent_instances.items():
695+
# First try to get tools directly from the agent's corresponding tool class
696+
tools_dict = None
697+
698+
# Try to access plugins property which returns the get_all_kernel_functions result
699+
if hasattr(agent, "plugins"):
700+
try:
701+
# Access plugins as a property, not a method
702+
tools_dict = agent.plugins
703+
logging.info(f"Got tools dictionary from {agent_name}'s plugins property")
704+
705+
# Check if tools_dict is a list or a dictionary
706+
if isinstance(tools_dict, list):
707+
# Convert list to dictionary if needed
708+
tools_dict_converted = {}
709+
for i, func in enumerate(tools_dict):
710+
func_name = getattr(func, "__name__", f"function_{i}")
711+
tools_dict_converted[func_name] = func
712+
tools_dict = tools_dict_converted
713+
logging.info(f"Converted tools list to dictionary for {agent_name}")
714+
715+
except Exception as e:
716+
logging.warning(f"Error accessing plugins property for {agent_name}: {e}")
717+
718+
# Process tools from tools_dict if available
719+
if tools_dict:
720+
for func_name, func in tools_dict.items():
721+
# Check if the function has necessary attributes
722+
if hasattr(func, "__name__") and hasattr(func, "__doc__"):
723+
description = func.__doc__ or f"Function {func_name}"
724+
725+
# Create tool entry
726+
tool_entry = {
727+
"agent": agent_name,
728+
"function": func_name,
729+
"description": description,
730+
"arguments": "{}", # Default empty dict
731+
}
732+
733+
tools_list.append(tool_entry)
695734

696-
if hasattr(agent, "_tools") and agent._tools:
735+
# Fall back to the previous approach if no tools_dict found
736+
elif hasattr(agent, "_tools") and agent._tools:
697737
# Add each tool from this agent
698738
for tool in agent._tools:
699739
if hasattr(tool, "name") and hasattr(tool, "description"):

src/backend/kernel_agents/procurement_agent.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ def __init__(
7272
client=client,
7373
definition=definition,
7474
)
75+
76+
@property
77+
def plugins(self):
78+
"""Get the plugins for the procurement agent."""
79+
return ProcurementTools.get_all_kernel_functions()

src/backend/kernel_agents/tech_support_agent.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ def __init__(
7272
client=client,
7373
definition=definition,
7474
)
75+
76+
@property
77+
def plugins(self):
78+
"""Get the plugins for the tech support agent."""
79+
return TechSupportTools.get_all_kernel_functions()

src/backend/kernel_tools/generic_tools.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
import time
3+
import logging
34
from datetime import datetime
45
from typing import Annotated, Callable, List
56

@@ -46,4 +47,8 @@ def get_all_kernel_functions() -> dict[str, Callable]:
4647
):
4748
kernel_functions[name] = method
4849

50+
logging.info(
51+
f"GenericTools.get_all_kernel_functions found {len(kernel_functions)} functions: {list(kernel_functions.keys())}"
52+
)
53+
4954
return kernel_functions
File renamed without changes.

0 commit comments

Comments
 (0)