Using Composio With IBM

Composio enables IBM’s Granite Models to connect with many tools!

Goal: Star a repository on GitHub with natural language

Video Guide

Install Packages & Connect a Tool

Ensure you have the necessary packages installed and connect your GitHub account to allow your IBM agents to utilize GitHub functionalities.

Run command
$pip install composio-langchain
>pip install langchain-ibm
>
># Connect your GitHub so agents can use it.
>composio add github
># Check all different apps which you can connect with
>composio apps

Goal: Prepare your environment by initializing necessary imports from Composio & IBM.

1

Import Base Packages

Prepare your environment by initializing necessary imports from Composio & IBM.

Default Imports
1from composio_langchain import ComposioToolSet, Action
2from langchain_ibm import ChatWatsonx
3import os
4
5os.environ['WATSONX_API_KEY'] = '<ibm_api_key>' #add your ibm api key here
6if not os.environ.get('WATSONX_API_KEY'):
7 raise ValueError("WATSONX_API_KEY environment variable is not set")
2

Integrating GitHub Tools with Composio

This step involves fetching and integrating GitHub tools provided by Composio, enabling enhanced functionality for Agent operations.

IBM Supported tools from Composio
1composio_toolset = ComposioToolSet()
2tools = composio_toolset.get_tools(
3 actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER]
4)
3

IBM Agent Setup

This step involves configuring and executing the agent to carry out actions, such as starring a GitHub repository.

IBM Agent Setup
1parameters = {
2"decoding_method": "sample",
3"max_new_tokens": 100,
4"min_new_tokens": 1,
5"temperature": 0.5,
6"top_k": 50,
7"top_p": 1,
8}
9url = input('Add your IBM Cloud URL here: ')
10project_id = input('Add your IBM Project ID here: ')
11watsonx_llm = ChatWatsonx(
12model_id = 'ibm/granite-3-8b-instruct',
13url = url,
14project_id = project_id,
15)
16
17if not url or not project_id:
18 raise ValueError("IBM Cloud URL and Project ID must be provided")
19
20llm_with_tools = watsonx_llm.bind_tools(tools)
4

Execute with your prompt/task.

Execute the following code to execute the agent, ensuring that the intended task has been successfully completed.

Agent Execution
1response = llm_with_tools.invoke("Star the composiohq/composio repository")
2print(response)
Built with