|
@@ -0,0 +1,24 @@
|
|
|
+import json
|
|
|
+
|
|
|
+from pqai_agent.agents.simple_chat_agent import SimpleOpenAICompatibleChatAgent
|
|
|
+from pqai_agent.data_models.agent_configuration import AgentConfiguration
|
|
|
+from pqai_agent.toolkit import get_tools
|
|
|
+from pqai_agent.toolkit.sub_agent_toolkit import SubAgentToolkit
|
|
|
+
|
|
|
+
|
|
|
+def create_agent_from_config(agent_config: AgentConfiguration, session_maker) -> SimpleOpenAICompatibleChatAgent:
|
|
|
+ tools = get_tools(json.loads(agent_config.tools))
|
|
|
+ sub_agent_ids = json.loads(agent_config.sub_agents)
|
|
|
+ if sub_agent_ids:
|
|
|
+ # 查询子Agent配置
|
|
|
+ with session_maker() as session:
|
|
|
+ sub_agent_configs = session.query(AgentConfiguration).filter(
|
|
|
+ AgentConfiguration.id.in_(sub_agent_ids)).all()
|
|
|
+ # 将子Agent配置转换为工具
|
|
|
+ for sub_agent_config in sub_agent_configs:
|
|
|
+ sub_agent_tool = SubAgentToolkit.create_tool_from_agent(sub_agent_config)
|
|
|
+ tools.append(sub_agent_tool)
|
|
|
+ chat_agent = SimpleOpenAICompatibleChatAgent(model=agent_config.execution_model,
|
|
|
+ system_prompt=agent_config.system_prompt,
|
|
|
+ tools=tools)
|
|
|
+ return chat_agent
|