Class: A2A::Server::Middleware::LimitHistoryLength
- Inherits:
-
Object
- Object
- A2A::Server::Middleware::LimitHistoryLength
- Defined in:
- lib/a2a/server/middleware/limit_history_length.rb
Overview
Resolves the effective history length limit and sets
env["a2a.history_length"] to an integer.
The server max is required. The effective limit is the minimum of the client-requested value and the server cap. When the client doesn't specify a history_length, the server cap is used.
env["a2a.history_length"] is always an Integer (0..max).
The agent applies it unconditionally:
result["history"] = task[:history]&.last(limit)
Part of the A2A::Server middleware stack — the max comes from
A2A::Server.new(history_length: 20).
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, max) ⇒ LimitHistoryLength
constructor
A new instance of LimitHistoryLength.
Constructor Details
#initialize(app, max) ⇒ LimitHistoryLength
Returns a new instance of LimitHistoryLength.
25 26 27 28 |
# File 'lib/a2a/server/middleware/limit_history_length.rb', line 25 def initialize(app, max) @app = app @max = max end |
Instance Method Details
#call(env) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/a2a/server/middleware/limit_history_length.rb', line 30 def call(env) request = env["a2a.request"] limit = @max if request.respond_to?(:history_length) && request.history_length limit = [request.history_length.to_i, @max].min end env["a2a.history_length"] = limit @app.call(env) end |