Executing Tools

Learn how to execute Composio's tools with different providers and frameworks

Tool calling is a feature of all frontier LLMs to allow them to interact with the outside world. Earlier you might be able to ask an LLM to write you a nice email, but you would have to manually send it. With tool calling, you can now provide an LLM a valid tools for example, GMAIL_SEND_EMAIL to go and accomplish the task autonomously.

Using Chat Completions

For non-agent providers—such as OpenAI, Anthropic, and Google AI—you can process tool calls using the tool call handlers provided by the Composio SDK. This approach works consistently across all supported non-agent providers.

To learn how to setup these providers, see Providers.

1import { Composio } from "@composio/core";
2import { AnthropicProvider } from "@composio/anthropic";
3
4const userId = "user@acme.com"; // User's UUID
5
6const anthropic = new Anthropic();
7const composio = new Composio({
8 apiKey: process.env.COMPOSIO_API_KEY,
9 provider: new AnthropicProvider(),
10});
11
12const tools = await composio.tools.get(userId, {
13 tools: ["GITHUB_GET_THE_ZEN_OF_GITHUB"],
14});
15
16const msg = await anthropic.messages.create({
17 model: "claude-3-7-sonnet-latest",
18 tools: tools,
19 messages: [
20 {
21 role: "user",
22 content: "gimme me some zen!!",
23 },
24 ],
25 max_tokens: 1024,
26});
27
28
29const result = await composio.provider.handleToolCalls(userId, msg);
30console.log(result);

Using Agentic Frameworks

Composio also has first-party support for agentic frameworks which execute tools, feed the result to the LLM and continue the conversation.

Here, the tool execution is handled by the agentic framework. Composio makes sure the tools are formatted into the correct objects for the agentic framework to execute.

1import { Composio } from "@composio/core";
2import { generateText } from "ai";
3import { anthropic } from "@ai-sdk/anthropic";
4import { VercelProvider } from "@composio/vercel";
5
6const userId = "0000";
7
8const composio = new Composio({
9 apiKey: process.env.COMPOSIO_API_KEY,
10 provider: new VercelProvider(),
11});
12
13const tools = await composio.tools.get(userId, {
14 toolkits: ["LINEAR"],
15 limit: 15,
16});
17
18const { text } = await generateText({
19 model: anthropic("claude-3-7-sonnet-20250219"),
20 messages: [
21 {
22 role: "user",
23 content:
24 "Fetch all my projects",
25 },
26 ],
27 tools,
28 maxSteps: 5,
29});
30
31console.log(text);

Tools are scoped to a user

Each tool and tool action is scoped to a user. Hence, a user_id is required to fetch and execute tools.

The authentication state is checked and used while fetching and executing a tool.

You need to authorize the user to execute tools. For more information on authentication, see Authenticating Tools.

For Humans (deterministic tool calling)

In case you just want to call a tool manually — not using any framework or LLM provider, you can do so using the execute method.

1const userId = "user@example.com";
2const composio = new Composio();
3
4const result = await composio.tools.execute("HACKERNEWS_GET_USER", {
5 userId,
6 arguments: {
7 username: "pg",
8 },
9});
10console.log(result);

Proxy Execute — Manually calling toolkit APIs

You can also proxy requests to an API of any supported toolkit. This is useful when you want to manually call an API of a toolkit and inject the authentication state from Composio.

1// Send a custom request to a toolkit
2const { data } = await composio.tools.proxyExecute({
3 toolkitSlug: 'github',
4 userId: 'user@example.com',
5 data: {
6 endpoint: '/repos/owner/repo/issues',
7 method: 'GET'
8 }
9});
10console.log(data);

If you’re interested in extending toolkits and creating custom tools, see Custom tools.