Skip to content
Blog

Multi-Step Tool Chains: Tools That Call Other Subordinate Tools

When and how to compose composite tools in ADK — bundling multi-step validation, fetching, and transformation pipelines into single atomic operations.

Published on • November 28, 2026

AI Assistant

A common architectural trap in agent system design is forcing the foundation model to orchestrate deterministic, multi-step subroutines step by step. If resolving an address requires geocoding coordinates, querying a census tract, looking up a tax rate, and logging an audit entry, making the LLM plan and invoke each tool separately wastes tokens, inflates turn latency, and introduces unnecessary points of conversational failure. Encapsulating deterministic sequences into composite tools preserves LLM reasoning for high-level decisions.

This tutorial covers when to delegate multi-step work to code versus LLM turn orchestration, passing ToolContext through nested functions, enforcing transaction rollbacks, and establishing call-depth guardrails.

Code composition vs LLM orchestration

Choosing between an atomic composite tool and multi-turn LLM delegation depends on whether intermediate decisions require semantic reasoning:

ScenarioArchitectural approachExecution mechanismLatencyFailure modes
Fixed 3-step pipeline (e.g., validate → debit → receipt)Composite toolSingle tool function in PythonLow (1 LLM turn)Handled by code try/except
Exploratory research (e.g., search → evaluate → re-search)LLM orchestrationMultiple sequential tool callsHigh (N LLM turns)LLM halluncination / loop
Specialist delegation (e.g., coding or SQL sub-task)Sub-agent (AgentTool)Subordinate Agent executionMediumDelegation protocol issues

When a workflow follows an invariant path with zero requirement for creative judgment, write it as a composite tool.

Implementing a composite tool

A composite tool wraps multiple lower-level service functions inside a single FunctionTool definition:

from google.adk.tools import ToolContext

async def _verify_inventory(sku: str, quantity: int) -> bool:
    # Subordinate step 1: Check warehouse inventory
    return await warehouse_service.check_stock(sku, quantity)

async def _reserve_stock(sku: str, quantity: int) -> str:
    # Subordinate step 2: Hold items temporarily
    return await warehouse_service.reserve(sku, quantity)

async def _charge_customer(user_id: str, amount_cents: int) -> str:
    # Subordinate step 3: Execute payment
    return await payment_service.charge(user_id, amount_cents)

async def purchase_product_bundle(sku: str, quantity: int, ctx: ToolContext) -> dict:
    """Execute an end-to-end product purchase including stock reservation and billing.

    Args:
        sku (str): Product inventory SKU identifier.
        quantity (int): Number of units to purchase.
    """
    user_id = ctx.state.get("user:id")
    if not user_id:
        return {"status": "error", "error_message": "User session not authenticated."}

    # Step 1: Inventory check
    in_stock = await _verify_inventory(sku, quantity)
    if not in_stock:
        return {"status": "out_of_stock", "sku": sku, "requested": quantity}

    # Step 2: Hold inventory
    reservation_id = await _reserve_stock(sku, quantity)

    # Step 3: Payment processing with rollback on failure
    try:
        charge_id = await _charge_customer(user_id, amount_cents=quantity * 1500)
    except Exception as exc:
        # Compensation action (rollback)
        await warehouse_service.release_reservation(reservation_id)
        return {"status": "payment_failed", "error_message": str(exc)}

    # Save to session state for downstream turns
    ctx.state["temp:last_order_id"] = charge_id

    return {
        "status": "success",
        "order_id": charge_id,
        "reservation_id": reservation_id,
        "summary": f"Successfully purchased {quantity} units of {sku}."
    }

The model sees a single purchase_product_bundle capability. It doesn’t need to juggle reservations or manage compensation logic.

Propagating ToolContext across internal steps

When subordinate helper functions require access to session state or artifact storage, pass ToolContext explicitly down the call hierarchy:

async def _record_audit_log(action: str, ctx: ToolContext):
    session_id = ctx.session.session_id if ctx.session else "unknown"
    await audit_db.insert({"session": session_id, "action": action})

async def execute_account_migration(target_tier: str, ctx: ToolContext) -> dict:
    """Migrate the current user account to a new service tier."""
    await _record_audit_log("migration_started", ctx)
    # Proceed with migration operations...
    ctx.state["user:tier"] = target_tier
    await _record_audit_log("migration_completed", ctx)
    return {"status": "success", "new_tier": target_tier}

Depth and recursion guards

If tools invoke other tools dynamically or trigger secondary agent sub-tasks, establish strict depth counters to prevent runaway recursion:

MAX_CHAIN_DEPTH = 3

async def execute_chained_task(task_type: str, depth: int = 1) -> dict:
    if depth > MAX_CHAIN_DEPTH:
        raise RuntimeError(f"Maximum tool chaining depth of {MAX_CHAIN_DEPTH} exceeded.")
    
    # Process task and potentially call next subordinate step
    ...

Takeaways

  • Prefer composite tools over LLM multi-turn orchestration for invariant, deterministic multi-step pipelines.
  • Composite tools drastically cut token consumption and conversational latency.
  • Implement explicit rollback and compensation logic inside Python error handlers rather than expecting the LLM to recover gracefully.
  • Pass ToolContext down through private helper functions to share state access and session tracing.
  • Enforce recursion depth limits whenever tools dynamically spawn subordinate actions.

Further reading