跳转到内容

Composio Tool

Composio 是一个集成平台,可让你把 AI agents 连接到 250+ 种工具。主要特性包括:

  • 企业级认证:内置支持 OAuth、API Keys、JWT,并可自动刷新 token
  • 完整可观测性:详细的工具使用日志、执行时间戳等

要将 Composio 工具集成到项目中,请按以下步骤操作:

Terminal window
pip install composio composio-crewai
pip install crewai

安装完成后,将你的 Composio API key 设为 COMPOSIO_API_KEY。你可以 在这里 获取 Composio API key。

下面的示例展示了如何初始化工具并执行一个 github action:

  1. 使用 CrewAI Provider 初始化 Composio
from composio_crewai import ComposioProvider
from composio import Composio
from crewai import Agent, Task, Crew
composio = Composio(provider=ComposioProvider())
  1. 创建新的 Composio Session 并获取工具
Code
session = composio.create(
user_id="your-user-id",
toolkits=["gmail", "github"] # optional, default is all toolkits
)
tools = session.tools()

关于 session 和用户管理的更多信息请见 这里

  1. 手动认证用户

Composio 会在 agent 对话过程中自动认证用户。不过,你也可以通过调用 authorize 方法手动认证用户。

connection_request = session.authorize("github")
print(f"Open this URL to authenticate: {connection_request.redirect_url}")
  1. 定义 agent
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()
  • 更详细的工具列表可以在 这里 查看