Skip to main content

Using Tools with LLMs

Composio enables you to integrate various tools (such as Gmail, GitHub, and Salesforce) and perform actions (such as sending emails or creating GitHub issues). Browse our complete list of supported Tools. Install packages:
pip install composio-openai openai
Using tools with LLMs:
# Import required libraries
from composio_openai import ComposioToolSet, App
from openai import OpenAI

# Initialize OpenAI and Composio clients
openai_client = OpenAI()
composio_toolset = ComposioToolSet()

# Get GitHub tools from Composio
tools = composio_toolset.get_tools(apps=[App.GITHUB])

task = "Star the repo composiohq/composio on GitHub"

# Make API call to OpenAI with the tools
response = openai_client.chat.completions.create(
    model="gpt-4o-mini",
    tools=tools,
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": task},
    ],
)

# Execute the tool calls
result = composio_toolset.handle_tool_calls(response)
print(result)
This code demonstrates how to use LLMs with Composio Tools to execute actions. The example shows how to connect OpenAI’s LLM with Composio’s tools, in this case using the GitHub tool. The LLM understands the natural language task (“Star the repo”) and determines which action to use from the GitHub tool, then executes the action.

How can I use Tools for a specific user?

You can use the entity_id parameter to specify the user on behalf of whom you want to execute the action. Learn more about Entities here. Install packages:
pip install composio-openai openai
Using tools for a specific user:
# Import required libraries
from composio_openai import ComposioToolSet, App
from openai import OpenAI

# Initialize OpenAI and Composio clients
openai_client = OpenAI()
composio_toolset = ComposioToolSet(entity_id="Jessica")

# Get GitHub tools from Composio for the entity Jessica
tools = composio_toolset.get_tools(apps=[App.GITHUB])

task = "Star the repo composiohq/composio on GitHub"

# Make API call to OpenAI with the tools
response = openai_client.chat.completions.create(
    model="gpt-4o-mini",
    tools=tools,
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": task},
    ],
)

# Execute the tool calls
result = composio_toolset.handle_tool_calls(response=response)
print(result)
Composio supports multiple agent frameworks including LlamaIndex, CrewAI, Letta, and LangChain. See the Supported Frameworks section for details.