Class: Brute::Middleware::OTel::ToolCalls
- Defined in:
- lib/brute/middleware/otel/tool_calls.rb
Overview
Records tool calls the LLM requested as span events.
Runs POST-call: after the LLM responds, inspects ctx.functions for any tool calls the model wants to make, and adds a span event for each one with the tool name, call ID, and arguments.
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Brute::Middleware::Base
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/brute/middleware/otel/tool_calls.rb', line 18 def call(env) response = @app.call(env) span = env[:span] if span functions = env[:context].functions if functions && !functions.empty? span.set_attribute("brute.tool_calls.count", functions.size) functions.each do |fn| attrs = { "tool.name" => fn.name.to_s, "tool.id" => fn.id.to_s, } args = fn.arguments attrs["tool.arguments"] = args.to_json if args span.add_event("tool_call", attributes: attrs) end end end response end |