主题
Composio Tool
Composio 为智能体提供 250+ 个生产就绪的工具,并具备灵活的身份认证管理。
ComposioToolSet
描述
Composio 是一个集成平台,可让你的智能体连接到 250+ 个工具。主要特性包括:
- 企业级身份认证:内置支持 OAuth、API Keys、JWT,并自动刷新 token
- 完整可观测性:详细的工具使用日志、执行时间戳等
安装
要将 Composio 工具引入你的项目,请按以下说明操作:
shell
pip install composio composio-crewai
pip install crewai安装完成后,将你的 Composio API 密钥设置为 COMPOSIO_API_KEY。可从这里获取你的 Composio API 密钥
示例
以下示例演示如何初始化该工具并执行一个 github action:
- 使用 CrewAI 服务商初始化 Composio
python
from composio_crewai import ComposioProvider
from composio import Composio
from crewai import Agent, Task, Crew
composio = Composio(provider=ComposioProvider())- 创建一个新的 Composio 会话并获取工具
python
session = composio.create(
user_id="your-user-id",
toolkits=["gmail", "github"] # optional, default is all toolkits
)
tools = session.tools()在这里了解更多关于会话和用户管理的内容
- 手动完成用户身份认证
Composio 会在智能体聊天会话期间自动完成用户身份认证。不过,你也可以通过调用 authorize 方法手动完成用户身份认证。
python
connection_request = session.authorize("github")
print(f"Open this URL to authenticate: {connection_request.redirect_url}")- 定义智能体
python
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
)- 执行任务
python
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()- 更详细的工具列表见这里