Class LlmChaosProfile


public class LlmChaosProfile extends ObjectWithJsonToString
Declarative fault/chaos injection for an HttpLlmResponse, for testing agent resilience: probabilistic provider errors (e.g. 429/529 with a Retry-After header), mid-stream truncation, and malformed SSE chunks.

Determinism: with errorProbability of 1.0 (always) or 0.0/null (never) the error decision is fully deterministic. A fractional probability draws once per response; set seed to make that single draw reproducible (note: a fixed seed yields the same decision every time). Truncation and malformed-SSE are deterministic. Follows the model field/withX/getter convention so it round-trips without a bespoke (de)serializer.

It also carries an optional stateful request quota (a fixed-window rate limit): when quotaName, quotaLimit, and quotaWindowMillis are set, requests beyond quotaLimit within the window are rejected with quotaErrorStatus (default 429) and the retryAfter header. Unlike the probabilistic error this is deterministic and counts real requests across the process (see LlmQuotaRegistry); expectations sharing a quotaName share one counter.

A separate token-based quota (tokenQuotaLimit + tokenQuotaWindowMillis) models TPM/TPD limits: the cumulative token count of each response is charged against the window and a 429 is returned when the sum exceeds the limit. Both request-count and token quotas can be active simultaneously on the same profile (they use independent counters within the registry, namespaced by suffix).

  • Constructor Details

    • LlmChaosProfile

      public LlmChaosProfile()
  • Method Details

    • llmChaosProfile

      public static LlmChaosProfile llmChaosProfile()
    • withErrorStatus

      public LlmChaosProfile withErrorStatus(Integer errorStatus)
    • getErrorStatus

      public Integer getErrorStatus()
    • withRetryAfter

      public LlmChaosProfile withRetryAfter(String retryAfter)
    • getRetryAfter

      public String getRetryAfter()
    • withErrorProbability

      public LlmChaosProfile withErrorProbability(Double errorProbability)
    • getErrorProbability

      public Double getErrorProbability()
    • withTruncateMode

      public LlmChaosProfile withTruncateMode(LlmChaosProfile.TruncateMode truncateMode)
    • getTruncateMode

      public LlmChaosProfile.TruncateMode getTruncateMode()
    • withTruncateAtFraction

      public LlmChaosProfile withTruncateAtFraction(Double truncateAtFraction)
    • getTruncateAtFraction

      public Double getTruncateAtFraction()
    • withMalformedSse

      public LlmChaosProfile withMalformedSse(Boolean malformedSse)
    • getMalformedSse

      public Boolean getMalformedSse()
    • withSeed

      public LlmChaosProfile withSeed(Long seed)
    • getSeed

      public Long getSeed()
    • withQuotaName

      public LlmChaosProfile withQuotaName(String quotaName)
    • getQuotaName

      public String getQuotaName()
    • withQuotaLimit

      public LlmChaosProfile withQuotaLimit(Integer quotaLimit)
    • getQuotaLimit

      public Integer getQuotaLimit()
    • withQuotaWindowMillis

      public LlmChaosProfile withQuotaWindowMillis(Long quotaWindowMillis)
    • getQuotaWindowMillis

      public Long getQuotaWindowMillis()
    • withQuotaErrorStatus

      public LlmChaosProfile withQuotaErrorStatus(Integer quotaErrorStatus)
    • getQuotaErrorStatus

      public Integer getQuotaErrorStatus()
    • withTokenQuotaLimit

      public LlmChaosProfile withTokenQuotaLimit(Long tokenQuotaLimit)
      Maximum tokens allowed within the token quota window (TPM or TPD depending on window size). Requires quotaName and tokenQuotaWindowMillis to be set. Uses the same quotaErrorStatus and retryAfter as the request-count quota.
    • getTokenQuotaLimit

      public Long getTokenQuotaLimit()
    • withTokenQuotaWindowMillis

      public LlmChaosProfile withTokenQuotaWindowMillis(Long tokenQuotaWindowMillis)
      Window length in milliseconds for the token-based quota. Requires quotaName and tokenQuotaLimit to be set.
    • getTokenQuotaWindowMillis

      public Long getTokenQuotaWindowMillis()
    • withErrorKind

      public LlmChaosProfile withErrorKind(String errorKind)
      Optional provider-specific error shape. When set to OVERLOAD, RATE_LIMIT, or SERVER_ERROR, an injected chaos / quota error emits the active provider's distinct error body (e.g. Anthropic's overloaded_error at HTTP 529, OpenAI's rate_limit_exceeded envelope), so client SDK retry/backoff logic that parses the body can be tested faithfully. When unset (or the provider is unknown), the generic chaos body is used and any explicit errorStatus/quotaErrorStatus still applies. An explicit status, when set, overrides the provider's natural status for the kind while keeping the provider-correct body. Case-insensitive; an unrecognised value falls back to the generic body.
    • getErrorKind

      public String getErrorKind()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class ObjectWithReflectiveEqualsHashCodeToString
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class ObjectWithReflectiveEqualsHashCodeToString