文章目录
一、关于 Composio
Composo 是 AI代理的生产就绪工具集,为代理提供精心设计的工具,使他们能够处理复杂的任务
- github : https://github.com/ComposioHQ/composio
- 官网:https://www.composio.dev/
- 官方文档:https://docs.composio.dev/introduction/intro/overview
- API : https://docs.composio.dev/api-reference/
- Dashboard 上试用 : https://app.composio.dev/
为什么是Composo?🤔
我们相信基于AI的代理/工作流是未来。Composo是将AI代理集成到最佳代理工具并使用它们来完成任务的最佳工具集。
主要特点 🔥
- 100多种工具:支持一系列不同的类别
- 软件:在GitHub、Notion、Linear、Gmail、Slack、Hubspot、赛福时等90个平台上做任何事情。
- 操作系统:单击任意位置,键入任何内容,复制到剪切板等。
- 浏览器:智能搜索、截屏、MultiOn、下载、上传等。
- 搜索:谷歌搜索、困惑搜索、Tavily、Exa等。
- SWE:Ngrok、数据库、Redis、Vercel、Git等。
- RAG:用于任何类型数据的代理RAG!
- 框架:在一行代码中使用带有代理框架的工具,如OpenAI、Claude、LlamaIndex、Langchain、CrewAI、Autogen、Double、Julep、Lyzr等。
- 托管授权:支持六种不同的身份验证协议。访问代币、刷新代币、OAuth、API密钥、JWT等等,因此您可以专注于构建代理。
- 精度:由于更好的工具设计,在您的工具调用中获得高达40%的代理精度。
- 可嵌入:应用程序后端的Whitelabel为所有用户和代理管理身份验证和集成,并保持一致的体验。
- 可插拔:旨在非常轻松地使用其他工具、框架和授权协议进行扩展。
例子💡
- Competitor Researcher : https://docs.composio.dev/guides/examples/CompetitorResearcher
- Todolist to Calendar : https://docs.composio.dev/guides/examples/todo-to-calendar
- Github到Trellox : https://docs.composio.dev/guides/examples/github-trello
二、Python入门🚀
1、安装
要开始使用,请在终端中键入以下命令。
pip install composio-core
如果您想安装’composo’包及其openai插件:
pip install composio-openai
2、马上测试 Composio
让我们使用Composo创建一个可以启动Github Repo的AI代理。
composio add github # Connect your Github - Run this in terminal
from openai import OpenAI
from composio_openai import ComposioToolSet, App, Action
openai_client = OpenAI(
api_key="{{OPENAIKEY}}"
)
# Initialise the Composio Tool Set
composio_tool_set = ComposioToolSet()
# Get GitHub tools that are pre-configured
actions = composio_tool_set.get_actions(
actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER]
)
my_task = "Star a repo composiodev/composio on GitHub"
# Setup openai assistant
assistant_instruction = "You are a super intelligent personal assistant"
assistant = openai_client.beta.assistants.create(
name="Personal Assistant",
instructions=assistant_instruction,
model="gpt-4-turbo",
tools=actions,
)
# create a thread
thread = openai_client.beta.threads.create()
message = openai_client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content=my_task
)
# Execute Agent with integrations
run = openai_client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id
)
# Execute Function calls
response_after_tool_calls = composio_tool_set.wait_and_handle_assistant_tool_calls(
client=openai_client,
run=run,
thread=thread,
)
print(response_after_tool_calls)
三、🚀Javascript入门
要开始使用Javascript中的Composo SDK,请执行以下步骤:
1、安装Composo SDK:
npm install composio-core
2、设置OpenAI和 Composio 工具集:
import { OpenAI } from "openai";
import { OpenAIToolSet } from "composio-core";
const toolset = new OpenAIToolSet({
apiKey: process.env.COMPOSIO_API_KEY,
});
async function setupUserConnectionIfNotExists(entityId) {
const entity = await toolset.client.getEntity(entityId);
const connection = await entity.getConnection('github');
if (!connection) {
// If this entity/user hasn't already connected the account
const connection = await entity.initiateConnection(appName);
console.log("Log in via: ", connection.redirectUrl);
return connection.waitUntilActive(60);
}
return connection;
}
async function executeAgent(entityName) {
const entity = await toolset.client.getEntity(entityName)
await setupUserConnectionIfNotExists(entity.id);
const tools = await toolset.get_actions({ actions: ["github_issues_create"] }, entity.id);
const instruction = "Make an issue with sample title in the repo - himanshu-dixit/custom-repo-breaking"
const client = new OpenAI({ apiKey: process.env.OPEN_AI_API_KEY })
const response = await client.chat.completions.create({
model: "gpt-4-turbo",
messages: [{
role: "user",
content: instruction,
}],
tools: tools,
tool_choice: "auto",
})
console.log(response.choices[0].message.tool_calls);
await toolset.handle_tool_call(response, entity.id);
}
executeAgent("your-entity-name");
3.运行您的脚本:
node your_script.js
这将设置Composo SDK并执行一个代理,该代理使用提供的指令创建GitHub问题。
更多详情可见Composo SDK文档。
2024-07-25(四)