Introducing Composio: The Ultimate Toolset for AI Agents

In the rapidly evolving world of AI and automation, having the right tools at your disposal can make all the difference. Composio stands out as a robust, production-ready toolset designed to equip AI agents with high-quality tools and integrations. With Composio, you can effortlessly manage authentication, accuracy, and reliability, all with just a single line of code. This blog post will delve into why Composio is the ideal choice for integrating AI agents, explore its key features, and guide you through getting started with Python and JavaScript.

Why Composio?

The future of automation and AI lies in the seamless integration of AI-based agents and workflows. Composio is designed to be the best toolset for integrating these AI agents with a wide range of Agentic Tools, enabling them to accomplish tasks efficiently and effectively. Here are some compelling reasons why Composio is the toolset you need:

Simplified Integration

Composio allows you to integrate AI agents with over 100 tools across various categories. Whether it's software, operating systems, browsers, search engines, or software engineering tools, Composio has you covered. This extensive range of tools ensures that your AI agents can handle diverse tasks without any hassle.

Managed Authorization

One of the most significant challenges in integrating multiple tools and services is managing different authentication protocols. Composio abstracts this complexity by supporting six different auth protocols, including access tokens, refresh tokens, OAuth, API keys, JWT, and more. This managed authorization allows you to focus on building and deploying agents without worrying about the intricacies of authentication.

Enhanced Accuracy

Composio's well-designed tools ensure up to 40% better agentic accuracy in tool calls. This means your AI agents can perform tasks more accurately and reliably, leading to better outcomes and improved efficiency.

Embeddable and Pluggable

Composio is designed to be easily embeddable in the backend of your applications. It manages auth and integrations for all your users and agents, maintaining a consistent experience. Moreover, it is highly pluggable, allowing you to extend it with additional tools, frameworks, and authorization protocols as needed.

Key Features of Composio

Composio boasts a wide range of features that make it a powerful toolset for AI agents. Here are some of the key features that set Composio apart:

Extensive Tool Support

Composio supports over 100 tools across different categories, making it a versatile toolset for various use cases:

  • Software: Integrate with GitHub, Notion, Linear, Gmail, Slack, Hubspot, Salesforce, and many more.
  • Operating Systems: Perform actions like clicking anywhere, typing anything, copying to clipboard, etc.
  • Browsers: Conduct smart searches, take screenshots, and manage downloads and uploads.
  • Search Engines: Utilize Google Search, Perplexity Search, Tavily, Exa, and more.
  • Software Engineering Tools: Connect with Ngrok, Database, Redis, Vercel, Git, etc.
  • RAG (Retrieval-Augmented Generation): Implement Agentic RAG for any type of data on the fly.

Seamless Integration with Frameworks

Composio integrates seamlessly with popular agent frameworks such as OpenAI, Claude, LlamaIndex, Langchain, CrewAI, Autogen, Gemini, Julep, Lyzr, and more. This compatibility ensures that you can leverage the best AI frameworks in a single line of code.

Simplified Authorization Management

Composio supports multiple authentication protocols, including access tokens, refresh tokens, OAuth, API keys, and JWT. This managed authorization simplifies the process of integrating different tools and services, allowing you to focus on building robust AI agents.

High Accuracy

Composio's tools are designed for high accuracy, offering up to 40% better agentic accuracy in tool calls. This ensures that your AI agents can perform tasks more accurately and efficiently.

Embeddable and Pluggable

Composio can be easily embedded in the backend of your applications, managing auth and integrations for all your users and agents. It is also designed to be pluggable, allowing you to extend it with additional tools, frameworks, and authorization protocols as needed.

Getting Started with Composio

Now that you understand the benefits and features of Composio, let's dive into how you can get started with it using Python and JavaScript.

Getting Started with Python

1. Installation

To get started with Composio in Python, you need to install the composio-core package. Open your terminal and run the following command:

pip install composio-core

If you want to install the composio package along with its OpenAI plugin, use the following command:

pip install composio-openai

2. Testing Composio in Action

Let's create an AI agent using Composio that can star a GitHub repository. Follow these steps:

  1. Connect Your GitHub Account

    Run the following command in your terminal to connect your GitHub account:

    composio add github
    
  2. Create a Python Script

    Create a Python script with the following content to star a GitHub repository:

    from openai import OpenAI
    from composio_openai import ComposioToolSet, App, Action
    
    openai_client = OpenAI(
        api_key="{{OPENAIKEY}}"
    )
    
    # Initialise the Composio Tool Set
    composio_tool_set = ComposioToolSet()
    
    # Get GitHub tools that are pre-configured
    actions = composio_tool_set.get_actions(
        actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]
    )
    
    my_task = "Star a repo composiodev/composio on GitHub"
    
    # Setup OpenAI assistant
    assistant_instruction = "You are a super intelligent personal assistant"
    
    assistant = openai_client.beta.assistants.create(
        name="Personal Assistant",
        instructions=assistant_instruction,
        model="gpt-4-turbo",
        tools=actions,
    )
    
    # Create a thread
    thread = openai_client.beta.threads.create()
    
    message = openai_client.beta.threads.messages.create(
        thread_id=thread.id,
        role="user",
        content=my_task
    )
    
    # Execute Agent with integrations
    run = openai_client.beta.threads.runs.create(
        thread_id=thread.id,
        assistant_id=assistant.id
    )
    
    # Execute Function calls
    response_after_tool_calls = composio_tool_set.wait_and_handle_assistant_tool_calls(
        client=openai_client,
        run=run,
        thread=thread,
    )
    
    print(response_after_tool_calls)
    
  3. Run the Script

    Execute the Python script to see Composio in action.

Getting Started with JavaScript

To get started with Composio in JavaScript, follow these steps:

1. Install the Composio SDK

Run the following command in your terminal to install the Composio SDK:

npm install composio-core

2. Setup the OpenAI and Composio Tool Set

Create a JavaScript file and add the following content to set up the OpenAI and Composio Tool Set:

import { OpenAI } from "openai";
import { OpenAIToolSet } from "composio-core";

const toolset = new OpenAIToolSet({
    apiKey: process.env.COMPOSIO_API_KEY,
});

async function setupUserConnectionIfNotExists(entityId) {
    const entity = await toolset.client.getEntity(entityId);
    const connection = await entity.getConnection('github');

    if (!connection) {
        // If this entity/user hasn't already connected the account
        const connection = await entity.initiateConnection(appName);
        console.log("Log in via: ", connection.redirectUrl);
        return connection.waitUntilActive(60);
    }

    return connection;
}

async function executeAgent(entityName) {
    const entity = await toolset.client.getEntity(entityName)
    await setupUserConnectionIfNotExists(entity.id);

    const tools = await toolset.get_actions({ actions: ["github_issues_create"] }, entity.id);
    const instruction = "Make an issue with sample title in the repo - himanshu-dixit/custom-repo-breaking"

    const client = new OpenAI({ apiKey: process.env.OPEN_AI_API_KEY })
    const response = await client.chat.completions.create({
        model: "gpt-4-turbo",
        messages: [{
            role: "user",
            content: instruction,
        }],
        tools: tools,
        tool_choice: "auto",
    })

    console.log(response.choices[0].message.tool_calls);
    await toolset.handle_tool_call(response, entity.id);
}

executeAgent("your-entity-name");

3. Run Your Script

Execute the JavaScript file to see Composio in action.

Examples

To help you get started with Composio, here are some example scripts in Python and JavaScript:

Python Example

Here's a Python example of using Composio to star a GitHub repository:

from openai import OpenAI
from composio_openai import ComposioToolSet, App, Action

openai_client = OpenAI(
    api_key="{{OPENAIKEY}}"
)

# Initialise the Composio Tool Set
composio_tool_set = ComposioToolSet()

# Get GitHub tools that are pre-configured
actions = composio_tool_set.get_actions(
    actions=[Action.GITHUB_STAR_A_RE

POSITORY_FOR_THE_AUTHENTICATED_USER]
)

my_task = "Star a repo composiodev/composio on GitHub"

# Setup OpenAI assistant
assistant_instruction = "You are a super intelligent personal assistant"

assistant = openai_client.beta.assistants.create(
    name="Personal Assistant",
    instructions=assistant_instruction,
    model="gpt-4-turbo",
    tools=actions,
)

# Create a thread
thread = openai_client.beta.threads.create()

message = openai_client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content=my_task
)

# Execute Agent with integrations
run = openai_client.beta.threads.runs.create(
    thread_id=thread.id,
    assistant_id=assistant.id
)

# Execute Function calls
response_after_tool_calls = composio_tool_set.wait_and_handle_assistant_tool_calls(
    client=openai_client,
    run=run,
    thread=thread,
)

print(response_after_tool_calls)

JavaScript Example

Here's a JavaScript example of using Composio to create an issue in a GitHub repository:

import { OpenAI } from "openai";
import { OpenAIToolSet } from "composio-core";

const toolset = new OpenAIToolSet({
    apiKey: process.env.COMPOSIO_API_KEY,
});

async function setupUserConnectionIfNotExists(entityId) {
    const entity = await toolset.client.getEntity(entityId);
    const connection = await entity.getConnection('github');

    if (!connection) {
        // If this entity/user hasn't already connected the account
        const connection = await entity.initiateConnection(appName);
        console.log("Log in via: ", connection.redirectUrl);
        return connection.waitUntilActive(60);
    }

    return connection;
}

async function executeAgent(entityName) {
    const entity = await toolset.client.getEntity(entityName)
    await setupUserConnectionIfNotExists(entity.id);

    const tools = await toolset.get_actions({ actions: ["github_issues_create"] }, entity.id);
    const instruction = "Make an issue with sample title in the repo - himanshu-dixit/custom-repo-breaking"

    const client = new OpenAI({ apiKey: process.env.OPEN_AI_API_KEY })
    const response = await client.chat.completions.create({
        model: "gpt-4-turbo",
        messages: [{
            role: "user",
            content: instruction,
        }],
        tools: tools,
        tool_choice: "auto",
    })

    console.log(response.choices[0].message.tool_calls);
    await toolset.handle_tool_call(response, entity.id);
}

executeAgent("your-entity-name");

Contribution and Community

Composio is an open-source project, and we welcome contributions from the community. If you're interested in contributing to Composio, please follow these steps:

  1. Fork the Repository

    Fork the Composio repository on GitHub and create a new branch for your feature or improvement.

  2. Add Your Feature or Improvement

    Implement your feature or improvement in the new branch.

  3. Send a Pull Request

    Once your changes are ready, send a pull request to the main repository.

  4. Follow Contribution Guidelines

    Please go through our Contribution Guidelines and Code of Conduct before you start contributing.

Additional Resources

For more information about Composio, check out the following resources:

Conclusion

Composio is a game-changer for integrating AI agents with a wide range of tools and services. With its extensive tool support, managed authorization, high accuracy, and easy integration with popular frameworks, Composio simplifies the process of building and deploying robust AI agents. Whether you're a developer looking to streamline your workflows or a business aiming to enhance productivity, Composio has the tools and features you need to succeed.

Get started with Composio today and experience the future of AI and automation!

For any questions or support, feel free to reach out to our community or check the documentation. Happy coding!

Next Post Previous Post
No Comment
Add Comment
comment url