Tool Hint Service

chevron-rightRelevant source fileshashtag

The Tool Hint Service generates system message hints for LLMs, listing candidate Composio actions that match user intent. This service acts as a pre-filtering layer before tool execution, helping the LLM select the most relevant actions from 880+ apps with 12,000+ actions. For actual tool execution, see Tool Router & Execution. For tool discovery and metadata, see Tool Discovery & Resolution.


Purpose & Scope

The ComposioHintService is the single source of truth for generating action hints across all consumers (chatbot, recipe executor, workflow engine). It replaces three divergent implementations that previously existed:

  • consumers/chatbot/service.py stream methods (token ILIKE only, no safety filtering)

  • modules/agents/factory/agent_factory.py (3-tier with broken scoring)

  • Recipe executor inline logic

The service outputs system message text that lists available Composio action names, which are then injected into LLM context to guide tool selection.

Sources: orchestrator/modules/tools/services/composio_hint_service.py:1-22


Architecture Overview

spinner

Sources: orchestrator/modules/tools/services/composio_hint_service.py:89-212


Three-Tier Resolution Strategy

The service uses a hierarchical fallback strategy to match actions to user intent:

Tier
Strategy
Database Table
Fallback Condition

Tier 1

Capability-based

ComposioActionMetadata

Requires taxonomy match + metadata exists

Tier 2

Token-filtered

ComposioActionCache

Tier 1 returned 0 results + tokens extracted

Tier 3

Top-N fallback

ComposioActionCache

Tiers 1 & 2 returned 0 results (chatbot only)

Tier 1: Capability-Based Hints

Uses the capability taxonomy to match actions:

spinner

Key Implementation Details:

  • Queries ComposioActionMetadata table with capabilities.overlap() operator

  • Filters out destructive actions (destructive = False)

  • Scores by: capability matches (40%) + keyword overlap (40%) + confidence (20%)

  • Only activates when taxonomy returns specific capabilities (not generic fallback like data.query)

Sources: orchestrator/modules/tools/services/composio_hint_service.py:316-392

Tier 2: Token-Filtered Hints (Chatbot Mode)

When Tier 1 fails, uses prompt tokens with a mandatory capability gate:

spinner

Critical Fix: The capability terms act as a mandatory gate, not a score boost. This prevents irrelevant actions like SLACK_CREATE_CHANNEL_BASED_CONVERSATION from competing with SLACK_SEND_MESSAGE for messaging intents.

Sources: orchestrator/modules/tools/services/composio_hint_service.py:433-550

Tier 2 Alternative: Recipe Mode Token Hints

Recipe mode bypasses the taxonomy entirely, using pure token matching:

spinner

Key Differences from Chatbot Mode:

  • No taxonomy lookup — scales to any number of tools without manual curation

  • No capability gate — relies on the curated prompt being specific

  • Heavier name weightingJIRA_GET_ISSUE ranks high even if "get" ≠ "read"

  • Used when recipe_mode=True flag is set

Sources: orchestrator/modules/tools/services/composio_hint_service.py:397-432, orchestrator/modules/tools/services/composio_hint_service.py:152-159

Tier 3: Top-N Fallback

Only used in chatbot mode when Tiers 1 & 2 both return zero results:

  • Returns up to 10 safe actions per app (capped at 6 apps, 60 actions total)

  • Filters destructive actions (NOT ILIKE on dangerous tokens: archive, delete, etc.)

  • Orders by action_name ASC for consistency

Sources: orchestrator/modules/tools/services/composio_hint_service.py:554-626


Core Components

ComposioHintService Class

spinner

Sources: orchestrator/modules/tools/services/composio_hint_service.py:89-99, orchestrator/modules/tools/services/composio_hint_service.py:67-84

Key Method: build_hints()

Parameters:

Parameter
Type
Description

agent_id

int

Agent whose app assignments to query

prompt

str

User prompt / task text to match actions against

workspace_id

UUID (optional)

Workspace UUID to filter by connected apps

recipe_mode

bool

When True, skips taxonomy gate and uses direct token matching

Returns: ComposioHintResult with:

  • hint_lines: List of strings for LLM system message

  • matched_actions: Action names that were selected

  • strategy_used: One of "capability", "token_filtered", "recipe_token", "fallback", "none"

Sources: orchestrator/modules/tools/services/composio_hint_service.py:103-212


App Resolution Flow

Before matching actions, the service determines which apps the agent can use:

spinner

Auto-Inheritance Logic: When an agent has no explicit app assignments, it inherits all workspace-connected apps. This prevents empty tool lists when agents haven't been configured yet.

Sources: orchestrator/modules/tools/services/composio_hint_service.py:217-275


Output Format

The service generates a system message with this structure:

Key Features:

  1. Exact action names — prevents LLM from inventing names

  2. Grouped by app — easy to scan

  3. Parameter hints — top 5-10 actions get full param schemas

  4. Strong directive — triggers tool_choice="required" in OpenAI client (when the text contains "You MUST call")

Sources: orchestrator/modules/tools/services/composio_hint_service.py:137-201


Integration with Other Systems

Usage in Chat Service

spinner

The chat service calls ComposioHintService.build_hints() early in the request flow (before agent activation), then injects the result as a system message.

Sources: orchestrator/consumers/chatbot/service.py (referenced in comments)

Usage in Recipe Executor

spinner

The recipe executor uses recipe_mode=True to bypass taxonomy and rely on the curated prompt_template for token matching.

Sources: orchestrator/api/recipe_executor.py (referenced in comments)


Constants & Configuration

Token Limits

Constant
Value
Purpose

MAX_QUERY_TOKENS

10

Max tokens extracted from prompt

MAX_APPS_SEARCH

12

Max apps to query in ILIKE search

MAX_DB_ROWS_PER_APP

100

Max rows fetched per app from cache

MAX_ACTIONS_PER_APP

6

Max actions returned per app

MAX_PARAM_HINT_ACTIONS

10

Max actions with full param schemas

MAX_PARAMS_PER_ACTION

5

Max params shown per action

MAX_APPS_FALLBACK

6

Max apps in Tier 3 fallback

MAX_FALLBACK_ROWS

10

Max rows per app in fallback

Sources: orchestrator/modules/tools/services/composio_hint_service.py:54-61

Safety Filters

Sources: orchestrator/modules/tools/services/composio_hint_service.py:44-51


Database Schema Dependencies

ComposioActionMetadata (Tier 1)

Sources: orchestrator/modules/tools/capabilities/models.py (referenced in code)

ComposioActionCache (Tiers 2 & 3)

Sources: orchestrator/core/models/composio_cache.py:1-50 (model definitions)


Performance Characteristics

Query Costs by Tier

Tier
Database Queries
Typical Latency
Fallback Cost

Tier 1

1 query (metadata table)

~10-30ms

No API calls

Tier 2

1-12 queries (per-app cache)

~50-150ms

No API calls

Tier 3

1-6 queries (fallback cache)

~30-80ms

No API calls

All tiers are local database queries — no Composio API calls during hint generation. The metadata sync service (see Metadata Sync) pre-populates both tables.

Sources: orchestrator/modules/tools/services/composio_hint_service.py:1-22 (design comments)


Parameter Hint Extraction

The service extracts parameter schemas for the top 5-10 actions to provide inline documentation:

spinner

Example Output:

Sources: orchestrator/modules/tools/services/composio_hint_service.py:628-688, orchestrator/modules/tools/formatting/schema_detector.py:1-50


Error Handling & Logging

Graceful Degradation

Each tier catches exceptions and returns empty results, allowing fallback to the next tier. The service never throws exceptions to the caller.

Debug Logging

All hint generation is logged with:

  • Agent ID

  • Strategy used (capability / token_filtered / recipe_token / fallback / none)

  • Allowed apps

  • Number of matched actions

  • Number of parameter hints

Sources: orchestrator/modules/tools/services/composio_hint_service.py:203-212


Relationship to ComposioToolService

The ComposioHintService is distinct from ComposioToolService (see Tool Discovery):

Aspect
ComposioHintService
ComposioToolService

Purpose

Generate LLM hints (action selection)

Fetch action schemas for execution

Output

System message text

OpenAI function schemas

Resolution

3-tier (capability → token → fallback)

3-tier (explicit → SDK search → cache)

When Called

Before LLM invocation

During agent activation

Mode

Chatbot vs Recipe

Step execution only

Both services query the same database tables (ComposioActionMetadata, ComposioActionCache) but with different filtering logic.

Sources: orchestrator/modules/tools/services/composio_tool_service.py:1-22, orchestrator/modules/tools/services/composio_hint_service.py:1-22


Usage Examples

Chatbot Mode

Recipe Mode

Sources: orchestrator/modules/tools/services/composio_hint_service.py:103-212


Future Enhancements

Planned Improvements (from comments)

  1. Caching of capability extraction — taxonomy lookup is repeated across requests with similar intents

  2. Per-action popularity scoring — boost frequently-used actions in fallback tier

  3. Workspace-level action preferences — learn which actions users prefer per workspace

  4. Token-level caching — reuse ILIKE query results across similar prompts within a session

Sources: orchestrator/modules/tools/services/composio_hint_service.py:1-40 (design comments)


Last updated