Using Composio With Cloudflare Worker AI

Star A Repository on Github

In this example, we will use Cloudflare Worker AI to star a repository on Github using Composio Tools

1

Install Packages

JavaScript
$npm install composio-core -g wrangler fs
2

Setup wrangler in wrangler.toml file

wrangler.toml
1name = "github-agent"
2main = "worker.js"
3compatibility_date = "2024-09-23"
4compatibility_flags = ["nodejs_compat"]
5
6[vars]
7COMPOSIO_API_KEY = "<your-composio-api-key>"
8
9[ai]
10binding = "AI"
3

Import Libraries & Initialize Hono

worker.js
1import { Hono } from 'hono';
2import { CloudflareToolSet } from "composio-core"
3
4const app = new Hono();
4

Create an endpoint & get GitHub Tools

You can get all the tools for a given app as shown below, but you can get specific actions and filter actions using usecase & tags. Learn more here

worker.js
1app.post('/', async (c) => {
2 const toolset = new CloudflareToolSet();
3
4 try {
5 const tools = await toolset.getTools({ apps: ['github'] });
6 const instruction = 'Star the repository "composiohq/composio"';
7
8 let messages = [
9 { role: 'system', content: '' },
10 { role: 'user', content: instruction },
11 ];
12
13 const config = {
14 model: '@hf/nousresearch/hermes-2-pro-mistral-7b',
15 };
16
17 const toolCallResp = await c.env.AI.run(config.model, {
18 messages,
19 tools,
20 });
21
22 await toolset.handleToolCall(toolCallResp, entity.id);
23 return c.json({ messages: "Your issue has been created" });
24 } catch (err) {
25 console.log(err);
26 return c.text('Something went wrong', 500);
27 }
28
29 export default app;
30});
5

Start the Worker

CLI
$wrangler dev