Module: Rubino::ActiveAgent
- Defined in:
- lib/rubino/active_agent.rb
Overview
In-process slot holding the ONE primary agent the user has switched to for this session. Mirrors Rubino::Modes / Rubino::ActiveSkill: a process-level slot, set via the ‘/agent <name>` picker (or a bare `/<name>` for a primary) and cycled with Tab. The selected agent’s Definition (its system prompt and tool scope) is threaded into the runner each turn, so the choice actually changes the model’s persona/tools — not just a cosmetic chip.
Lives at the process level intentionally — alpha rule: no premature persistence. A fresh ‘rubino chat` boots on the registry default (“build”); an explicit switch takes effect for the rest of that process.
The slot stores the agent NAME (a String); resolution to a Definition goes through Rubino.agent_registry so a freshly registered/overridden agent is always reflected. Only PRIMARY agents are switchable here — subagents (explore/general) are invoked one-shot via ‘/<name> <message>`, never pinned.
Class Method Summary collapse
-
.current ⇒ Object
The pinned primary-agent name (String).
-
.cycle ⇒ Object
Cycle to the NEXT primary agent (Tab).
-
.default_name ⇒ Object
The registry default primary name, used as the initial value.
-
.definition ⇒ Object
The resolved Definition for the current agent, or nil if it has since gone missing (defensive — the registry is stable within a process).
-
.names ⇒ Object
The names of all switchable (primary) agents, in registry order.
-
.reset! ⇒ Object
Test/teardown hook.
-
.set(name) ⇒ Object
Pins
nameas the active primary agent.
Class Method Details
.current ⇒ Object
The pinned primary-agent name (String). Defaults to the registry’s default primary on first read.
23 24 25 |
# File 'lib/rubino/active_agent.rb', line 23 def current @current ||= default_name end |
.cycle ⇒ Object
Cycle to the NEXT primary agent (Tab). Wraps around. Returns the new name. No-op-safe when only one primary agent exists.
54 55 56 57 58 59 60 |
# File 'lib/rubino/active_agent.rb', line 54 def cycle all = names return current if all.empty? idx = all.index(current) || -1 @current = all[(idx + 1) % all.length] end |
.default_name ⇒ Object
The registry default primary name, used as the initial value.
63 64 65 |
# File 'lib/rubino/active_agent.rb', line 63 def default_name Rubino.agent_registry.default&.name end |
.definition ⇒ Object
The resolved Definition for the current agent, or nil if it has since gone missing (defensive — the registry is stable within a process).
43 44 45 |
# File 'lib/rubino/active_agent.rb', line 43 def definition Rubino.agent_registry.find(current) end |
.names ⇒ Object
The names of all switchable (primary) agents, in registry order.
48 49 50 |
# File 'lib/rubino/active_agent.rb', line 48 def names Rubino.agent_registry.primary_agents.map(&:name) end |
.reset! ⇒ Object
Test/teardown hook. Not part of the public API.
68 69 70 |
# File 'lib/rubino/active_agent.rb', line 68 def reset! @current = nil end |
.set(name) ⇒ Object
Pins name as the active primary agent. Validates against the registry’s primary agents and raises on an unknown/non-primary name so a typo surfaces immediately (parity with Modes.set). Returns the new name.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubino/active_agent.rb', line 30 def set(name) candidate = name.to_s.strip agent = Rubino.agent_registry.find(candidate) unless agent&.primary? raise ArgumentError, "unknown primary agent: #{name.inspect} (valid: #{names.join(", ")})" end @current = agent.name end |