Runtime Governance

Tool Call Nesting Depth and Runtime Limits in AI Agent Execution

Tool call nesting depth refers to how many chained or recursive tool invocations an AI agent can trigger before execution stops. Agent orchestration frameworks enforce this through recursion or iteration limits at the runtime layer, not within the model itself, to prevent runaway execution, unbounded cost, and unauditable behavior.


Defining Tool Call Nesting Depth

Tool call nesting depth describes the number of sequential or recursive tool invocations an AI agent executes within a single task before returning a final response. In agentic systems, a model does not simply answer a query. It can call a tool, receive a result, and use that result to decide whether to call another tool, which may itself trigger further calls. Nesting depth is the measure of how many of these steps occur in a chain.

No major orchestration framework currently uses "nesting depth" as a formally standardized metric. LangGraph refers to a recursion limit measured in super-steps. AWS Bedrock Agents describes orchestration iterations. Microsoft Semantic Kernel uses a maximum iteration count for auto function calling. OpenAI's function calling documentation describes multi-turn tool loops but leaves iteration control to the developer. These are functionally equivalent concepts expressed with different terminology, and most are implemented as an integer cap on steps or iterations rather than a true call-stack depth measurement.

Why Unbounded Nesting Is an Enterprise Problem

Chained tool calls create a control-flow pattern that behaves differently from a single request-response interaction. When a tool's output feeds back into the agent's reasoning and that reasoning triggers another tool call, the sequence can continue indefinitely if nothing forces it to stop. LangChain's own documentation notes that agent executors can enter infinite loops when tool outputs repeatedly generate further tool calls that never resolve to a final answer.

The operational consequences are concrete rather than theoretical. Each additional tool call and its result consumes context window tokens, so deeper chains increase both latency and cost per task, as OpenAI's documentation confirms. Uncontrolled chains also increase security exposure, since every additional tool invocation is an additional opportunity for the agent to access data or systems it was not explicitly scoped to use. OWASP's Excessive Agency category in its LLM application guidance identifies this pattern directly, describing risk that arises when agents are given functionality, permissions, or autonomy without adequate constraints.

How Runtime Environments Enforce Depth Limits

Nesting or recursion limits are enforced at the orchestration layer, meaning the agent executor or graph runtime that manages the sequence of tool calls, rather than within the underlying language model. LangGraph raises a GraphRecursionError once a configured recursion limit is exceeded. AWS Bedrock Agents supports configurable limits on the number of orchestration iterations within its agent loop. Semantic Kernel applies a maximum iteration count to its auto function calling behavior. In each case, exceeding the configured limit typically produces a runtime exception rather than a silent truncation, which allows the calling application to handle the failure explicitly.

Frameworks generally do not architecturally distinguish between linear tool chains, where calls proceed one after another, and recursive chains, where a tool call triggers another agent invocation. Both are counted against the same iteration or recursion limit. This means the limit functions as a blunt but effective backstop rather than a fine-grained structural control.

Nesting Limits Are Not a Substitute for Permission Scoping

A depth limit constrains how long a chain of tool calls can run, but it does not constrain what those calls are permitted to do. Semantic Kernel's documentation notes that function-calling loops execute under the identity and permission scope of the calling application, meaning nested calls do not automatically acquire new authorization context. In practice, this means a recursion limit can stop a runaway chain, but every call within that chain still carries whatever access the originating agent had from the start.

This distinction matters for enterprise governance. NIST's AI Risk Management Framework calls for organizations to map and manage risks from AI system behaviors, including cascading or unanticipated actions, as part of ongoing risk measurement. Treating nesting depth limits and permission scoping as separate but complementary controls, rather than assuming one substitutes for the other, aligns with that framing. A well-scoped agent with a generous depth limit may be lower risk than a narrowly-limited agent with broad, unscoped tool access.

Where Runtime Governance Fits

Nesting depth limits are one control among several needed to govern how AI agents behave at runtime. They address a specific failure mode, uncontrolled or recursive execution, but they operate independently from identity, permission scope, and audit logging. Trussed AI provides runtime governance for enterprise AI agents, including runtime policy enforcement, agent identity and permissions, least privilege controls, tool approval workflows, and audit logging. These capabilities are relevant to the concerns raised in this guide because they address the layers surrounding a depth limit, such as what an agent is authorized to do at each step and how that activity is recorded for review, rather than the iteration count itself.


What Nesting Depth Controls Address

Three practical failure modes motivate runtime depth enforcement:

Runaway Execution

Tool outputs that repeatedly trigger further tool calls without converging to a final answer.

Resource and Cost Exposure

Each nested call consumes additional context tokens and compute, increasing cost with chain depth.

Audit Complexity

Longer or recursive chains make it harder to reconstruct what an agent actually did.


Architecture Decisions That Shape Depth Control

Platform teams evaluating agent runtimes should look closely at how each framework handles the following four decisions.

  1. 1

    Enforcement layer

    Whether limits are enforced natively by the orchestration framework or require custom application-level counters.

  2. 2

    Scope of the limit

    Whether recursion or iteration limits apply globally per session or can be scoped per agent, per tool, or per request.

  3. 3

    Failure behavior

    Whether breaching the limit produces a hard error, a fallback response, or a partial result, and whether that behavior is configurable.

  4. 4

    Tracing granularity

    How each tool invocation step is logged, and whether the full sequence of nested calls can be reconstructed after the fact.


Implementation Considerations for Platform Teams

Depth limits are necessary but not sufficient. Teams implementing runtime governance for agentic systems should also account for the following:

  • Configure recursion or iteration limits explicitly rather than relying on framework defaults, since defaults vary widely across LangGraph, Bedrock Agents, and Semantic Kernel.
  • Treat a breached limit as an application-level failure to handle deliberately, not an edge case to ignore.
  • Pair depth limits with permission scoping so that nested calls cannot exceed the originating agent's authorized access.
  • Log each tool invocation individually so nested or recursive chains can be reconstructed during audit or incident review.
  • Evaluate whether limits can be scoped per agent or per tool, rather than applied only at the session level.

Govern Agent Execution Beyond Depth Limits

Nesting depth controls reduce runaway execution risk. Identity, permission scope, and audit logging determine what each call in that chain is actually allowed to do.

Explore Runtime Governance