跳转到主要内容

Composio工具集

描述

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()
  • 更详细的工具列表可在此处找到