当前位置: 首页 > news >正文

CrewAI智能体开发:合并代理处理工具

通过 Merge 的 Agent Handler 平台,使 CrewAI 代理能够安全地访问 Linear、GitHub、Slack 等第三方集成

MergeAgentHandlerTool

MergeAgentHandlerTool允许 CrewAI 代理通过 Merge 的 Agent Handler 平台安全地访问第三方集成。Agent Handler 为 Linear、GitHub、Slack、Notion 等数百种热门工具提供预构建的安全连接器,所有连接器均内置身份验证、权限管理和监控功能。

安装

uv pip install 'crewai[tools]'

要求

  • 已配置工具包的 Merge Agent Handler 账户
  • Agent Handler API 密钥
  • 至少一个已注册用户并关联到您的工具包
  • 在您的工具包中配置的第三方集成

Agent Handler 入门

  1. 在 ah.merge.dev/signup注册一个 Merge Agent Handler 账户
  2. 创建一个工具包并配置您需要的集成
  3. 注册用户以通过第三方服务进行身份验证
  4. 从 Agent Handler 仪表板获取您的 API 密钥
  5. 设置环境变量export AGENT_HANDLER_API_KEY='您的密钥'
  6. 使用 CrewAI 中的 MergeAgentHandlerTool开始构建

注意

  • 工具包 ID 和注册用户 ID 可以在您的 Agent Handler 仪表板中找到或通过 API 创建
  • 该工具使用模型上下文协议(MCP)与 Agent Handler 通信
  • 会话 ID 自动生成,但可以自定义以保持上下文持久性
  • 所有工具调用都通过 Agent Handler 平台进行记录和审计
  • 工具参数从 Agent Handler API 动态发现并自动验证

用法

单一工具用法以下是使用工具包中特定工具的方法

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)

从工具包加载多个工具您可以一次性加载工具包中所有可用的工具

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

工具参数

from_tool_name()方法

参数类型必填默认值描述
tool_namestr要使用的特定工具的名称(例如,“linear__create_issue”)
tool_pack_idstr您的 Agent Handler 工具包的 UUID
registered_user_idstr注册用户的 UUID 或 origin_id
base_urlstr“https://ah-api.merge.dev”Agent Handler API 的基本 URL
session_idstr自动生成用于维护上下文的 MCP 会话 ID

from_tool_pack()方法

参数类型必填默认值描述
tool_pack_idstr您的 Agent Handler 工具包的 UUID
registered_user_idstr注册用户的 UUID 或 origin_id
tool_nameslist[str]要加载的特定工具名称。如果为 None,则加载所有可用工具
base_urlstr“https://ah-api.merge.dev”Agent Handler API 的基本 URL

环境变量

AGENT_HANDLER_API_KEY=your_api_key_here # Required for authentication

高级用法

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

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

自定义会话管理使用会话 ID 在多个工具调用之间保持上下文

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
  • 使代理能够通过一个集成点与 Linear、GitHub、Slack、Notion、Jira、Asana 等工具协同工作
  • 通过让 Agent Handler 管理身份验证和 API 版本控制来降低集成复杂性

安全的企业工作流

  • 利用所有第三方集成的内置身份验证和权限管理
  • 通过集中式访问控制和审计日志维护企业安全标准
  • 使代理能够访问公司工具,而无需在代码中暴露 API 密钥或凭据

跨平台自动化

  • 构建跨多个平台的工作流(例如,从 Linear 任务创建 GitHub 问题,将 Notion 页面同步到 Slack)
  • 实现技术栈中不同工具之间的无缝数据流
  • 创建理解不同平台上下文的智能自动化

动态工具发现

  • 在运行时加载所有可用工具,无需硬编码集成逻辑
  • 使代理能够发现并使用添加到工具包中的新工具
  • 构建能够适应工具可用性变化的灵活代理

用户特定工具访问

  • 不同的用户可以拥有不同的工具权限和访问级别
  • 实现多租户工作流,其中代理代表特定用户执行操作
  • 为所有工具操作维护适当的归属和权限

可用集成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 文档 以获取可用集成的完整列表。

错误处理该工具提供全面的错误处理

  • 身份验证错误:无效或缺失的 API 密钥
  • 权限错误:用户缺乏所需操作的权限
  • API 错误:与 Agent Handler 或第三方服务通信问题
  • 验证错误:传递给工具方法的参数无效

所有错误都封装在MergeAgentHandlerToolError中,以实现一致的错误处理。

《AI提示工程必知必会》为读者提供了丰富的AI提示工程知识与实战技能。《AI提示工程必知必会》主要内容包括各类提示词的应用,如问答式、指令式、状态类、建议式、安全类和感谢类提示词,以及如何通过实战演练掌握提示词的使用技巧;使用提示词进行文本摘要、改写重述、语法纠错、机器翻译等语言处理任务,以及在数据挖掘、程序开发等领域的应用;AI在绘画创作上的应用,百度文心一言和阿里通义大模型这两大智能平台的特性与功能,以及市场调研中提示词的实战应用。通过阅读《AI提示工程必知必会》,读者可掌握如何有效利用AI提示工程提升工作效率,创新工作流程,并在职场中脱颖而出。

http://www.jsqmd.com/news/739459/

相关文章:

  • 【MySQL初阶】MySQL连接池原理与简易网站数据流动是如何进行的(初阶完)
  • 创业团队如何借助Taotoken统一API降低多模型试错与接入成本
  • GD32F103虚拟串口(CDC)移植避坑指南:从Demo到实用项目的关键三步
  • 第九章-04-Python模块的导入
  • 深入解析STM32存储器架构与总线系统
  • Stein《复分析》第一章精读笔记:从“荒谬”的负数平方根到Cauchy定理的引子
  • AI时代,如何保持深度思考的能力
  • 什么是中间人攻击
  • AI推理时代的逻辑重构
  • 拯救C盘!手把手教你将Anaconda虚拟环境安装到其他盘(附权限问题解决)
  • 2026年哪些平台可以购买积存金?主流渠道对比参考 - 品牌排行榜
  • 为 Hermes Agent 自定义 LLM 提供商并接入 Taotoken 的配置指南
  • R3nzSkin皮肤注入工具:5步轻松实现英雄联盟皮肤自定义
  • 如何用PyTorch自动微分快速构建科学计算模型:从理论到实践的完整指南 [特殊字符]
  • Obsidian Zettelkasten终极指南:30天打造高效个人知识库系统
  • 2026南京男士假发定制天花板?世晨非凡男士假发定制(南京金轮国际店)实测:4秒佩戴 + 隐形无痕,这效果绝了! - 律界观察
  • 电商订单数据分析实战:基于SQL的全流程业务挖掘
  • 暗黑破坏神2存档编辑器终极指南:3分钟快速上手修改你的游戏角色
  • 告别轮询!在Linux上用select实现高效串口中断接收(附i.MX6ULL实测代码)
  • 别再手画流程图了!用PlantUML 5分钟搞定产品需求文档里的用例图
  • OneNote高手都在用的‘隐藏’操作:用键盘搞定表格、大纲和页面管理(Windows版)
  • 【仅限机构订阅的优化清单】:Linux实时调度+CPU隔离+RDT技术在Python交易引擎中的军工级落地
  • 一步到位!OpenClaw 全自动部署教程(附下载链接+问题排查)
  • 对比直接使用原生 API 与通过 Taotoken 聚合调用的便捷性差异
  • xss的介绍
  • LLM驱动的硬件木马攻防新范式解析
  • Spring 框架 05:Spring AOP 配置文件方式详解
  • 通过官方价折扣与活动价降低大模型api的长期使用成本
  • 如何用Keyviz免费工具让键盘鼠标操作一目了然?完整指南
  • 别急着装Kubuntu!在Ubuntu上保留GNOME的同时体验KDE Plasma(双桌面共存指南)