pub struct EventBridge { /* private fields */ }Expand description
Bridge between agent code and AG-UI protocol events.
This is the main interface for emitting events from agent code. It handles the AG-UI protocol details like run IDs, message IDs, and event sequencing.
Implementations§
Source§impl EventBridge
impl EventBridge
Sourcepub fn new(
event_tx: Sender<Event<JsonValue>>,
thread_id: Arc<RwLock<ThreadId>>,
run_id: Arc<RwLock<Option<RunId>>>,
) -> Self
pub fn new( event_tx: Sender<Event<JsonValue>>, thread_id: Arc<RwLock<ThreadId>>, run_id: Arc<RwLock<Option<RunId>>>, ) -> Self
Creates a new event bridge.
Sourcepub async fn start_run(&self)
pub async fn start_run(&self)
Starts a new agent run.
Call this at the beginning of an agent interaction.
Sourcepub async fn finish_run(&self)
pub async fn finish_run(&self)
Finishes the current run successfully.
Sourcepub async fn finish_run_with_error(&self, message: &str)
pub async fn finish_run_with_error(&self, message: &str)
Finishes the current run with an error.
Sourcepub async fn interrupt(&self, reason: Option<&str>, payload: Option<Value>)
pub async fn interrupt(&self, reason: Option<&str>, payload: Option<Value>)
Interrupt the current run for human-in-the-loop interaction.
This emits a RunFinished event with outcome: Interrupt, signaling
that the frontend should show approval UI and resume with user input.
§Arguments
reason- Optional interrupt reason (e.g., “file_write”, “deployment”)payload- Optional JSON payload with context for the approval UI
Sourcepub async fn interrupt_with_id(
&self,
id: &str,
reason: Option<&str>,
payload: Option<Value>,
)
pub async fn interrupt_with_id( &self, id: &str, reason: Option<&str>, payload: Option<Value>, )
Interrupt with a tracking ID for correlation.
The interrupt ID can be used by the client to correlate the resume request with the original interrupt.
Sourcepub async fn start_message(&self) -> MessageId
pub async fn start_message(&self) -> MessageId
Starts a new text message from the assistant.
Sourcepub async fn emit_text_chunk(&self, delta: &str)
pub async fn emit_text_chunk(&self, delta: &str)
Emits a text chunk as part of the current message.
Sourcepub async fn end_message(&self)
pub async fn end_message(&self)
Ends the current text message.
Sourcepub async fn emit_message(&self, content: &str)
pub async fn emit_message(&self, content: &str)
Convenience: Emits a complete text message (start + content + end).
Sourcepub async fn start_tool_call(&self, name: &str, args: &JsonValue) -> ToolCallId
pub async fn start_tool_call(&self, name: &str, args: &JsonValue) -> ToolCallId
Starts a tool call.
Returns the tool call ID for use with subsequent events.
Sourcepub async fn emit_tool_args_chunk(&self, tool_call_id: &ToolCallId, delta: &str)
pub async fn emit_tool_args_chunk(&self, tool_call_id: &ToolCallId, delta: &str)
Emits a chunk of tool call arguments (for streaming args).
Sourcepub async fn end_tool_call(&self, tool_call_id: &ToolCallId)
pub async fn end_tool_call(&self, tool_call_id: &ToolCallId)
Ends a tool call.
Note: Tool results are handled separately via messages in AG-UI protocol.
Sourcepub async fn emit_tool_call(&self, name: &str, args: &JsonValue)
pub async fn emit_tool_call(&self, name: &str, args: &JsonValue)
Convenience: Emits a complete tool call (start + end).
Sourcepub async fn emit_state_snapshot(&self, state: JsonValue)
pub async fn emit_state_snapshot(&self, state: JsonValue)
Emits a state snapshot.
Sourcepub async fn emit_state_delta(&self, delta: Vec<JsonValue>)
pub async fn emit_state_delta(&self, delta: Vec<JsonValue>)
Emits a state delta (JSON Patch).
Sourcepub async fn start_thinking(&self, title: Option<&str>)
pub async fn start_thinking(&self, title: Option<&str>)
Starts a thinking/processing step.
Sourcepub async fn end_thinking(&self)
pub async fn end_thinking(&self)
Ends the current thinking step.
Sourcepub async fn start_step(&self, name: &str)
pub async fn start_step(&self, name: &str)
Starts a step in the agent workflow.
Sourcepub async fn emit_custom(&self, name: &str, value: JsonValue)
pub async fn emit_custom(&self, name: &str, value: JsonValue)
Emits a custom event.
Trait Implementations§
Source§impl Clone for EventBridge
impl Clone for EventBridge
Source§fn clone(&self) -> EventBridge
fn clone(&self) -> EventBridge
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for EventBridge
impl !RefUnwindSafe for EventBridge
impl Send for EventBridge
impl Sync for EventBridge
impl Unpin for EventBridge
impl UnsafeUnpin for EventBridge
impl !UnwindSafe for EventBridge
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> 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>
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>
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 more