Skip to content
agentgateway has joined the Agentic AI FoundationLearn more

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Page as Markdown

Fault injection

Inject artificial latency into requests to test how your clients and services handle slow responses.

Attaches to:

Agentgateway supports more than one configuration style. Where a feature can also be configured in the simplified llm or mcp modes, the examples on this page show each option in tabs. For more information, see Routing-based configuration.

Fault injection adds artificial latency to matching requests before agentgateway forwards them to the backend. Use it to test how your clients and upstream services behave when responses are slow, such as verifying that timeouts, retries, and client-side deadlines work as expected.

The injected delay counts against the request timeout. If the delay is longer than the configured request timeout, the request times out.

Inject a delay

Set delay.duration in the route policies. The duration can be either of the following values.

ValueDescription
A duration stringA fixed latency to inject, such as 2s or 500ms.
A CEL expressionAn expression that is evaluated against each request and returns a duration or a number of milliseconds. Use this option for conditional, probabilistic, or randomized delays. A non-positive result injects no delay.

The following example injects a fixed 2-second delay before agentgateway forwards requests to the backend.

# yaml-language-server: $schema=https://agentgateway.dev/schema/config
mcp:
  port: 3000
  policies:
    delay:
      duration: 2s
  targets:
  - name: everything
    stdio:
      cmd: npx
      args: ["@modelcontextprotocol/server-everything"]

Inject a probabilistic or random delay

Because duration accepts a CEL expression, you can inject latency into only a subset of requests, or add jitter. The expression returns either a duration or a number that is interpreted as milliseconds.

ExpressionEffect
duration("500ms")A fixed 500ms delay, expressed as a CEL duration.
random() < 0.1 ? 500 : 0A 500ms delay on approximately 10% of requests, and no delay otherwise.
int(random() * 500.0)A random delay between 0 and 500ms (jitter) on every request.

The following example delays approximately 10% of requests by 500ms.

# yaml-language-server: $schema=https://agentgateway.dev/schema/config
binds:
- port: 3000
  listeners:
  - routes:
    - policies:
        delay:
          duration: "random() < 0.1 ? 500 : 0"
      backends:
      - host: localhost:8080
Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.