Class: Brute::Middleware::Summarize
- Inherits:
-
Object
- Object
- Brute::Middleware::Summarize
- Defined in:
- lib/brute/middleware/004_summarize.rb
Overview
Runs a final tool-free LLM call after the ToolResultLoop completes, ensuring the agent produces a clean summary response.
This middleware sits above ToolResultLoop in the stack. After the tool loop finishes (either naturally or via MaxIterations), Summarize injects a summary prompt and calls the inner stack one more time with tools removed. The LLM responds with text only, giving the agent a proper final answer.
Stack order:
use Summarize
use ToolResultLoop
use MaxIterations
use ToolCall
run LLMCall.new
Constant Summary collapse
- DEFAULT_PROMPT =
"Provide your complete findings based on everything you've explored."
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, prompt: DEFAULT_PROMPT) ⇒ Summarize
constructor
A new instance of Summarize.
Constructor Details
#initialize(app, prompt: DEFAULT_PROMPT) ⇒ Summarize
Returns a new instance of Summarize.
28 29 30 31 |
# File 'lib/brute/middleware/004_summarize.rb', line 28 def initialize(app, prompt: DEFAULT_PROMPT) @app = app @prompt = prompt end |
Instance Method Details
#call(env) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/brute/middleware/004_summarize.rb', line 33 def call(env) @app.call(env) saved_tools = env[:tools] env[:tools] = [] env[:current_iteration] = 1 env[:messages] << RubyLLM::Message.new(role: :user, content: @prompt) @app.call(env) env[:tools] = saved_tools env end |