ComposioToolSet

描述

Composio 是一个集成平台,可让您将 AI 智能体连接到 250 多个工具。主要功能包括:

  • 企业级认证:内置支持 OAuth、API 密钥、JWT 并带有自动令牌刷新功能
  • 全面的可观测性:详细的工具使用日志、执行时间戳等

安装

要将 Composio 工具整合到您的项目中,请遵循以下说明:

pip install composio-crewai
pip install crewai

安装完成后,运行 composio login 或将您的 composio API 密钥导出为 COMPOSIO_API_KEY。您可以在此处获取您的 Composio API 密钥

示例

以下示例演示了如何初始化工具并执行一个 GitHub 操作

  1. 初始化 Composio 工具集
代码
from composio_crewai import ComposioToolSet, App, Action
from crewai import Agent, Task, Crew

toolset = ComposioToolSet()
  1. 连接您的 GitHub 账户
composio add github
  1. 获取工具
  • 从应用程序中检索所有工具(不建议用于生产环境)
代码
tools = toolset.get_tools(apps=[App.GITHUB])
  • 根据标签过滤工具
代码
tag = "users"

filtered_action_enums = toolset.find_actions_by_tags(
    App.GITHUB,
    tags=[tag], 
)

tools = toolset.get_tools(actions=filtered_action_enums)
  • 根据用例过滤工具
代码
use_case = "Star a repository on GitHub"

filtered_action_enums = toolset.find_actions_by_use_case(
    App.GITHUB, use_case=use_case, advanced=False
)

tools = toolset.get_tools(actions=filtered_action_enums)
设置 advanced 为 True 以获取复杂用例的操作
  • 使用特定工具

在此演示中,我们将使用 GitHub 应用程序中的 GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER 操作。

代码
tools = toolset.get_tools(
    actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]
)

在此此处了解更多关于过滤操作的信息

  1. 定义智能体
代码
crewai_agent = Agent(
    role="GitHub Agent",
    goal="You take action on GitHub using GitHub APIs",
    backstory="You are AI agent that is responsible for taking actions on GitHub on behalf of users using GitHub APIs",
    verbose=True,
    tools=tools,
    llm= # pass an llm
)
  1. 执行任务
代码
task = Task(
    description="Star a repo composiohq/composio on GitHub",
    agent=crewai_agent,
    expected_output="Status of the operation",
)

crew = Crew(agents=[crewai_agent], tasks=[task])

crew.kickoff()
  • 在此此处可找到更详细的工具列表