Composio and OpenAI work together to extend the capabilities of your agents by interacting with a variety of external applications.

Install Packages & Connect a Tool

Goal: Enable OpenAI assistants to perform tasks like starring a repository on GitHub via natural language commands

These steps prepare your environment to enable interactions between OpenAI and GitHub through Composio.

pip install composio-openai

# Connect your GitHub so agents can interact with it
composio-cli add github 

# Check all supported apps 
composio-cli show-apps
1

Import Base Packages & Configure OpenAI Client

from openai import OpenAI
from composio_openai import ComposioToolset, App

openai_client = OpenAI()
# Initialise the Composio Tool Set
composio_tools = ComposioToolset()
2

Fetch All GitHub Tools via Composio

# Get GitHub tools that are pre-configured
actions = composio_tools.get_tools(tools=App.GITHUB)
3

Execute the Task via OpenAI Agent

my_task = "Star a repo SamparkAI/composio_sdk on GitHub"

response = openai_client.chat.completions.create(
    model="gpt-4-turbo-preview",
    tools=actions, # Passing actions we fetched earlier.
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": my_task}
    ]
)

from pprint import pprint
pprint(response)
4

Handle Tool Calls and Check Response

result = composio_tools.handle_tool_calls(response)
pprint(result)

Use Specific Actions

# To restrict agents from executing any actions, filter specific actions
composio_tools.register_tools(actions=[Action.GITHUB_CREATE_ISSUE])

Use Specific Apps

# To restrict agents from using all tools, filter specific tools
composio_tools.register_tools(apps=[App.ASANA, App.GITHUB])

Filter apps actions by tags


Tags
composio_tools.register_tools(apps=[App.ASANA], tags=[Tag.ASANA_TASKS])