Class: Prescient::Agent::Context
- Inherits:
-
Object
- Object
- Prescient::Agent::Context
- Defined in:
- lib/prescient/agent/context.rb
Overview
Per-run, bounded conversation history rendered as provider context.
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
-
#append(role:, content:) ⇒ void
Append a bounded turn to the run history.
-
#initialize(system_prompt:, task:, max_bytes: Configuration::DEFAULT_MAX_CONTEXT_BYTES) ⇒ Context
constructor
A new instance of Context.
-
#to_a ⇒ Array<Hash>
Return a copy of the provider-compatible history.
Constructor Details
#initialize(system_prompt:, task:, max_bytes: Configuration::DEFAULT_MAX_CONTEXT_BYTES) ⇒ Context
Returns a new instance of Context.
9 10 11 12 13 14 15 16 |
# File 'lib/prescient/agent/context.rb', line 9 def initialize(system_prompt:, task:, max_bytes: Configuration::DEFAULT_MAX_CONTEXT_BYTES) @max_bytes = max_bytes @messages = [ { role: "system", content: system_prompt }, { role: "user", content: task } ] enforce_limit! end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
7 8 9 |
# File 'lib/prescient/agent/context.rb', line 7 def @messages end |
Instance Method Details
#append(role:, content:) ⇒ void
This method returns an undefined value.
Append a bounded turn to the run history.
22 23 24 25 |
# File 'lib/prescient/agent/context.rb', line 22 def append(role:, content:) @messages << { role: role, content: content.to_s } enforce_limit! end |
#to_a ⇒ Array<Hash>
Return a copy of the provider-compatible history.
29 30 31 |
# File 'lib/prescient/agent/context.rb', line 29 def to_a @messages.map(&:dup) end |