class Riffer::Agent::Context
Typed value object wrapping the runtime context Hash held by a Riffer::Agent. Exposes typed skills, token_usage, mcp_progressive_tools, and discovered_tools accessors while preserving [] / dig for caller-provided keys.
Constants
- RESERVED_KEYS
-
@rbs @data: Hash[Symbol, untyped]
Public Class Methods
Source
# File lib/riffer/agent/context.rb, line 16 def initialize(data = {}) reserved = data.keys & RESERVED_KEYS if reserved.any? raise Riffer::ArgumentError, "Reserved keys cannot be passed in context: #{reserved.join(", ")}" end @data = data.dup @data[:skills] = nil @data[:token_usage] = nil @data[:mcp_progressive_tools] = nil @data[:discovered_tools] = nil end
Builds a new context. The caller Hash is duped so later caller mutations donโt leak in. Raises Riffer::ArgumentError if it contains a reserved key.
Public Instance Methods
Source
# File lib/riffer/agent/context.rb, line 76 def [](key) @data[key] end
Hash-style read, preserved so tools can pull caller-provided keys via context[:agent].
Source
# File lib/riffer/agent/context.rb, line 129 def discover_tools(tools) existing = @data[:discovered_tools] || [] @data[:discovered_tools] = (existing + tools).uniq(&:name) end
Accumulates newly discovered MCP tool classes, deduplicating by name. Each call extends the existing set; calling multiple times is safe.
Source
# File lib/riffer/agent/context.rb, line 106 def discovered_tools @data[:discovered_tools] end
MCP tool classes discovered during progressive search. Accumulates across generate calls and is merged into the active tool list on every LLM call.
Source
# File lib/riffer/agent/context.rb, line 113 def discovered_tools=(value) valid = value.nil? || ( value.is_a?(Array) && value.all? { |tool| tool.is_a?(Class) && tool < Riffer::Tool } ) unless valid raise Riffer::ArgumentError, "discovered_tools must be an Array of Riffer::Tool subclasses or nil, got #{value.class}" end @data[:discovered_tools] = value end
Sets the discovered tools array. Raises Riffer::ArgumentError on an invalid value.
Source
# File lib/riffer/agent/context.rb, line 83 def mcp_progressive_tools @data[:mcp_progressive_tools] end
Auth-wrapped MCP tool classes for progressive discovery, or nil.
Source
# File lib/riffer/agent/context.rb, line 90 def mcp_progressive_tools=(value) valid = value.nil? || ( value.is_a?(Array) && value.all? { |tool| tool.is_a?(Class) && tool < Riffer::Tool } ) unless valid raise Riffer::ArgumentError, "mcp_progressive_tools must be an Array of Riffer::Tool subclasses or nil, got #{value.class}" end @data[:mcp_progressive_tools] = value end
Sets progressive MCP tools. Raises Riffer::ArgumentError on an invalid value.
Source
# File lib/riffer/agent/context.rb, line 35 def skills @data[:skills] end
The agentโs resolved Riffer::Skills::Context, or nil when skills are not configured.
Source
# File lib/riffer/agent/context.rb, line 43 def skills=(value) unless value.nil? || value.is_a?(Riffer::Skills::Context) raise Riffer::ArgumentError, "skills must be a Riffer::Skills::Context or nil, got #{value.class}" end @data[:skills] = value end
Sets the resolved skills context. Raises Riffer::ArgumentError on an invalid value.
Source
# File lib/riffer/agent/context.rb, line 144 def to_h @data.dup end
Returns a copy of the underlying Hash; mutating it does not affect this context.
Source
# File lib/riffer/agent/context.rb, line 56 def token_usage @data[:token_usage] end
The cumulative Riffer::Providers::TokenUsage across every Run on this agent, or nil before the first response is recorded.
Source
# File lib/riffer/agent/context.rb, line 64 def token_usage=(value) unless value.nil? || value.is_a?(Riffer::Providers::TokenUsage) raise Riffer::ArgumentError, "token_usage must be a Riffer::Providers::TokenUsage or nil, got #{value.class}" end @data[:token_usage] = value end
Sets the cumulative token usage. Raises Riffer::ArgumentError on an invalid value.