Class: Nexo::Loops::RubyLLM

Inherits:
Nexo::Loop show all
Defined in:
lib/nexo/loops/ruby_llm.rb

Overview

The default, provider-neutral loop. It is the Spec 1 Agent#prompt body extracted verbatim: build the agent's chat (with its four sandbox-backed tools) and let ruby_llm run the whole tool loop inside #ask. It works identically on any +ruby_llm+-supported model — Anthropic, OpenAI, Gemini, Ollama/Gemma — because file/shell capability comes entirely from the agent's own sandbox-backed tools, not from anything vendor-specific here.

Tool-call observability (not a hard cap — see the turn-cap caveat in the README) is wired through +ruby_llm+'s +before_tool_call+/+after_tool_result+ callbacks when the installed version exposes them, and is silently omitted otherwise so an older/newer ruby_llm degrades to no observability rather than crashing.

Instance Method Summary collapse

Instance Method Details

#run(agent:, prompt:, max_turns: 25, chat: nil, &on_event) ⇒ Object

chat: lets a Nexo::Session inject the hydrated, continuing chat so the loop runs over the persisted thread; left nil it builds the agent's own fresh chat exactly as before — the default (no-session) path is unchanged.



25
26
27
28
29
30
31
32
33
# File 'lib/nexo/loops/ruby_llm.rb', line 25

def run(agent:, prompt:, max_turns: 25, chat: nil, &on_event)
  chat ||= agent.chat

  wire_observability(chat, &on_event)

  response = chat.ask(prompt)
  on_event&.call(:done, response)
  response
end