Class: Prescient::Agent::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/prescient/agent/context.rb

Overview

Per-run, bounded conversation history rendered as provider context.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#messagesObject (readonly)

Returns the value of attribute messages.



7
8
9
# File 'lib/prescient/agent/context.rb', line 7

def messages
  @messages
end

Instance Method Details

#append(role:, content:) ⇒ void

This method returns an undefined value.

Append a bounded turn to the run history.

Parameters:

  • role (String)

    Message role

  • content (String)

    Message content



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_aArray<Hash>

Return a copy of the provider-compatible history.

Returns:

  • (Array<Hash>)


29
30
31
# File 'lib/prescient/agent/context.rb', line 29

def to_a
  @messages.map(&:dup)
end