Class: ActionAgent::TraceInteractionSerializer
- Inherits:
-
Object
- Object
- ActionAgent::TraceInteractionSerializer
- Defined in:
- app/serializers/action_agent/trace_interaction_serializer.rb
Overview
Reconstructs a conversation stream from a telemetry trace, in the shape the dashboard's Interactions view already renders for platform-executed agents.
Interactions normally reads solid_agent persistence (AgentContext / AgentMessage / AgentGeneration), which only exists for agents the platform ran itself. Agents running inside a customer's own app — a RubyLLM chat reporting through the telemetry endpoint, say — never write those tables, so the view was blind to them.
The spans carry the same story when the reporter opts into content capture:
the llm span holds llm.prompt / llm.instructions / llm.completion, and
each tool span holds tool.arguments / tool.result. Ordering them by start
time yields prompt → tool call → tool result → response.
Class Method Summary collapse
Instance Method Summary collapse
- #detail ⇒ Object
-
#initialize(trace) ⇒ TraceInteractionSerializer
constructor
A new instance of TraceInteractionSerializer.
- #summary ⇒ Object
Constructor Details
#initialize(trace) ⇒ TraceInteractionSerializer
Returns a new instance of TraceInteractionSerializer.
26 27 28 29 |
# File 'app/serializers/action_agent/trace_interaction_serializer.rb', line 26 def initialize(trace) @trace = trace @spans = Array(trace.spans) end |
Class Method Details
.detail(trace) ⇒ Object
22 23 24 |
# File 'app/serializers/action_agent/trace_interaction_serializer.rb', line 22 def self.detail(trace) new(trace).detail end |
.summary(trace) ⇒ Object
18 19 20 |
# File 'app/serializers/action_agent/trace_interaction_serializer.rb', line 18 def self.summary(trace) new(trace).summary end |
Instance Method Details
#detail ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/serializers/action_agent/trace_interaction_serializer.rb', line 59 def detail summary.merge( instructions: llm_attribute("llm.instructions") || any_attribute("prompt.input.instructions"), messages: , generations: generations ) end |
#summary ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/serializers/action_agent/trace_interaction_serializer.rb', line 31 def summary { id: "trace-#{@trace.id}", source: "telemetry", agent_name: @trace.agent_class, action_name: @trace.agent_action, display_name: @trace.display_name, agent: nil, service_name: @trace.service_name, environment: @trace.environment, model: @trace.model, tokens: { input: @trace.total_input_tokens, output: @trace.total_output_tokens, total: @trace.total_input_tokens.to_i + @trace.total_output_tokens.to_i }, message_count: .size, preview: preview, # Tool activity is known even when content capture is off, so a run # reported without prompts still shows what it did. tool_count: tool_spans.size, duration_ms: @trace.total_duration_ms&.to_f, generation_count: llm_spans.size, created_at: @trace..iso8601, last_activity_at: @trace..iso8601 } end |