Skip to main content

enqueue_messages

Function enqueue_messages 

Source
pub fn enqueue_messages(session: &AgentSession, messages: impl IntoMessages)
Expand description

Queue messages for the next model call of a run on session.

Port of upstream’s enqueue_messages / MessageInjectionMiddleware. Messages can be queued before a run or while one is in progress (for example from a tool, through FunctionInvocationContext::session). The function-invocation loop appends them to the next request it sends, and when a model call would end the run while messages are still queued, it makes another call so they are answered. The injected messages are part of the run’s response, so session history records them.

Injection is built into the function-invocation loop (always on, and a no-op while nothing is queued) rather than being a middleware the caller adds. It applies to non-streaming model calls; a token-streaming run leaves the queue for its next non-streaming call.