Class: Riffer::Tools::Runtime
- Inherits:
-
Object
- Object
- Riffer::Tools::Runtime
- Defined in:
- lib/riffer/tools/runtime.rb
Overview
Handles tool call execution for an agent, composing with a Riffer::Runner for concurrency. Subclass and override dispatch_tool_call to customize dispatch (e.g. HTTP, gRPC).
Defined Under Namespace
Classes: Fibers, Inline, Threaded
Instance Method Summary collapse
-
#around_tool_call(tool_call, context:, assistant_message: nil) ⇒ Object
Hook wrapping each tool call; override in subclasses to instrument or customize.
-
#execute(tool_calls, tools:, context:, assistant_message: nil) ⇒ Object
Executes a batch of tool calls, returning
[tool_call, response]pairs. -
#initialize(runner:) ⇒ Runtime
constructor
– : (runner: Riffer::Runner) -> void.
Constructor Details
#initialize(runner:) ⇒ Runtime
– : (runner: Riffer::Runner) -> void
14 15 16 17 |
# File 'lib/riffer/tools/runtime.rb', line 14 def initialize(runner:) raise NotImplementedError, "#{self.class} is abstract — use a subclass like Riffer::Tools::Runtime::Inline" if instance_of?(Riffer::Tools::Runtime) @runner = runner end |
Instance Method Details
#around_tool_call(tool_call, context:, assistant_message: nil) ⇒ Object
Hook wrapping each tool call; override in subclasses to instrument or customize. Must yield to continue.
class InstrumentedRuntime < Riffer::Tools::Runtime::Inline
private
def around_tool_call(tool_call, context:, assistant_message: nil)
start = Time.now
result = yield
Rails.logger.info("Tool #{tool_call.name} took #{Time.now - start}s")
result
end
end
– : (Riffer::Messages::Assistant::ToolCall, context: Riffer::Agent::Context?, ?assistant_message: Riffer::Messages::Assistant?) { () -> Riffer::Tools::Response } -> Riffer::Tools::Response
47 48 49 |
# File 'lib/riffer/tools/runtime.rb', line 47 def around_tool_call(tool_call, context:, assistant_message: nil) yield end |
#execute(tool_calls, tools:, context:, assistant_message: nil) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/riffer/tools/runtime.rb', line 22 def execute(tool_calls, tools:, context:, assistant_message: nil) @runner.map(tool_calls, context: context) do |tool_call| result = around_tool_call(tool_call, context: context, assistant_message: ) do dispatch_tool_call(tool_call, tools: tools, context: context, assistant_message: ) end [tool_call, result] end end |