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. max_turns is a BUDGET, not a hard stop. ruby_llm runs the whole tool loop inside #ask and its callbacks cannot halt it, so this loop cannot cut a run short. What it can do is COUNT the tool calls and say so: exceeding the budget emits a :turn_limit_exceeded event (once) carrying the count and the limit.

Previously the parameter was accepted and never read, which made it look like a safety bound it has never been. Treat it as telemetry: if you need a hard ceiling, bound the work inside your tools, or use Loops::AgentSDK whose engine enforces its own max_turns natively.



34
35
36
37
38
39
40
41
42
# File 'lib/nexo/loops/ruby_llm.rb', line 34

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

  wire_observability(chat, max_turns: max_turns, &on_event)

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