Record Class TimeoutPolicy

java.lang.Object
java.lang.Record
com.tnsai.timeout.TimeoutPolicy
Record Components:
llmCall - ceiling for an LLM chat / streaming call
toolCall - ceiling for a single tool dispatch
mcpCall - ceiling for an MCP request to an external server
channelSend - ceiling for a single channel adapter send

public record TimeoutPolicy(Duration llmCall, Duration toolCall, Duration mcpCall, Duration channelSend) extends Record
Framework-level timeout configuration for the four call categories the framework can issue (issue #16). Centralises what was previously scattered across modules (the LLM client, MCP transport, Telegram adapter, individual tools).

Duration.ZERO means unbounded for that category — the call may run indefinitely. Negative durations are rejected.

Foundation slice: this PR ships the type. Integration into AgentBuilder.timeoutPolicy(), the LLM call path, MCP stdio transport, and channel send wraps lands as separate follow-ups so each integration ships with its own dedicated tests.

Since:
0.5.0 (issue #16)
  • Field Details

    • UNBOUNDED

      public static final Duration UNBOUNDED
      Sentinel for "no timeout" — call may run indefinitely.
  • Constructor Details

    • TimeoutPolicy

      public TimeoutPolicy(Duration llmCall, Duration toolCall, Duration mcpCall, Duration channelSend)
      Creates an instance of a TimeoutPolicy record class.
      Parameters:
      llmCall - the value for the llmCall record component
      toolCall - the value for the toolCall record component
      mcpCall - the value for the mcpCall record component
      channelSend - the value for the channelSend record component
  • Method Details

    • defaults

      public static TimeoutPolicy defaults()
      Sensible defaults rooted in observed production behaviour: LLM 60s (long generations), tool 30s (matches Tool.getTimeout() default from #18), MCP 15s (interactive snappiness), channel 10s (rate-limited backoff happens above this).
    • unbounded

      public static TimeoutPolicy unbounded()
      Every category is unbounded. Useful for batch / overnight workflows where wall-clock cost is irrelevant.
    • builder

      public static TimeoutPolicy.Builder builder()
    • toBuilder

      public TimeoutPolicy.Builder toBuilder()
      Returns a builder pre-populated with this policy's values.
    • isUnbounded

      public boolean isUnbounded(TimeoutPolicy.Category category)
      Whether the given category is unbounded under this policy.
    • get

      public Duration get(TimeoutPolicy.Category category)
      Generic accessor for the duration of a given category.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • llmCall

      public Duration llmCall()
      Returns the value of the llmCall record component.
      Returns:
      the value of the llmCall record component
    • toolCall

      public Duration toolCall()
      Returns the value of the toolCall record component.
      Returns:
      the value of the toolCall record component
    • mcpCall

      public Duration mcpCall()
      Returns the value of the mcpCall record component.
      Returns:
      the value of the mcpCall record component
    • channelSend

      public Duration channelSend()
      Returns the value of the channelSend record component.
      Returns:
      the value of the channelSend record component