pub struct SseForwardObserver { /* private fields */ }Expand description
A StepObserver that forwards token/tool callbacks as StreamFrames onto an
unbounded tokio::sync::mpsc channel. The send side (this observer, called
from the LLM read loop) never blocks or drops a frame for backpressure
reasons — the channel is unbounded. The receive side is drained directly by
the SSE responder via futures::stream::unfold, which feeds Sse::new
(see agent_chat_stream_core / agent_chat_stream); there is no separate
bounded intermediate stage between the observer and the SSE response.
Implementations§
Source§impl SseForwardObserver
impl SseForwardObserver
pub fn new(tx: UnboundedSender<StreamFrame>) -> SseForwardObserver
Trait Implementations§
Source§impl StepObserver for SseForwardObserver
impl StepObserver for SseForwardObserver
Source§fn wants_streaming(&self) -> bool
fn wants_streaming(&self) -> bool
Whether this observer wants token-level streaming. Defaults to
false so the non-streaming AgentRuntime::step path calls
LlmBackend::complete and preserves the exact request wire shape
(no stream: true) every existing caller relied on before streaming
existed. A streaming consumer overrides this to true, which makes
[r#loop::run_step] use LlmBackend::complete_streaming and drive
StepObserver::on_token_delta.Source§fn on_token_delta(&self, chunk: &str)
fn on_token_delta(&self, chunk: &str)
Called with each incremental text chunk of the assistant reply.
Only invoked when
StepObserver::wants_streaming returns true.Source§fn on_tool_call(&self, name: &str, call_id: &str, args: &Value)
fn on_tool_call(&self, name: &str, call_id: &str, args: &Value)
Called just before a tool is dispatched, with its arguments.
Source§fn on_tool_result(&self, _name: &str, call_id: &str, result: &Value)
fn on_tool_result(&self, _name: &str, call_id: &str, result: &Value)
Called after a tool dispatch succeeds, with the tool’s result.
Source§fn on_tool_failed(&self, _name: &str, call_id: &str, error: &Value)
fn on_tool_failed(&self, _name: &str, call_id: &str, error: &Value)
Called after a tool dispatch fails or is blocked (e.g. not in the
agent’s allow-list), with the error/reason payload. Additive hook —
see the “Extending this trait” note above.
Source§fn on_llm_call(&self, tokens_in: u64, tokens_out: u64)
fn on_llm_call(&self, tokens_in: u64, tokens_out: u64)
Called after each LLM iteration completes, with that call’s token usage.
Additive hook — lets a streaming consumer surface a per-message LLM/token
trace even for turns that call no tools (the token trail is otherwise
only in the final
AgentOutput.trail, which the SSE stream omits).Source§fn on_guardrail(&self, _obs: &GuardrailObservation)
fn on_guardrail(&self, _obs: &GuardrailObservation)
Called for every guardrail denial — blocked (Enforce) or merely recorded
(Monitor). Default no-op: only the audit observer forwards these.
Additive hook — see the “Extending this trait” note above.
Auto Trait Implementations§
impl !Freeze for SseForwardObserver
impl RefUnwindSafe for SseForwardObserver
impl Send for SseForwardObserver
impl Sync for SseForwardObserver
impl Unpin for SseForwardObserver
impl UnsafeUnpin for SseForwardObserver
impl UnwindSafe for SseForwardObserver
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request