Class AgentTrace
java.lang.Object
ai.redouble.demo.AgentTrace
- All Implemented Interfaces:
JobObserver<JobEvent>
One agent run, streamed to the browser as it happens: an observer on the runtime's message
bus, scoped to the run's workflow, that writes every event of the run and of every job
under it - the model turns, the tool calls, the sub-agents - as one line of
newline-delimited JSON, so a page draws the run as a timeline while it is on. Every line
names its job (id, parent, type, display name, the turn it belongs to), so the page
rebuilds the tree and shows the calls of one turn side by side. A model turn's completion
carries what the model decided - its reasoning, the tool calls it asked for, whether it
answered - and what the call cost; a tool's first line carries the arguments the model
gave it, paired from the turn's decision by order and name, and its completion carries
the result as the tool returned it. The run's totals ride on every terminal line, summed
the way the benchmark's rows are. The last line is the answer with the totals, or the
failure, written when the run's own terminal event comes through the bus - after every
line before it, since the bus delivers in order and the dispatcher publishes the terminal
event before it settles the handle. A browser that leaves stops the lines and nothing
else: the run goes on to its end on the runtime.
The logic is the demo's, shared by every host: a host supplies how a line reaches the
client (sink), how the stream is closed (onEnd), and its own JSON serializer
(toJson), so the wire is the framework's while the trace is one. The serializer is the
host's rather than the runtime's because the page reads the answer's fields as the host's
mapper names them (skillsUsed, not the runtime's snake case).
- Since:
- 0.1 (2026-09-25)
- Author:
- Andrey Santrosyan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether the stream ended within the wait: the run's own terminal event came through and wrote the last line.voidThe last line when the run itself failed, then the stream closes.Returns a predicate for filtering events at the MessageBus level.voidProcess a job event.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface JobObserver
isStale
-
Constructor Details
-
AgentTrace
public AgentTrace(Function<Object, String> toJson, String workflowId, String agentJobId, Consumer<String> sink, Runnable onEnd) - Parameters:
toJson- the host's JSON serializer, so the answer's fields are named as the page reads themsink- where a rendered line goes, one call per lineonEnd- closes the stream, called once when the last line is written
-
-
Method Details
-
getPredicate
Description copied from interface:JobObserverReturns a predicate for filtering events at the MessageBus level. Called once during subscription.- Specified by:
getPredicatein interfaceJobObserver<JobEvent>- Returns:
- predicate to filter events, or null to accept all events of type T
-
observe
Description copied from interface:JobObserverProcess a job event. Runs in a separate virtual thread. Must handle its own resources and exceptions.- Specified by:
observein interfaceJobObserver<JobEvent>- Parameters:
event- the job event to process
-
fail
The last line when the run itself failed, then the stream closes. The run's own failed event brings it here; a holder of the handle calls it only when no terminal event reached the stream (awaitEnd(Duration)), so a stream never hangs open on a run that ended without one. -
awaitEnd
Whether the stream ended within the wait: the run's own terminal event came through and wrote the last line.- Throws:
InterruptedException
-