Skip to main content

Tool Chaining

Hunch supports intelligent multi-tool chaining, allowing the AI to automatically execute multiple tools in sequence based on user intent, with results from one tool flowing into the next.

How Tool Chaining Works

When a user request requires multiple actions, the AI can:

  1. Detect chaining intent - Recognize when multiple actions are needed
  2. Execute sequentially - Run tools in the correct order
  3. Pass results - Use output from one tool as input to the next
  4. Synthesize response - Provide a unified response with all results

Examples

Shopping Flow

User: "Find a red sweater and add it to my cart"

AI: Executes search_products → add_to_cart

Result: "Found the red sweater! I've added it to your cart."

Booking Flow

User: "Check if you have the blue shirt in size M, and if so, book an appointment"

AI: Executes check_inventory → book_calendly_appointment

Result: "Yes, the blue shirt is available! I've booked your appointment."

Newsletter + Lead

User: "Subscribe me to the newsletter and notify your team"

AI: Executes subscribe_newsletter → send_lead_notification

Result: "You're subscribed! Our team has been notified."

Context Sharing

Tools automatically share context through the Tool State Manager:

Cart State

  • Products added to cart persist across tools
  • Cart can be checked at any point
  • Checkout tool can access full cart contents

Previous Results

  • Each tool's result is stored
  • Subsequent tools can reference prior results
  • Context is preserved for the session

User Context

  • Email, name, and ID available to all tools
  • Tools can personalize based on user data
  • Context updates as user provides information

Supported Chains

E-commerce

ChainToolsDescription
Search → Add to Cartsearch_products, add_to_cartFind and purchase
Add → Checkoutadd_to_cart, get_cart, checkoutComplete purchase
Inventory → Bookcheck_shopify_inventory, book_calendly_appointmentCheck availability and book

Scheduling

ChainToolsDescription
Check → Bookcheck_calendly_availability, book_calendly_appointmentFind and book
Search → Schedulesearch_products, book_calendly_appointmentProduct inquiry to booking

Lead Capture

ChainToolsDescription
Subscribe → Notifysubscribe_newsletter, send_lead_notificationNewsletter with alert
Contact → CRMsubmit_contact_form, create_crm_leadForm submission pipeline

Implementation

Frontend Integration

The embed widget automatically handles tool chaining - no additional configuration needed.

API Integration

For custom implementations, use the /llm/tool-chain endpoint:

POST /api/llm/tool-chain
{
"website_id": "abc123",
"session_id": "session_xyz",
"messages": [
{ "role": "user", "content": "Find red sweater and add to cart" }
],
"tools": [...],
"tool_results": [
{ "toolName": "search_products", "result": { "products": [...] } }
],
"continue_chain": true
}

Configuration

Chain Length Limits

  • Default: 5 tools per chain
  • Configurable per plan
  • Prevents infinite loops

Context Injection

Results are automatically injected into subsequent tools.

Critical Tool Handling

If a critical tool (checkout, payment, booking) fails, the chain stops.

Best Practices

  1. Enable relevant tools - More tools = better chaining
  2. Test flows - Verify chains work for common user journeys
  3. Monitor usage - Track which chains are most popular
  4. Handle failures - Provide fallback options when chains fail