Refining Tool Schemas, Inputs, & Outputs
In many scenarios, the schemas, inputs, or outputs of tools may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are three key use cases:- Modifying Schema: Modify the tool schema like the description of the parameters or the default values. For example, if you’re manually providing certain values in input (like project_id), you can mark these fields as “not required” in the schema so the LLM knows it doesn’t need to ask for them.
- Modifying Inputs: Add values as inputs to avoid specifying them in the prompt. e.g., passing
project_id&team_idto theLINEAR_CREATE_LINEAR_ISSUEaction. - Modifying Outputs: Modify outputs to get the desired data. e.g., extracting
execution_id&issue_idfrom the response ofLINEAR_CREATE_LINEAR_ISSUEaction. Doing this can help keep the LLM context clean.
- App-level: Affects all actions within a specific tool.
- Action-level: Tailored processing for individual actions.
- Python
- TypeScript
1
Install required libraries
Python
2
Import required libraries
Python
3
Import Prompt template & Initialize ChatOpenAI & composio toolset client
Python
4
Define a Custom Function to Modify Schema
This function will be used to modify the schema of the
LINEAR_CREATE_LINEAR_ISSUE action, we get rid of the parameters project_id and team_id, later in the program we will pass these values as inputs to the action manually. The technical term for this is Action-level Schema Processing.Python
5
Define a Custom Function to Modify Input
This function will be used to modify the input data for the
LINEAR_CREATE_LINEAR_ISSUE action. Here we have added the values for project_id and team_id parameters to the input data. By doing this, we can avoid specifying these values in the prompt and be sure that the agent uses the correct values. The technical term for this is Action-level Pre-Processing.Python
6
Define a Custom Function to Modify Output
This function will be used to modify the output data for the
LINEAR_CREATE_LINEAR_ISSUE action. Here we are modifying the output to just return the action execution status successful & the issue_id, by doing this can keep the LLM context clean. The technical term for this is Action-level Post-Processing.Python
7
Get Linear Action from Composio
When getting tools using the
get_tools() method, we need to pass the processors parameter to specify the schema, pre-processing, and post-processing functions. In this example, we’re setting up an Action-level preprocessor by mapping the LINEAR_CREATE_LINEAR_ISSUE action to our linear_schema_processor, linear_pre_processor and linear_post_processor functions defined above respectively in schema, pre, and post processors.Python
8
Invoke the agent
Python