2025-03-29 19:13:56 +08:00
|
|
|
from src.agents.chatbot import ChatbotAgent
|
|
|
|
|
from src.agents.react import ReActAgent
|
2025-03-24 19:07:51 +08:00
|
|
|
|
|
|
|
|
class AgentManager:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.agents = {}
|
2025-05-15 22:34:32 +08:00
|
|
|
self.agent_instances = {} # 存储已创建的 agent 实例
|
2025-03-24 19:07:51 +08:00
|
|
|
|
2025-03-29 17:33:09 +08:00
|
|
|
def add_agent(self, agent_id, agent_class):
|
|
|
|
|
self.agents[agent_id] = agent_class
|
2025-03-24 23:00:14 +08:00
|
|
|
|
2025-03-25 05:40:07 +08:00
|
|
|
def get_runnable_agent(self, agent_id, **kwargs):
|
2025-05-15 22:34:32 +08:00
|
|
|
# 检查是否已经创建了该 agent 的实例
|
|
|
|
|
if agent_id not in self.agent_instances:
|
|
|
|
|
agent_class = self.get_agent(agent_id)
|
|
|
|
|
self.agent_instances[agent_id] = agent_class()
|
|
|
|
|
return self.agent_instances[agent_id]
|
2025-03-25 05:40:07 +08:00
|
|
|
|
|
|
|
|
def get_agent(self, agent_id):
|
2025-03-29 17:33:09 +08:00
|
|
|
return self.agents[agent_id]
|
2025-03-25 05:40:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
agent_manager = AgentManager()
|
2025-03-29 17:33:09 +08:00
|
|
|
agent_manager.add_agent("chatbot", ChatbotAgent)
|
2025-05-15 23:17:22 +08:00
|
|
|
# agent_manager.add_agent("react", ReActAgent) # 暂时屏蔽 ReActAgent
|
2025-03-25 05:40:07 +08:00
|
|
|
|
|
|
|
|
__all__ = ["agent_manager"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
agent = agent_manager.get_agent("chatbot")
|
|
|
|
|
conf = agent_manager.get_configuration("chatbot")
|
|
|
|
|
agent_info = {
|
|
|
|
|
"name": agent.name,
|
|
|
|
|
"description": agent.description,
|
|
|
|
|
}
|
|
|
|
|
print(agent_info)
|