Class: Omen::Conversation

Inherits:
Object
  • Object
show all
Defined in:
app/models/omen/conversation.rb

Overview

The one place Claude is spoken to, so everything above it is ours to read and to test.

Constant Summary collapse

MAX_TOKENS =

How many tokens one reply may run to. Thinking is on by default and spends from the same budget, so this is sized well past the JSON it has to leave room for.

16_000
SENDABLE =

What each kind of block may carry back in, since a reply handed back whole is a 400.

{
  'text' => %w[ type text ],
  'thinking' => %w[ type thinking signature ],
  'redacted_thinking' => %w[ type data ],
  'tool_use' => %w[ type id name input ],
  'tool_result' => %w[ type tool_use_id content is_error ],
}

Instance Method Summary collapse

Constructor Details

#initialize(questions) ⇒ Conversation

Returns a new instance of Conversation.

Parameters:

  • questions (ActiveRecord::Relation)

    the questions asked so far, oldest first, up to and including the one being answered.



18
19
20
# File 'app/models/omen/conversation.rb', line 18

def initialize(questions)
  @questions = questions
end

Instance Method Details

#advanceHash

No tools are sent, by design: a tool_result block would be rows travelling back to Claude.

Returns:

  • (Hash)

    the blocks Claude answered with, why it stopped, and what it cost.



24
25
26
27
28
29
30
31
32
33
# File 'app/models/omen/conversation.rb', line 24

def advance
  said = client.messages.create model: Omen.config.claude_model, max_tokens: MAX_TOKENS,
    system_: Omen::Instructions.block, messages: messages,
    output_config: Omen::Instructions.output_config

  { content: said.content.map { |block| block.to_h.deep_stringify_keys },
    stop_reason: said.stop_reason, input_usage: said.usage.input_tokens,
    output_usage: said.usage.output_tokens,
  }
end