Files
sentclaw/backend/app/services/tool.py
T
2026-04-07 16:05:05 +08:00

36 lines
1.0 KiB
Python

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()