Traces Module¶
The traces module provides full interaction-level recording for the learning
system. Every agent interaction can produce a Trace capturing the sequence
of steps (route, retrieve, generate, tool_call, respond) with timing, inputs,
outputs, and outcomes. The TraceCollector wraps any agent to record traces
automatically, while TraceAnalyzer provides aggregated statistics.
TraceStore¶
TraceStore
¶
Append-only SQLite store for interaction traces.
Source code in src/openjarvis/traces/store.py
Functions¶
save
¶
save(trace: Trace) -> None
Persist a complete trace with all its steps.
Source code in src/openjarvis/traces/store.py
get
¶
get(trace_id: str) -> Optional[Trace]
Retrieve a trace by id, or None if not found.
Source code in src/openjarvis/traces/store.py
list_traces
¶
list_traces(*, agent: Optional[str] = None, model: Optional[str] = None, outcome: Optional[str] = None, since: Optional[float] = None, until: Optional[float] = None, limit: int = 100) -> List[Trace]
Query traces with optional filters.
Source code in src/openjarvis/traces/store.py
count
¶
TraceCollector¶
TraceCollector
¶
TraceCollector(agent: BaseAgent, *, store: Optional[TraceStore] = None, bus: Optional[EventBus] = None)
Wraps a BaseAgent and records a :class:Trace for every run().
The collector subscribes to the EventBus to capture inference, tool,
and memory events emitted during agent execution, converting them into
TraceStep objects. When the agent finishes, the complete Trace
is persisted to the TraceStore and published on the bus.
Usage::
agent = OrchestratorAgent(engine, model, tools=tools, bus=bus)
collector = TraceCollector(agent, store=trace_store, bus=bus)
result = collector.run("What is 2+2?")
# Trace is automatically saved to trace_store
Source code in src/openjarvis/traces/collector.py
Attributes¶
last_trace
property
¶
last_trace: Optional[Trace]
Return the trace from the most recent run(), if available.
Functions¶
run
¶
run(input: str, context: Optional[AgentContext] = None, **kwargs: Any) -> AgentResult
Execute the wrapped agent and record a trace.
Source code in src/openjarvis/traces/collector.py
TraceAnalyzer¶
TraceAnalyzer
¶
TraceAnalyzer(store: TraceStore)
Read-only query layer over a :class:TraceStore.
Computes aggregated statistics from stored traces, providing the inputs that the learning system needs to update routing policies.
Source code in src/openjarvis/traces/analyzer.py
Functions¶
summary
¶
summary(*, since: Optional[float] = None, until: Optional[float] = None) -> TraceSummary
Compute an overall summary of all traces in the time range.
Source code in src/openjarvis/traces/analyzer.py
per_route_stats
¶
per_route_stats(*, since: Optional[float] = None, until: Optional[float] = None) -> List[RouteStats]
Compute stats grouped by (model, agent) routing decisions.
Source code in src/openjarvis/traces/analyzer.py
per_tool_stats
¶
per_tool_stats(*, since: Optional[float] = None, until: Optional[float] = None) -> List[ToolStats]
Compute stats grouped by tool name.
Source code in src/openjarvis/traces/analyzer.py
traces_for_query_type
¶
traces_for_query_type(*, has_code: bool = False, min_length: Optional[int] = None, max_length: Optional[int] = None, since: Optional[float] = None, until: Optional[float] = None) -> List[Trace]
Retrieve traces matching query characteristics.
Useful for the learning system to find traces similar to a new query and learn which routing decisions worked best.
Source code in src/openjarvis/traces/analyzer.py
export_traces
¶
export_traces(*, since: Optional[float] = None, until: Optional[float] = None, limit: int = 1000) -> List[Dict[str, Any]]
Export traces as plain dicts (for JSON serialization).
Source code in src/openjarvis/traces/analyzer.py
RouteStats¶
RouteStats
dataclass
¶
RouteStats(model: str, agent: str, count: int = 0, avg_latency: float = 0.0, avg_tokens: float = 0.0, success_rate: float = 0.0, avg_feedback: Optional[float] = None)
Aggregated statistics for a specific routing decision (model+agent).
ToolStats¶
ToolStats
dataclass
¶
Aggregated statistics for a specific tool.
TraceSummary¶
TraceSummary
dataclass
¶
TraceSummary(total_traces: int = 0, total_steps: int = 0, avg_steps_per_trace: float = 0.0, avg_latency: float = 0.0, avg_tokens: float = 0.0, success_rate: float = 0.0, step_type_distribution: Dict[str, int] = dict())
Overall summary statistics across all traces.