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(GeminiModel::GeminiLive2_5FlashNativeAudio);
// Add agent's tools to config
let session = connect(config, TransportConfig::default()).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 with_middleware(self, mw: impl Middleware + 'static) -> Self
pub fn with_middleware(self, mw: impl Middleware + 'static) -> Self
Add middleware to the runner (applied to all agent invocations).
Sourcepub fn with_plugin(self, plugin: impl Plugin + 'static) -> Self
pub fn with_plugin(self, plugin: impl Plugin + 'static) -> Self
Add a plugin to the runner.
Sourcepub fn with_state(self, state: State) -> Self
pub fn with_state(self, state: State) -> Self
Set initial state (available to all agents).
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(())