class Riffer::ToolRuntime
Riffer::ToolRuntime handles tool call execution for an agent.
Composes with a Riffer::Runner for concurrency control and provides execute as the sole public entry point.
Subclass and override dispatch_tool_call to customize how individual tool calls are dispatched (e.g., HTTP, gRPC).
runtime = Riffer::ToolRuntime::Inline.new results = runtime.execute(tool_calls, tools: tools, context: context)
Public Class Methods
Source
# File lib/riffer/tool_runtime.rb, line 25 def initialize(runner:) raise NotImplementedError, "#{self.class} is abstract — use a subclass like Riffer::ToolRuntime::Inline" if instance_of?(Riffer::ToolRuntime) @runner = runner end
- runner
-
the concurrency runner to use for batch execution.
Subclasses must provide a runner; instantiating ToolRuntime directly raises NotImplementedError.
Public Instance Methods
Source
# File lib/riffer/tool_runtime.rb, line 65 def around_tool_call(tool_call, context:) yield end
Hook that wraps each tool call execution. Override in subclasses to customize. Must yield to continue execution.
The default implementation simply yields.
class InstrumentedRuntime < Riffer::ToolRuntime::Inline private def around_tool_call(tool_call, context:) start = Time.now result = yield Rails.logger.info("Tool #{tool_call.name} took #{Time.now - start}s") result end end
Source
# File lib/riffer/tool_runtime.rb, line 38 def execute(tool_calls, tools:, context:) @runner.map(tool_calls, context: context) do |tool_call| result = around_tool_call(tool_call, context: context) do dispatch_tool_call(tool_call, tools: tools, context: context) end [tool_call, result] end end
Executes a batch of tool calls, returning [tool_call, response] pairs.
- tool_calls
-
the tool calls to execute.
- tools
-
the resolved tool classes.
- context
-
the context hash.