Using Composio With Google AI

Enable Google AI models to seamlessly interact with external apps via Composio for enhanced functionality

Composio enables your Google AI models to connect with many tools!

Install Packages & Connect a Tool

Goal: Enable Google AI models to perform tasks like starring a repository on GitHub via natural language commands

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

Run Command
$pip install composio-google
>
># Connect your GitHub so models can interact with it
>
>composio add github
>
># Check all supported apps
>
>composio apps
1

Import Base Packages & Initialize Google AI Model

Replace {google_api_key} with your actual API key.

Default Imports & Configuration
1import dotenv
2from composio_google import App, ComposioToolset
3from vertexai.generative_models import GenerativeModel
4
5# Load environment variables from .env
6dotenv.load_dotenv()
7
8# Initialize the Composio Toolset
9composio_toolset = ComposioToolset()
10
11# Get GitHub tools that are pre-configured
12tool = composio_toolset.get_tool(apps=[App.GITHUB])
13
14# Initialize the Google AI Gemini model
15model = GenerativeModel("gemini-1.5-pro", tools=[tool])
2

Start a Chat Session with the Model

Start Chat Session
1# Start a chat session
2chat = model.start_chat()
3

Execute the Task via Google AI Model

Execute Task
1# Define task
2task = "Star a repo composiohq/composio on GitHub"
3
4# Send a message to the model
5response = chat.send_message(task)
6
7print("Model response:")
8print(response)
4

Handle the Tool Calls

Handle Tool Calls
1result = composio_toolset.handle_response(response)
2print("Function call result:")
3print(result)

Use Specific Actions

Filter Specific Action
1# To restrict models from executing any actions, filter specific actions
2actions = composio_toolset.get_tool(actions=[Action.GITHUB_CREATE_ISSUE])

Use Specific Apps

Filter Specific App
1# To restrict models from using all tools, filter specific tools
2actions = composio_toolset.get_tool(apps=[App.ASANA, App.GITHUB])

Filter apps actions by tags

Filter Actions by Tags
1actions = composio_toolset.get_tool(apps=[App.ASANA], tags=[Tag.ASANA_TASKS])