pub struct Runner { /* private fields */ }Expand description
Orchestrates agent execution across Gemini Live sessions.
Handles the full lifecycle: connect → run → transfer → reconnect → repeat. Transfer is complex in Gemini Live because tools are fixed at setup — changing agents means changing sessions.
§Example
let runner = Runner::new(root_agent);
runner.run(|agent| async move {
let config = SessionConfig::new(&api_key)
.model(ModelId::LIVE_2_5_FLASH_NATIVE_AUDIO);
// Add agent's tools to config
let session = connect(config).await?;
Ok(AgentSession::new(session))
}).await?;Implementations§
Source§impl Runner
impl Runner
Sourcepub fn new(root_agent: impl Agent + 'static) -> Self
pub fn new(root_agent: impl Agent + 'static) -> Self
Create a new Runner with a root agent.
Automatically registers the root agent and all sub-agents recursively.
Sourcepub fn from_arc(root_agent: Arc<dyn Agent>) -> Self
pub fn from_arc(root_agent: Arc<dyn Agent>) -> Self
Create a Runner from an already-Arc’d agent.
Sourcepub fn middleware(self, mw: impl Middleware + 'static) -> Self
pub fn middleware(self, mw: impl Middleware + 'static) -> Self
Add middleware to the runner (applied to all agent invocations).
Sourcepub fn register(&mut self, agent: Arc<dyn Agent>)
pub fn register(&mut self, agent: Arc<dyn Agent>)
Manually register an additional agent (useful for cross-tree transfers).
Sourcepub fn registry(&self) -> &AgentRegistry
pub fn registry(&self) -> &AgentRegistry
Access the agent registry.
Sourcepub fn root_agent(&self) -> &dyn Agent
pub fn root_agent(&self) -> &dyn Agent
Access the root agent.
Sourcepub async fn run<F, Fut>(&self, connect_fn: F) -> Result<(), AgentError>where
F: Fn(Arc<dyn Agent>) -> Fut + Send + Sync,
Fut: Future<Output = Result<AgentSession, AgentError>> + Send,
pub async fn run<F, Fut>(&self, connect_fn: F) -> Result<(), AgentError>where
F: Fn(Arc<dyn Agent>) -> Fut + Send + Sync,
Fut: Future<Output = Result<AgentSession, AgentError>> + Send,
Run the agent lifecycle. Handles transfers automatically.
connect_fn is a factory that creates a new AgentSession for a given agent.
This allows the Runner to reconnect with different configs on agent transfer
(different tools/instructions → different Gemini Live session).
The Runner will:
- Call
connect_fnwith the current agent - Run
agent.run_live()on the resulting session - If
TransferRequestedis returned, resolve the target agent, disconnect, preserve state, and loop back to step 1 - If the agent completes normally, return Ok(())
Auto Trait Implementations§
impl Freeze for Runner
impl !RefUnwindSafe for Runner
impl Send for Runner
impl Sync for Runner
impl Unpin for Runner
impl !UnwindSafe for Runner
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].