Class: AgUi::Middleware::SystemPrompt
- Inherits:
-
Object
- Object
- AgUi::Middleware::SystemPrompt
- Defined in:
- lib/ag_ui/middleware/system_prompt.rb
Overview
Brute-style turn middleware: prepends the agent's system prompt, with the run's RunAgentInput.context entries appended as a context addendum (useAgentContext — how the agent "sees" the current page).
Skips entirely when the history already carries a system message (the client can send its own via system/developer roles).
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, prompt: nil, context: nil) ⇒ SystemPrompt
constructor
A new instance of SystemPrompt.
Constructor Details
#initialize(app, prompt: nil, context: nil) ⇒ SystemPrompt
Returns a new instance of SystemPrompt.
15 16 17 18 19 |
# File 'lib/ag_ui/middleware/system_prompt.rb', line 15 def initialize(app, prompt: nil, context: nil) @app = app @prompt = prompt @context = context end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ag_ui/middleware/system_prompt.rb', line 21 def call(env) unless env[:messages].any? { |m| m.role == :system } content = [@prompt, context_addendum].compact.join("\n\n") unless content.empty? env[:messages].unshift(Brute::Message.new(role: :system, content: content)) end end @app.call(env) end |