Skip to main content

Tool Execution Flow

This page describes the complete lifecycle of a user message, from input to final response.

Sequence

Customer          App (Chat UI)         LLM Proxy           LLM Provider
│ │ │ │
│ "Add milk to │ │ │
│ my cart" │ │ │
│──────────────────▶│ │ │
│ │ │ │
│ │ POST /chat/v1/ │ │
│ │ conversation │ │
│ │ {messages, tools, │ │
│ │ systemPrompt, │ │
│ │ context} │ │
│ │───────────────────▶│ │
│ │ │ │
│ │ │ Send to LLM with │
│ │ │ base prompt + │
│ │ │ extension + tools │
│ │ │───────────────────▶│
│ │ │ │
│ │ │ Response: │
│ │ │ tool_call: │
│ │ │ search_products │
│ │ │ {query: "milk"} │
│ │ │◀───────────────────│
│ │ │ │
│ │ tool_call: │ │
│ │ search_products │ │
│ │ {query: "milk"} │ │
│ │◀──────────────────│ │
│ │ │ │
│ │ Execute locally │ │
│ │ via MCP Server │ │
│ │ (Hybris search) │ │
│ │ │ │
│ │ tool_result: │ │
│ │ {products: [...]} │ │
│ │───────────────────▶│ │
│ │ │ │
│ │ │ tool_result + │
│ │ │ continue │
│ │ │───────────────────▶│
│ │ │ │
│ │ │ Response: │
│ │ │ tool_call: │
│ │ │ add_to_cart │
│ │ │ {code: "...", │
│ │ │ qty: 1} │
│ │ │◀───────────────────│
│ │ │ │
│ │ (execute locally) │ │
│ │ ... │ │
│ │ tool_result │ │
│ │───────────────────▶│───────────────────▶│
│ │ │ │
│ │ │ "I've added │
│ │ │ Full Cream Milk │
│ │ │ to your cart!" │
│ │ │◀───────────────────│
│ │ │ │
│ │ Final response │ │
│ │◀──────────────────│ │
│ │ │ │
│ "I've added │ │ │
│ Full Cream Milk │ │ │
│ to your cart!" │ │ │
│◀─────────────────│ │ │

Key Points

Tool call loop

The LLM can make multiple tool calls in sequence. For example, "add milk and bread" might result in:

  1. search_products("milk") → results
  2. add_to_cart(milk_code) → success
  3. search_products("bread") → results
  4. add_to_cart(bread_code) → success
  5. Final text response

The loop continues until the LLM returns a text response with no tool calls, or a safety limit is hit.

Safety limits

LimitValuePurpose
Max tool turns per request50Prevents infinite tool call loops
Max tool turns per session200Prevents runaway sessions (Android)
Rate limit30 req/minPrevents abuse

Local execution

Tools execute inside the app using existing services:

  • search_products → Hybris product search API
  • add_to_cart → Cart manager (Hybris cart API)
  • get_cart → Local cart state + Hybris refresh
  • Navigation tools → App coordinator / navigation controller

This means tool execution has zero additional network latency beyond what the app's existing services require.

iOS vs Android execution differences

AspectiOSAndroid
MCP ServerEcommerceMCPServer (single server)EcommerceMCPServerImpl + AppMCPServerImpl (two servers via router)
Tool routingSwitch statement in single serverMCPToolRouter aggregates multiple servers
NavigationNot exposed as tools (coordinator pattern)Exposed as 8 navigation MCP tools
UI displayshow_cart / show_products toolsNot yet implemented — text responses only
Division scopingVia DivisionalContainerVia @DivisionScope Dagger scoping