Class: Envoy::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/envoy/runner.rb

Constant Summary collapse

ERROR_CONVENTION =
<<~TXT.freeze
  When a tool returns a JSON object with an "error" key, it failed. The
  "type" tells you why: "not_found" (no such record), "forbidden" (you may
  not do that), "invalid" (bad arguments). Explain the problem to the user
  instead of retrying blindly.
TXT

Instance Method Summary collapse

Constructor Details

#initialize(conversation:) ⇒ Runner

Returns a new instance of Runner.



10
11
12
# File 'lib/envoy/runner.rb', line 10

def initialize(conversation:)
  @conversation = conversation
end

Instance Method Details

#call(content:, &on_event) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/envoy/runner.rb', line 14

def call(content:, &on_event)
  # Repair an interrupted tail before replaying: a prior turn killed mid-flight
  # (deploy restart, OOM, timeout) can leave a blank assistant or dangling
  # tool_use that the provider rejects on every subsequent turn. Heal first so
  # one bad turn can't permanently brick the conversation.
  @conversation.heal_interrupted_tail!
  tools = compiled_tools
  Envoy.llm(conversation: @conversation)
       .run(content: content, tools: tools, instructions: instructions, &on_event)
  backfill_statuses!
end