first commit

This commit is contained in:
2026-04-07 16:05:05 +08:00
commit 9d9bdbb1ce
136 changed files with 5103 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
from ..models import Tool, AgentTool
class ToolService:
@staticmethod
def create_tool(data):
if Tool.query.filter_by(name=data["name"]).first():
raise ValueError("工具名称已存在")
tool = Tool(
name=data["name"],
type=data["type"],
description=data.get("description"),
config=data.get("config"),
)
tool.save()
return tool
@staticmethod
def add_tool_to_agent(agent_id, tool_id):
if AgentTool.query.filter_by(agent_id=agent_id, tool_id=tool_id).first():
raise ValueError("工具已添加到此 Agent")
agent_tool = AgentTool(agent_id=agent_id, tool_id=tool_id)
agent_tool.save()
return agent_tool
@staticmethod
def remove_tool_from_agent(agent_id, tool_id):
agent_tool = AgentTool.query.filter_by(
agent_id=agent_id, tool_id=tool_id
).first()
if not agent_tool:
raise ValueError("工具关联不存在")
agent_tool.delete()