-
Notifications
You must be signed in to change notification settings - Fork 711
Expand file tree
/
Copy pathproduct_agent.py
More file actions
96 lines (81 loc) · 3.67 KB
/
Copy pathproduct_agent.py
File metadata and controls
96 lines (81 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from typing import List, Optional
from context.cosmos_memory_kernel import CosmosMemoryContext
from kernel_agents.agent_base import BaseAgent
from kernel_tools.product_tools import ProductTools
from models.messages_kernel import AgentType
from semantic_kernel.functions import KernelFunction
class ProductAgent(BaseAgent):
"""Product agent implementation using Semantic Kernel.
This agent specializes in product management, development, and related tasks.
It can provide information about products, manage inventory, handle product
launches, analyze sales data, and coordinate with other teams like marketing
and tech support.
"""
def __init__(
self,
session_id: str,
user_id: str,
memory_store: CosmosMemoryContext,
tools: Optional[List[KernelFunction]] = None,
system_message: Optional[str] = None,
agent_name: str = AgentType.PRODUCT.value,
client=None,
definition=None,
) -> None:
"""Initialize the Product Agent.
Args:
kernel: The semantic kernel instance
session_id: The current session identifier
user_id: The user identifier
memory_store: The Cosmos memory context
tools: List of tools available to this agent (optional)
system_message: Optional system message for the agent
agent_name: Optional name for the agent (defaults to "ProductAgent")
config_path: Optional path to the Product tools configuration file
client: Optional client instance
definition: Optional definition instance
"""
# Load configuration if tools not provided
if not tools:
# Get tools directly from ProductTools class
tools_dict = ProductTools.get_all_kernel_functions()
tools = [KernelFunction.from_method(func) for func in tools_dict.values()]
# Use system message from config if not explicitly provided
if not system_message:
system_message = self.default_system_message(agent_name)
# Use agent name from config if available
agent_name = AgentType.PRODUCT.value
super().__init__(
agent_name=agent_name,
session_id=session_id,
user_id=user_id,
memory_store=memory_store,
tools=tools,
system_message=system_message,
client=client,
definition=definition,
)
@staticmethod
def default_system_message(agent_name=None) -> str:
"""Get the default system message for the agent.
Args:
agent_name: The name of the agent (optional)
Returns:
The default system message for the agent
"""
return "You are a Product agent. You have knowledge about product management, development, and compliance guidelines. When asked to call a function, you should summarize back what was done."
@property
def plugins(self):
"""Get the plugins for the product agent."""
return ProductTools.get_all_kernel_functions()
# Explicitly inherit handle_action_request from the parent class
# This is not technically necessary but makes the inheritance explicit
async def handle_action_request(self, action_request_json: str) -> str:
"""Handle an action request from another agent or the system.
This method is inherited from BaseAgent but explicitly included here for clarity.
Args:
action_request_json: The action request as a JSON string
Returns:
A JSON string containing the action response
"""
return await super().handle_action_request(action_request_json)