pub struct MessageHandle<'a, S> { /* private fields */ }Expand description
One open text message.
Created by RunContext::assistant_message.
TEXT_MESSAGE_START has already gone out by the time you hold one; Drop
emits TEXT_MESSAGE_END if end was not called.
let mut message = ctx.assistant_message()?;
for word in ["Hello", ", ", "world"] {
message.delta(word)?;
}
message.end()?;
assert_eq!(events.drain().len(), 5);Implementations§
Source§impl<'a, S> MessageHandle<'a, S>
impl<'a, S> MessageHandle<'a, S>
Sourcepub fn delta(&mut self, text: impl Into<String>) -> Result<()>
pub fn delta(&mut self, text: impl Into<String>) -> Result<()>
Appends text — TEXT_MESSAGE_CONTENT.
No .await: see the module docs for why the emit path is
synchronous.
Sourcepub fn emit(&mut self, event: Event) -> Result<()>
pub fn emit(&mut self, event: Event) -> Result<()>
Emits an unrelated event without closing the message.
For the unordered families — STATE_*, ACTIVITY_*, CUSTOM, RAW —
which may legally interleave with a message. Opening a second message
through here is a protocol violation the verifier will reject.
Source§impl<S: AgentState> MessageHandle<'_, S>
The run’s state, reachable while the message is open — an agent that
narrates what it is doing changes both in the same breath. See
ToolCallHandle, where this matters most.
impl<S: AgentState> MessageHandle<'_, S>
The run’s state, reachable while the message is open — an agent that
narrates what it is doing changes both in the same breath. See
ToolCallHandle, where this matters most.
Sourcepub fn state_mut(&mut self) -> &mut S
pub fn state_mut(&mut self) -> &mut S
The typed state, mutably. Nothing is emitted until you call
publish_state.
Sourcepub fn publish_state(&mut self) -> Result<()>
pub fn publish_state(&mut self) -> Result<()>
Publishes whatever state_mut left behind, as a
STATE_SNAPSHOT or a STATE_DELTA inside this message’s brackets.
A no-op when nothing changed since the last publish.