zeph_llm/debug_dump.rs
1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Cross-crate sink trait for LLM request/response debug-dump instrumentation.
5//!
6//! `zeph-core` owns the concrete debug-dump writer (`DebugDumper`) and the top-level
7//! agent loop's `--debug-dump` wiring, but `zeph-subagent` cannot depend on `zeph-core`
8//! (the dependency runs the other way). [`DebugDumpSink`] is the minimal contract that
9//! lets `zeph-core` hand a dump-writer handle down into `zeph-subagent`'s agent loop —
10//! via `SpawnContext`/`AgentLoopArgs` — so sub-agent LLM calls are captured through the
11//! same pipeline as top-level calls (#6391).
12
13use crate::provider::{ChatResponse, Message, ToolDefinition};
14
15/// Receives LLM request/response pairs for debug-dump instrumentation.
16///
17/// Implemented by `zeph-core`'s `DebugDumper`. Callers pair each [`dump_request`] with a
18/// [`dump_response`] using the returned id.
19///
20/// [`dump_request`]: DebugDumpSink::dump_request
21/// [`dump_response`]: DebugDumpSink::dump_response
22pub trait DebugDumpSink: Send + Sync {
23 /// Returns `true` when the active dump format does not need `provider_request` built
24 /// (e.g. Trace format, which records spans instead of numbered files) — callers can
25 /// skip the (non-free) request serialization in that case.
26 fn is_trace_format(&self) -> bool;
27
28 /// Dump the outgoing request. Returns an id that must be passed to [`dump_response`]
29 /// to correlate the pair.
30 ///
31 /// [`dump_response`]: DebugDumpSink::dump_response
32 fn dump_request(
33 &self,
34 model_name: &str,
35 messages: &[Message],
36 tools: &[ToolDefinition],
37 provider_request: serde_json::Value,
38 ) -> u32;
39
40 /// Dump the response paired with a prior [`dump_request`] call.
41 ///
42 /// [`dump_request`]: DebugDumpSink::dump_request
43 fn dump_response(&self, id: u32, response: &ChatResponse);
44}