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
name = "github-agent"
main = "worker.js"
compatibility_date = "2024-09-23"
compatibility_flags = ["nodejs_compat"]

[vars]
COMPOSIO_API_KEY = "<your-composio-api-key>"

[ai]
binding = "AI"
3

Import Libraries & Initialize Hono

worker.js
import { Hono } from 'hono';
import { CloudflareToolSet } from "composio-core"

const 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
app.post('/', async (c) => {
    const toolset = new CloudflareToolSet();

    try {
        const tools = await toolset.getTools({ apps: ['github'] });
        const instruction = 'Star the repository "composiohq/composio"';    

        let messages = [
            { role: 'system', content: '' },
            { role: 'user', content: instruction },
        ];

        const config = {
            model: '@hf/nousresearch/hermes-2-pro-mistral-7b',
        };

        const toolCallResp = await c.env.AI.run(config.model, {
            messages,
            tools,
        });

        await toolset.handleToolCall(toolCallResp, entity.id);
        return c.json({ messages: "Your issue has been created" });
    } catch (err) {
        console.log(err);
        return c.text('Something went wrong', 500);
    }

    export default app;
});
5

Start the Worker

CLI
wrangler dev