跳转到内容

Merge Agent Handler Tool

MergeAgentHandlerTool 让 CrewAI agents 能够通过 Merge’s Agent Handler 平台安全访问第三方集成。Agent Handler 提供了预构建的安全连接器,可连接 Linear、GitHub、Slack、Notion 等数百种工具,并内置认证、权限和监控。

Terminal window
uv pip install 'crewai[tools]'
  • 已配置 Tool Pack 的 Merge Agent Handler 账户
  • Agent Handler API key
  • 至少一个与 Tool Pack 关联的已注册用户
  • 在 Tool Pack 中配置好的第三方集成
  1. 注册 一个 Merge Agent Handler 账户,地址是 ah.merge.dev/signup
  2. 创建 Tool Pack 并配置你需要的集成
  3. 注册用户,让他们通过第三方服务完成认证
  4. 获取 API key,从 Agent Handler 仪表板中取得
  5. 设置环境变量export AGENT_HANDLER_API_KEY='your-key-here'
  6. 开始构建 使用 CrewAI 的 MergeAgentHandlerTool
  • Tool Pack IDs 和 Registered User IDs 可以在 Agent Handler 仪表板中找到,也可以通过 API 创建
  • 该工具使用 Model Context Protocol(MCP)与 Agent Handler 通信
  • Session IDs 会自动生成,但也可以自定义以保持上下文
  • 所有工具调用都会被记录并可审计,且通过 Agent Handler 平台完成
  • 工具参数会从 Agent Handler API 动态发现并自动校验

下面展示如何从 Tool Pack 中使用某个特定工具:

from crewai import Agent, Task, Crew
from crewai_tools import MergeAgentHandlerTool
# Create a tool for Linear issue creation
linear_create_tool = MergeAgentHandlerTool.from_tool_name(
tool_name="linear__create_issue",
tool_pack_id="134e0111-0f67-44f6-98f0-597000290bb3",
registered_user_id="91b2b905-e866-40c8-8be2-efe53827a0aa"
)
# Create a CrewAI agent that uses the tool
project_manager = Agent(
role='Project Manager',
goal='Manage project tasks and issues efficiently',
backstory='I am an expert at tracking project work and creating actionable tasks.',
tools=[linear_create_tool],
verbose=True
)
# Create a task for the agent
create_issue_task = Task(
description="Create a new high-priority issue in Linear titled 'Implement user authentication' with a detailed description of the requirements.",
agent=project_manager,
expected_output="Confirmation that the issue was created with its ID"
)
# Create a crew with the agent
crew = Crew(
agents=[project_manager],
tasks=[create_issue_task],
verbose=True
)
# Run the crew
result = crew.kickoff()
print(result)

你可以一次性加载 Tool Pack 中所有可用工具:

from crewai import Agent, Task, Crew
from crewai_tools import MergeAgentHandlerTool
# Load all tools from the Tool Pack
tools = MergeAgentHandlerTool.from_tool_pack(
tool_pack_id="134e0111-0f67-44f6-98f0-597000290bb3",
registered_user_id="91b2b905-e866-40c8-8be2-efe53827a0aa"
)
# Create an agent with access to all tools
automation_expert = Agent(
role='Automation Expert',
goal='Automate workflows across multiple platforms',
backstory='I can work with any tool in the toolbox to get things done.',
tools=tools,
verbose=True
)
automation_task = Task(
description="Check for any high-priority issues in Linear and post a summary to Slack.",
agent=automation_expert
)
crew = Crew(
agents=[automation_expert],
tasks=[automation_task],
verbose=True
)
result = crew.kickoff()

只加载你需要的工具:

from crewai import Agent, Task, Crew
from crewai_tools import MergeAgentHandlerTool
# Load specific tools from the Tool Pack
selected_tools = MergeAgentHandlerTool.from_tool_pack(
tool_pack_id="134e0111-0f67-44f6-98f0-597000290bb3",
registered_user_id="91b2b905-e866-40c8-8be2-efe53827a0aa",
tool_names=["linear__create_issue", "linear__get_issues", "slack__post_message"]
)
developer_assistant = Agent(
role='Developer Assistant',
goal='Help developers track and communicate about their work',
backstory='I help developers stay organized and keep the team informed.',
tools=selected_tools,
verbose=True
)
daily_update_task = Task(
description="Get all issues assigned to the current user in Linear and post a summary to the #dev-updates Slack channel.",
agent=developer_assistant
)
crew = Crew(
agents=[developer_assistant],
tasks=[daily_update_task],
verbose=True
)
result = crew.kickoff()
ArgumentTypeRequiredDefaultDescription
tool_namestrYesNone要使用的具体工具名称(例如 "linear__create_issue"
tool_pack_idstrYesNone你的 Agent Handler Tool Pack 的 UUID
registered_user_idstrYesNone已注册用户的 UUID 或 origin_id
base_urlstrNohttps://ah-api.merge.devAgent Handler API 的基础 URL
session_idstrNoAuto-generated用于保持上下文的 MCP session ID
ArgumentTypeRequiredDefaultDescription
tool_pack_idstrYesNone你的 Agent Handler Tool Pack 的 UUID
registered_user_idstrYesNone已注册用户的 UUID 或 origin_id
tool_nameslist[str]NoNone要加载的具体工具名称。如果为 None,则加载所有可用工具
base_urlstrNohttps://ah-api.merge.devAgent Handler API 的基础 URL
Terminal window
AGENT_HANDLER_API_KEY=your_api_key_here # Required for authentication

具有不同工具访问权限的多 Agent 工作流

Section titled “具有不同工具访问权限的多 Agent 工作流”
from crewai import Agent, Task, Crew, Process
from crewai_tools import MergeAgentHandlerTool
# Create specialized tools for different agents
github_tools = MergeAgentHandlerTool.from_tool_pack(
tool_pack_id="134e0111-0f67-44f6-98f0-597000290bb3",
registered_user_id="91b2b905-e866-40c8-8be2-efe53827a0aa",
tool_names=["github__create_pull_request", "github__get_pull_requests"]
)
linear_tools = MergeAgentHandlerTool.from_tool_pack(
tool_pack_id="134e0111-0f67-44f6-98f0-597000290bb3",
registered_user_id="91b2b905-e866-40c8-8be2-efe53827a0aa",
tool_names=["linear__create_issue", "linear__update_issue"]
)
slack_tool = MergeAgentHandlerTool.from_tool_name(
tool_name="slack__post_message",
tool_pack_id="134e0111-0f67-44f6-98f0-597000290bb3",
registered_user_id="91b2b905-e866-40c8-8be2-efe53827a0aa"
)
# Create specialized agents
code_reviewer = Agent(
role='Code Reviewer',
goal='Review pull requests and ensure code quality',
backstory='I am an expert at reviewing code changes and providing constructive feedback.',
tools=github_tools
)
task_manager = Agent(
role='Task Manager',
goal='Track and update project tasks based on code changes',
backstory='I keep the project board up to date with the latest development progress.',
tools=linear_tools
)
communicator = Agent(
role='Team Communicator',
goal='Keep the team informed about important updates',
backstory='I make sure everyone knows what is happening in the project.',
tools=[slack_tool]
)
# Create sequential tasks
review_task = Task(
description="Review all open pull requests in the 'api-service' repository and identify any that need attention.",
agent=code_reviewer,
expected_output="List of pull requests that need review or have issues"
)
update_task = Task(
description="Update Linear issues based on the pull request review findings. Mark completed PRs as done.",
agent=task_manager,
expected_output="Summary of updated Linear issues"
)
notify_task = Task(
description="Post a summary of today's code review and task updates to the #engineering Slack channel.",
agent=communicator,
expected_output="Confirmation that the message was posted"
)
# Create a crew with sequential processing
crew = Crew(
agents=[code_reviewer, task_manager, communicator],
tasks=[review_task, update_task, notify_task],
process=Process.sequential,
verbose=True
)
result = crew.kickoff()

使用 session IDs 在多次工具调用之间保留上下文:

from crewai import Agent, Task, Crew
from crewai_tools import MergeAgentHandlerTool
# Create tools with the same session ID to maintain context
session_id = "project-sprint-planning-2024"
create_tool = MergeAgentHandlerTool(
name="linear_create_issue",
description="Creates a new issue in Linear",
tool_name="linear__create_issue",
tool_pack_id="134e0111-0f67-44f6-98f0-597000290bb3",
registered_user_id="91b2b905-e866-40c8-8be2-efe53827a0aa",
session_id=session_id
)
update_tool = MergeAgentHandlerTool(
name="linear_update_issue",
description="Updates an existing issue in Linear",
tool_name="linear__update_issue",
tool_pack_id="134e0111-0f67-44f6-98f0-597000290bb3",
registered_user_id="91b2b905-e866-40c8-8be2-efe53827a0aa",
session_id=session_id
)
sprint_planner = Agent(
role='Sprint Planner',
goal='Plan and organize sprint tasks',
backstory='I help teams plan effective sprints with well-defined tasks.',
tools=[create_tool, update_tool],
verbose=True
)
planning_task = Task(
description="Create 5 sprint tasks for the authentication feature and set their priorities based on dependencies.",
agent=sprint_planner
)
crew = Crew(
agents=[sprint_planner],
tasks=[planning_task],
verbose=True
)
result = crew.kickoff()
  • 通过单一统一 API 访问数百种第三方工具,而无需管理多个 SDK
  • 让 agents 能通过一个集成入口使用 Linear、GitHub、Slack、Notion、Jira、Asana 等更多工具
  • 让 Agent Handler 负责认证和 API 版本管理,从而降低集成复杂度
  • 为所有第三方集成利用内置的认证和权限管理
  • 通过集中式访问控制和审计日志保持企业安全标准
  • 让 agents 可以访问公司工具,而无需在代码中暴露 API keys 或凭据
  • 构建跨多个平台的工作流(例如:从 Linear 任务创建 GitHub issues、将 Notion pages 同步到 Slack)
  • 让你的技术栈中不同工具之间实现无缝数据流动
  • 创建能够理解跨平台上下文的智能自动化
  • 在运行时加载所有可用工具,而无需硬编码集成逻辑
  • 让 agents 能随着 Tool Pack 中新增工具而自动发现并使用它们
  • 构建可适应工具可用性变化的灵活 agents
  • 不同用户可以拥有不同的工具权限和访问级别
  • 支持多租户工作流,让 agents 代表特定用户执行操作
  • 为所有工具操作保持正确的归属和权限

Merge Agent Handler 支持跨多个类别的数百种集成:

  • 项目管理:Linear、Jira、Asana、Monday.com、ClickUp
  • 代码管理:GitHub、GitLab、Bitbucket
  • 通信:Slack、Microsoft Teams、Discord
  • 文档:Notion、Confluence、Google Docs
  • CRM:Salesforce、HubSpot、Pipedrive
  • 以及更多…

完整可用集成列表请参阅 Merge Agent Handler 文档

该工具提供了完整的错误处理:

  • Authentication Errors:无效或缺失的 API keys
  • Permission Errors:用户没有执行请求操作的权限
  • API Errors:与 Agent Handler 或第三方服务通信时出现的问题
  • Validation Errors:传给工具方法的参数无效

所有错误都会封装为 MergeAgentHandlerToolError,以便统一处理。