Class: AgUi::Terminals::RubyLLM

Inherits:
Object
  • Object
show all
Defined in:
lib/ag_ui/terminals/ruby_llm.rb

Overview

The ruby_llm terminal — the LLM call at the bottom of the brute pipeline. NOT required by lib/ag_ui.rb (the gem core stays LLM-agnostic); opt in with:

require "ag_ui/terminals/ruby_llm"

RubyLLM.configure { |c| c.anthropic_api_key = ENV["ANTHROPIC_API_KEY"] }
terminal = AgUi::Terminals::RubyLLM.new
agent = Brute.agent.use(...).run(terminal)   # standard Brute agent

One assistant turn per call: seeds the chat from env (including prior tool-call turns), registers env as schema-only CLIENT tools (they halt — never execute server-side), streams text deltas into env, then appends either the assistant text or the assistant tool-call message to env for the ToolRouter to route.

Accepts the host app's "anthropic/claude-sonnet-4-5" env form or a bare ruby_llm model id.

Defined Under Namespace

Classes: ClientTool, TurnEmitter

Instance Method Summary collapse

Constructor Details

#initialize(model: "anthropic/claude-sonnet-4-5", thinking: nil, chat_factory: nil) ⇒ RubyLLM

thinking: effort: or budget: enables extended thinking (ruby_llm with_thinking); its deltas stream as REASONING_* events.



32
33
34
35
36
# File 'lib/ag_ui/terminals/ruby_llm.rb', line 32

def initialize(model: "anthropic/claude-sonnet-4-5", thinking: nil, chat_factory: nil)
  @provider, @model = split_model(model)
  @thinking = thinking
  @chat_factory = chat_factory || default_chat_factory
end

Instance Method Details

#call(env) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ag_ui/terminals/ruby_llm.rb', line 38

def call(env)
  chat = @chat_factory.call(model: @model, provider: @provider)
  if @thinking
    chat.with_thinking(**@thinking)
  end
  register_client_tools(chat, env[:tools])
  apply_tool_choice(chat, env)
  seed(chat, env[:messages])

  emitter = TurnEmitter.new(env[:events])
  chat.complete do |chunk|
    thinking = chunk.thinking
    if thinking&.text
      emitter.thinking_delta(thinking.text.to_s)
    end
    emitter.text_delta(chunk.content.to_s)
  end
  emitter.finish

  conclude(chat, env)
  env
end

#to_procObject



61
62
63
# File 'lib/ag_ui/terminals/ruby_llm.rb', line 61

def to_proc
  method(:call).to_proc
end