🛠️ Configure Tools

Learn how to configure tools

Initialization Parameters

When setting up Composio tools, you might need to provide various configuration parameters like API keys, session IDs, or custom settings. These parameters can be specified at two levels:

  1. App-level: Parameters that apply to all actions within a specific tool/app
  2. Action-level: Specific parameters needed for individual actions

For example, if you’re using the Image Analyzer tool, you’ll need to provide an OpenAI API key. Similarly, other tools might require their own specific configuration parameters to function properly.

1

Import required libraries

1from langchain.agents import create_openai_functions_agent, AgentExecutor
2from langchain import hub
3from langchain_openai import ChatOpenAI
4from composio_langchain import ComposioToolSet, Action, App
2

Import Prompt template & Initialize ChatOpenAI & composio toolset client

During the initialization of the ComposioToolSet client, we can add metadata to actions & apps. In this example, we’re adding an OpenAI API key for the IMAGE_ANALYSER_ANALYSE action:

1prompt = hub.pull("hwchase17/openai-functions-agent")
2
3llm = ChatOpenAI()
4composio_toolset = ComposioToolSet(
5 metadata={
6 Action.IMAGE_ANALYSER_ANALYSE: {
7 "OPENAI_API_KEY": "<your-openai-api-key>",
8 }
9 }
10)
3

Get Image Analyser Action from Composio

1tools = composio_toolset.get_tools(
2 actions=[Action.IMAGE_ANALYSER_ANALYSE],
3)
4

Invoke the agent

1task = "Describe the image. Image Path: cat.png"
2
3agent = create_openai_functions_agent(llm, tools, prompt)
4agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
5
6agent_executor.invoke({"input": task})

How to add metadata at App-level?

Above we saw how to add metadata at the Action-level. Here’s an example of how to add metadata at the App-level:

1toolset = ComposioToolSet(
2 metadata={
3 App.<app_name>: {
4 "attribute": "value",
5 }
6 }
7)