Executing Tools
Learn how to run Composio tools via LLM frameworks or directly from your code
Once you have fetched or defined your tools (Fetching Tools), the next step is to execute them. This means triggering the actual API call or function execution that the tool represents.
There are two primary ways to execute Composio tools:
- Automatic execution: Your chosen LLM decides which tool to call, and a framework (like Vercel AI SDK, LangChain) handles triggering the execution logic provided by Composio.
- Direct execution: Your LLM/agent decides to call a tool and the code explicitly invokes the specific Composio tool using the
execute_action
method, often used for testing or simple automation.
Automatic execution
Frameworks like the Vercel AI, LangGraph often have features to automatically execute
the tools. The framework will handle the execution logic provided by Composio.
Here’s an example of how Vercel AI SDK automatically executes tools
Key Takeaway: When using a framework integration, you typically fetch tools using the corresponding Composio ToolSet (e.g., VercelAIToolSet
) and then use the framework’s standard way to handle tool calls. Composio’s ToolSet ensures the execution logic is correctly wired behind the scenes.
Refer to the specific Framework Integration Guide for your chosen framework (e.g., Vercel AI, LangChain, CrewAI) to see the exact code patterns for handling tool execution within that ecosystem.
Direct execution
For scenarios where you want to run a specific tool programmatically without an LLM making the decision, use the execute_action
method. This is available on the base ComposioToolSet
and framework-specific ToolSets.
Let’s create a GitHub issue using Composio.
This directly triggers the specified Composio action using the associated user’s credentials.
Specifying Users
By using entity_id
Composio needs to know which user’s connection/credentials to use when executing an authenticated action. You provide this context using entity_id
and sometimes connected_account_id
.
By default it uses the default entity ID "default"
.
For multi-tenant applications (multi-user apps), you need to provide the entity_id
.
By using connected_account_id
connected_account_id
offers more precision by identifying a specific instance of a connection (e.g., a user’s work Gmail vs. personal Gmail).
You typically only need this if an entity_id
has multiple active connections for the same app.
If connected_account_id
is not provided, Composio generally uses the most recently added active connection matching the entity_id
and the app being used. You can pass it when needed, primarily with execute_action
: