#Managing tools context

1 messages · Page 1 of 1 (latest)

lone sable
#

most tools returns too long responses which leads to over context from llm provider (too long context)

my question: does composio provide a way to handle this automatically,

and incase not how to get expected infer type of tool response so we can handle this from our side!

code example

const { data } = await composio.tools.execute('GMAIL_FETCH_EMAILS', {})
const dataResponse = data // typeof data => Record<string, unknown>  ??
lone sable
#

@glacial zephyr 👀

tribal raven
lone sable
#

Hi @tribal raven
thanks for the reply,

**but also using afterExecution, I don't know what's inside the data, therfor can't loop over and find useless long content to ignore
**

tranquil kiteBOT
#

I understand your concern! To know what's inside the data object for a specific tool, you need to inspect the tool's output schema. Composio provides several ways to do this:

1. Get the Raw Tool Schema

You can fetch the raw tool definition to see the exact output parameters:

// Get the raw tool schema
const tool = await composio.tools.getRawComposioToolBySlug('GMAIL_FETCH_EMAILS');

// Inspect the output parameters
console.log(tool.output_parameters);

This will show you the complete structure of what the tool returns, including all fields and their types [getRawComposioToolBySlug].

2. Check the Tool Documentation

You can also view the tool's schema in the Composio documentation. For example, the Tool Type Generator documentation shows how tool schemas include detailed output_parameters with properties like:

{
  "output_parameters": {
    "properties": {
      "data": {
        "description": "Data from the action execution",
        "properties": {
          "response_data": {
            "description": "Full response with details",
            "type": "object"
          }
        }
      }
    }
  }
}

3. Practical Approach

Once you know the schema, you can create a targeted afterExecute modifier:

#
// First, inspect the schema
const tool = await composio.tools.getRawComposioToolBySlug('GMAIL_FETCH_EMAILS');
console.log(JSON.stringify(tool.output_parameters, null, 2));

// Then create your modifier based on what you see
const result = await composio.tools.execute(
  'GMAIL_FETCH_EMAILS',
  {
    userId,
    arguments: { /* your arguments */ },
  },
  {
    afterExecute: ({ toolSlug, toolkitSlug, result }) => {
      if (result.successful && result.data) {
        // Based on the schema, keep only essential fields
        // For example, if emails is an array with many fields:
        const trimmedData = {
          emails: (result.data.emails as any[] || []).map(email => ({
            id: email.id,
            subject: email.subject,
            from: email.from,
            // Add only the fields you need
          }))
        };
        return {
          ...result,
          data: trimmedData,
        };
      }
      return result;
    },
  }
);

This way, you can inspect the schema first to understand what fields are available, then create a modifier that keeps only what you need [Fetching raw tools].

lone sable
#

Just to confirm
With this approach I've to send a request for each tool I want to execute to get output params,
also will need to use a schema convert like json to zod

If so just confirm, and I think this shouldn't be the way to just get a return type of an execution !!

gusty quest
#

Would love to hear if there's a resolution to this, seems like a common issue with tools that can query large data sets

tranquil kiteBOT