1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
//! # Integrated Realtime Runner Builder
//!
//! Provides `IntegratedRealtimeRunnerBuilder` — a builder API for constructing
//! `IntegratedRealtimeRunner` with optional ADK services (session, memory, plugins),
//! ADK tools (auto-bridged via `ToolBridgeAdapter`), and native `ToolHandler` tools.
use std::collections::HashMap;
use std::sync::Arc;
use adk_core::Tool;
use adk_memory::MemoryService;
use adk_plugin::EnhancedPluginManager;
use adk_session::SessionService;
use crate::config::{RealtimeConfig, ToolDefinition};
use crate::error::RealtimeError;
use crate::metering::RealtimePricing;
use crate::model::BoxedModel;
use crate::runner::{EventHandler, RealtimeRunner, RunnerConfig, ToolHandler};
use super::context::IdentityToolContextFactory;
use super::tool_bridge::ToolBridgeAdapter;
use super::{IntegrationConfig, SessionIdentity};
/// Builder for constructing an [`IntegratedRealtimeRunner`](super::IntegratedRealtimeRunner).
///
/// Provides a fluent API for configuring the realtime runner with optional ADK
/// services (session, memory, plugins), ADK tools (auto-bridged via
/// [`ToolBridgeAdapter`]), and native
/// [`ToolHandler`] tools.
///
/// # Example
///
/// ```rust,ignore
/// use adk_realtime::integration::builder::IntegratedRealtimeRunnerBuilder;
///
/// let runner = IntegratedRealtimeRunnerBuilder::new()
/// .model(model)
/// .identity("my-app", "user-1", "session-1")
/// .session_service(session_svc)
/// .memory_service(memory_svc)
/// .adk_tool(rag_tool)
/// .build()?;
/// ```
pub struct IntegratedRealtimeRunnerBuilder {
/// The realtime model (required for build).
pub(crate) model: Option<BoxedModel>,
/// Realtime session configuration.
pub(crate) config: RealtimeConfig,
/// Runner execution configuration.
pub(crate) runner_config: RunnerConfig,
/// Optional session service for persistence.
pub(crate) session_service: Option<Arc<dyn SessionService>>,
/// Optional memory service for RAG/search.
pub(crate) memory_service: Option<Arc<dyn MemoryService>>,
/// Optional plugin manager for lifecycle hooks.
pub(crate) plugin_manager: Option<Arc<EnhancedPluginManager>>,
/// ADK tools to be auto-bridged via `ToolBridgeAdapter`.
pub(crate) adk_tools: Vec<Arc<dyn Tool>>,
/// Native tools registered directly as `ToolHandler` implementations.
pub(crate) native_tools: HashMap<String, (ToolDefinition, Arc<dyn ToolHandler>)>,
/// The first native tool name registered twice; `build` rejects it.
pub(crate) duplicate_tool: Option<String>,
/// Optional event handler for raw realtime events.
pub(crate) event_handler: Option<Arc<dyn EventHandler>>,
/// Session identity triple (required for build).
pub(crate) identity: Option<SessionIdentity>,
/// Integration-layer configuration (transcript persistence, memory injection, etc.).
pub(crate) integration_config: IntegrationConfig,
/// Policy, kill switch, and confirmation applied to every dispatched tool call.
pub(crate) tool_governance: Option<adk_core::RunConfig>,
/// The runner's kill switch, when the caller shares one.
pub(crate) control: Option<adk_core::GovernanceControl>,
/// The tools that need a person's approval before they run.
pub(crate) confirmation: adk_core::ToolConfirmationPolicy,
/// How long one tool call may run.
pub(crate) tool_timeout: std::time::Duration,
/// Screens every tool result before the model and the session see it.
pub(crate) tool_result_screen: Option<Arc<dyn adk_core::ToolResultScreen>>,
/// Whether tool and plugin error messages reach the model.
pub(crate) expose_tool_error_messages: bool,
/// The identity the server authenticated for the session, if any.
pub(crate) request_context: Option<adk_core::RequestContext>,
/// Output guardrails on the model's text and transcripts.
#[cfg(feature = "guardrails")]
pub(crate) output_guardrails: Option<adk_guardrail::GuardrailSet>,
/// Prices each response's usage for the spend ledger.
pub(crate) pricing: Option<RealtimePricing>,
/// Whether `next_event` runs tool dispatch on its own task.
pub(crate) concurrent_tool_dispatch: bool,
/// The agent tool calls are governed, metered and held under.
pub(crate) agent_name: String,
}
impl Default for IntegratedRealtimeRunnerBuilder {
fn default() -> Self {
Self::new()
}
}
impl IntegratedRealtimeRunnerBuilder {
/// Creates a new builder with all fields set to defaults.
///
/// The `model` and `identity` fields must be set before calling `build()`.
pub fn new() -> Self {
Self {
model: None,
config: RealtimeConfig::default(),
runner_config: RunnerConfig::default(),
session_service: None,
memory_service: None,
plugin_manager: None,
adk_tools: Vec::new(),
native_tools: HashMap::new(),
duplicate_tool: None,
event_handler: None,
identity: None,
integration_config: IntegrationConfig::default(),
tool_governance: None,
control: None,
confirmation: adk_core::ToolConfirmationPolicy::Never,
tool_timeout: crate::runner::DEFAULT_REALTIME_TOOL_TIMEOUT,
tool_result_screen: None,
expose_tool_error_messages: false,
request_context: None,
#[cfg(feature = "guardrails")]
output_guardrails: None,
pricing: None,
concurrent_tool_dispatch: false,
agent_name: crate::runner::DEFAULT_REALTIME_AGENT_NAME.to_string(),
}
}
/// Sets the realtime model to use for the session.
///
/// This is required — `build()` will return an error if no model is set.
///
/// # Arguments
///
/// * `model` - A shared realtime model instance.
pub fn model(mut self, model: BoxedModel) -> Self {
self.model = Some(model);
self
}
/// Sets the realtime session configuration (instructions, voice, VAD, etc.).
///
/// # Arguments
///
/// * `config` - The realtime configuration.
pub fn config(mut self, config: RealtimeConfig) -> Self {
self.config = config;
self
}
/// Sets the runner execution configuration.
///
/// # Arguments
///
/// * `runner_config` - Controls auto-execution, concurrency, etc.
pub fn runner_config(mut self, runner_config: RunnerConfig) -> Self {
self.runner_config = runner_config;
self
}
/// Sets the session service for transcript persistence.
///
/// When configured, completed turns are automatically persisted to the session
/// history, enabling cross-session continuity.
///
/// # Arguments
///
/// * `service` - A shared session service instance.
pub fn session_service(mut self, service: Arc<dyn SessionService>) -> Self {
self.session_service = Some(service);
self
}
/// Sets the memory service for RAG search and memory injection.
///
/// When configured, memory entries can be injected into the system instruction
/// at session start, and completed turns can be stored for future retrieval.
///
/// # Arguments
///
/// * `service` - A shared memory service instance.
pub fn memory_service(mut self, service: Arc<dyn MemoryService>) -> Self {
self.memory_service = Some(service);
self
}
/// Sets the plugin manager for lifecycle hooks (before/after tool calls, etc.).
///
/// When configured, tool calls are intercepted by the plugin pipeline,
/// enabling short-circuit responses, argument modification, and result
/// transformation.
///
/// # Arguments
///
/// * `pm` - A shared enhanced plugin manager instance.
pub fn plugin_manager(mut self, pm: Arc<EnhancedPluginManager>) -> Self {
self.plugin_manager = Some(pm);
self
}
/// Sets the session identity triple (`app_name`, `user_id`, `session_id`).
///
/// This is required — `build()` will return an error if no identity is set.
/// The identity scopes all interactions with session, memory, and plugin services.
///
/// # Arguments
///
/// * `app_name` - The application name.
/// * `user_id` - The user identifier.
/// * `session_id` - The unique session identifier.
pub fn identity(
mut self,
app_name: impl Into<String>,
user_id: impl Into<String>,
session_id: impl Into<String>,
) -> Self {
self.identity = Some(SessionIdentity {
app_name: app_name.into(),
user_id: user_id.into(),
session_id: session_id.into(),
});
self
}
/// Registers an ADK tool for automatic bridging via [`ToolBridgeAdapter`].
///
/// The tool's name, description, and parameter schema are automatically
/// extracted and registered with the realtime provider. At execution time,
/// the bridge creates a `ToolContext` scoped to the current session.
///
/// # Arguments
///
/// * `tool` - A shared ADK tool instance.
pub fn adk_tool(mut self, tool: Arc<dyn Tool>) -> Self {
self.adk_tools.push(tool);
self
}
/// Registers a native tool with its definition and handler.
///
/// Native tools bypass the `ToolBridgeAdapter` and are executed directly
/// via their [`ToolHandler`] implementation. Use this for tools that are
/// already implemented against the realtime `ToolHandler` interface.
///
/// # Arguments
///
/// * `definition` - The tool definition (name, description, parameters schema).
/// * `handler` - The tool handler implementation.
pub fn tool(mut self, definition: ToolDefinition, handler: impl ToolHandler + 'static) -> Self {
let name = definition.name.clone();
if self.native_tools.insert(name.clone(), (definition, Arc::new(handler))).is_some() {
self.duplicate_tool.get_or_insert(name);
}
self
}
/// Sets the event handler for raw realtime server events.
///
/// The event handler receives audio deltas, text deltas, transcripts,
/// and other events from the realtime provider.
///
/// # Arguments
///
/// * `handler` - A shared event handler instance.
pub fn event_handler(mut self, handler: Arc<dyn EventHandler>) -> Self {
self.event_handler = Some(handler);
self
}
/// Sets the integration-layer configuration.
///
/// Controls which ADK service interactions are performed automatically
/// (transcript persistence, memory storage, memory injection).
///
/// # Arguments
///
/// * `config` - The integration configuration.
pub fn integration_config(mut self, config: IntegrationConfig) -> Self {
self.integration_config = config;
self
}
/// Governs every tool call with `config`'s tool policy, kill switches, confirmation
/// handler, approvals, and approval store, scoped to this runner's identity. ADK tools
/// are authorized after the plugin pipeline rewrites their arguments, and every tool
/// context answers [`run_config`](adk_core::ToolContext::run_config) with `config`.
/// A call the governed path holds, or that a tool's delegate holds, is surfaced as
/// [`ServerEvent::ToolConfirmationRequested`](crate::events::ServerEvent::ToolConfirmationRequested)
/// and recorded in the session; see
/// [`IntegratedRealtimeRunner::resume_held_calls`](super::IntegratedRealtimeRunner::resume_held_calls).
/// With a `spend_ledger`, every response is metered under the identity's app name.
///
/// Without it, every call still takes the governed path, under `RunConfig::default()`:
/// no tool policy, so a call runs unless the runner's kill switch
/// ([`IntegratedRealtimeRunner::governance`](super::IntegratedRealtimeRunner::governance))
/// is frozen or the call needs confirmation
/// ([`require_tool_confirmation`](Self::require_tool_confirmation)). Such a call is held
/// in the session when a [`session_service`](Self::session_service) is set, and refused
/// otherwise, since nothing could decide it.
///
/// # Example
///
/// ```rust,ignore
/// use adk_core::{DeclarativePolicy, RunConfig};
///
/// let runner = IntegratedRealtimeRunner::builder()
/// .model(model)
/// .identity("voice", "user-1", "session-1")
/// .tool_governance(
/// RunConfig::builder()
/// .tool_policy(Arc::new(DeclarativePolicy::builder().allow_read_only().build()))
/// .build(),
/// )
/// .build()?;
/// ```
pub fn tool_governance(mut self, config: adk_core::RunConfig) -> Self {
self.tool_governance = Some(config);
self
}
/// Attaches `control` as this runner's kill switch, as
/// [`RealtimeRunnerBuilder::governance`](crate::runner::RealtimeRunnerBuilder::governance)
/// does. Without it the runner creates its own.
///
/// # Example
///
/// ```rust,ignore
/// let control = GovernanceControl::new();
/// let runner = IntegratedRealtimeRunner::builder()
/// .model(model)
/// .identity("voice", "user-1", "session-1")
/// .governance(control.clone())
/// .build()?;
/// control.freeze("incident 4012");
/// ```
pub fn governance(mut self, control: adk_core::GovernanceControl) -> Self {
self.control = Some(control);
self
}
/// Sets which tools need a person's approval before they run, as
/// `LlmAgentBuilder::tool_confirmation_policy` does. See
/// [`tool_governance`](Self::tool_governance) for what happens to such a call.
pub fn tool_confirmation_policy(mut self, policy: adk_core::ToolConfirmationPolicy) -> Self {
self.confirmation = policy;
self
}
/// Requires a person's approval before `tool_name` runs. See
/// [`tool_confirmation_policy`](Self::tool_confirmation_policy).
///
/// # Example
///
/// ```rust,ignore
/// let runner = IntegratedRealtimeRunner::builder()
/// .model(model)
/// .identity("voice", "user-1", "session-1")
/// .adk_tool(refund)
/// .require_tool_confirmation("refund")
/// .build()?;
/// ```
pub fn require_tool_confirmation(mut self, tool_name: impl Into<String>) -> Self {
self.confirmation = self.confirmation.with_tool(tool_name);
self
}
/// Requires a person's approval before every tool call. See
/// [`tool_confirmation_policy`](Self::tool_confirmation_policy).
pub fn require_tool_confirmation_for_all(mut self) -> Self {
self.confirmation = adk_core::ToolConfirmationPolicy::Always;
self
}
/// Sets how long a tool may run before its call is answered with a timeout error.
pub fn tool_timeout(mut self, timeout: std::time::Duration) -> Self {
self.tool_timeout = timeout;
self
}
/// Screens every tool result before the model and the session see it.
///
/// For an ADK tool the screen runs after the plugin pipeline, before the tool event is
/// persisted and the result is sent; for a native handler it runs as
/// [`RealtimeRunnerBuilder::tool_result_screen`](crate::runner::RealtimeRunnerBuilder::tool_result_screen)
/// describes. A result it withholds, or cannot decide on, is replaced by
/// [`result_blocked_response`](adk_core::result_blocked_response).
pub fn tool_result_screen(mut self, screen: Arc<dyn adk_core::ToolResultScreen>) -> Self {
self.tool_result_screen = Some(screen);
self
}
/// Sends the full message of tool and plugin errors to the model, which by default sees
/// their component, category, and code only.
pub fn expose_tool_error_messages(mut self, expose: bool) -> Self {
self.expose_tool_error_messages = expose;
self
}
/// Runs every tool call as the identity the server authenticated for this session (spec
/// 3.1 §7.17): tool contexts answer
/// [`is_authenticated`](adk_core::ReadonlyContext::is_authenticated) with `true` and
/// [`user_scopes`](adk_core::ToolContext::user_scopes) with the context's scopes, so a
/// policy that trusts only authenticated users (such as a harness's standing approvals)
/// treats a voice session as the server does. Without it, tool contexts report an
/// unauthenticated user. The context's `user_id` must be the [`identity`](Self::identity)
/// user; [`build`](Self::build) refuses a mismatch.
///
/// # Example
///
/// ```rust,ignore
/// let runner = IntegratedRealtimeRunner::builder()
/// .model(model)
/// .identity("voice", "user-1", "session-1")
/// .request_context(authenticated) // from the server's RequestContextExtractor
/// .build()?;
/// ```
pub fn request_context(mut self, request_context: adk_core::RequestContext) -> Self {
self.request_context = Some(request_context);
self
}
/// Screens every completed model turn — its text, or its audio transcript when it
/// produced no text — with `guardrails` before it reaches the session and memory, as
/// `LlmAgent` screens final text. A transform replaces the persisted text; a block
/// interrupts the response, persists nothing of the turn, and makes
/// [`next_event`](super::IntegratedRealtimeRunner::next_event) return
/// [`crate::error::RealtimeError::OutputBlocked`].
///
/// # Example
///
/// ```rust,ignore
/// use adk_guardrail::{GuardrailSet, PiiRedactor};
///
/// let runner = IntegratedRealtimeRunner::builder()
/// .model(model)
/// .identity("voice", "user-1", "session-1")
/// .output_guardrails(GuardrailSet::new().with(PiiRedactor::new()))
/// .build()?;
/// ```
#[cfg(feature = "guardrails")]
pub fn output_guardrails(mut self, guardrails: adk_guardrail::GuardrailSet) -> Self {
self.output_guardrails = Some(guardrails);
self
}
/// Prices each response's reported usage, so the run's spend ledger is charged the
/// usage's price rather than the per-call estimate. Needs
/// [`tool_governance`](Self::tool_governance) with a `spend_ledger`.
pub fn realtime_pricing(mut self, pricing: RealtimePricing) -> Self {
self.pricing = Some(pricing);
self
}
/// Runs each tool dispatch on its own task, so
/// [`next_event`](super::IntegratedRealtimeRunner::next_event) keeps reading provider
/// events — the user's transcript included — while a tool runs or waits for a
/// confirmation handler. The follow-up response is sent once the dispatching response
/// has closed and every tool is in, as [`RealtimeRunner::run`] does. Off by default:
/// `next_event` then dispatches inline and returns after the result is sent.
pub fn concurrent_tool_dispatch(mut self, concurrent: bool) -> Self {
self.concurrent_tool_dispatch = concurrent;
self
}
/// Names the agent every tool call is governed, metered and held under: the gate's
/// agent name, the acting agent of each call, the agent tool contexts report, and the
/// author of the session events that record a hold. Defaults to
/// [`DEFAULT_REALTIME_AGENT_NAME`](crate::runner::DEFAULT_REALTIME_AGENT_NAME). A
/// surface that runs an existing agent's tools sets that agent's name, so the agent's
/// tool policy classifies its own tools (spec 3.1 §7.17).
///
/// # Example
///
/// ```rust,ignore
/// let runner = IntegratedRealtimeRunner::builder()
/// .model(model)
/// .identity("adk-rust", "ana", "voice-1")
/// .agent_name("harness")
/// .tool_governance(harness.run_config())
/// .build()?;
/// ```
pub fn agent_name(mut self, name: impl Into<String>) -> Self {
self.agent_name = name.into();
self
}
/// Builds the [`IntegratedRealtimeRunner`](super::IntegratedRealtimeRunner).
///
/// Validates required fields, bridges ADK tools via
/// [`ToolBridgeAdapter`], builds the underlying
/// [`RealtimeRunner`], and constructs the integrated runner
/// with all configured services.
///
/// # Errors
///
/// Returns a [`ConfigError`](crate::error::RealtimeError::ConfigError) if:
/// - `model` was not set
/// - `identity` was not set
/// - a [`request_context`](Self::request_context) names a user other than the identity's
/// - two tools, native or bridged, share a name
///
/// Also propagates any errors from the underlying `RealtimeRunner::builder().build()`.
///
/// # Example
///
/// ```rust,ignore
/// let runner = IntegratedRealtimeRunnerBuilder::new()
/// .model(model)
/// .identity("my-app", "user-1", "session-1")
/// .build()?;
/// ```
pub fn build(self) -> crate::error::Result<super::IntegratedRealtimeRunner> {
let model = self.model.ok_or_else(|| RealtimeError::config("Model is required"))?;
let identity = self.identity.ok_or_else(|| {
RealtimeError::config("Identity (app_name, user_id, session_id) is required")
})?;
if let Some(request_context) = &self.request_context
&& request_context.user_id != identity.user_id
{
return Err(RealtimeError::config(format!(
"the request context authenticates user '{}' but the session identity is user \
'{}'; pass the authenticated user to identity()",
request_context.user_id, identity.user_id
)));
}
// Resolved here rather than by the inner runner, so tool contexts carry the same
// config, kill switch included, that the runner governs with.
let control = self.control.unwrap_or_default();
let mut run_config = self.tool_governance.unwrap_or_default();
if !run_config.governance.iter().any(|existing| existing.same_as(&control)) {
run_config.governance.push(control.clone());
}
// Create context factory for ADK tools
let context_factory = Arc::new(IdentityToolContextFactory {
identity: identity.clone(),
memory_service: self.memory_service.clone(),
request_context: self.request_context.clone(),
run_config: run_config.clone(),
agent_name: self.agent_name.clone(),
});
// Bridge ADK tools via ToolBridgeAdapter
let mut all_tools = self.native_tools;
let mut duplicate_tool = self.duplicate_tool;
for tool in &self.adk_tools {
let def = ToolBridgeAdapter::definition(tool.as_ref());
let adapter = Arc::new(
ToolBridgeAdapter::new(tool.clone(), context_factory.clone())
.with_exposed_error_messages(self.expose_tool_error_messages),
);
let name = def.name.clone();
if all_tools.insert(name.clone(), (def, adapter as Arc<dyn ToolHandler>)).is_some() {
duplicate_tool.get_or_insert(name);
}
}
if let Some(name) = duplicate_tool {
return Err(RealtimeError::config(format!(
"two tools are registered as '{name}'; the model calls tools by name, so only \
one could ever run. Rename one of them or register it once."
)));
}
// Build underlying RealtimeRunner
let mut runner_builder = RealtimeRunner::builder()
.model(model)
.config(self.config)
.runner_config(self.runner_config)
.tool_timeout(self.tool_timeout)
.expose_tool_error_messages(self.expose_tool_error_messages)
.agent_name(self.agent_name)
.governance(control)
.tool_governance(
run_config,
adk_core::ApprovalScope::new(
&identity.app_name,
&identity.user_id,
&identity.session_id,
),
)
.tool_confirmation_policy(self.confirmation);
if let Some(screen) = self.tool_result_screen {
runner_builder = runner_builder.tool_result_screen(screen);
}
if let Some(pricing) = self.pricing {
runner_builder = runner_builder.realtime_pricing(pricing);
}
for (_, (def, handler)) in all_tools {
runner_builder = runner_builder.tool_arc(def, handler);
}
if let Some(handler) = self.event_handler {
runner_builder = runner_builder.event_handler_arc(handler);
}
let runner = Arc::new(runner_builder.build()?);
// Kept so the live event path can run them through the policy pipeline rather than
// only through the bridge adapter.
let adk_tools_by_name =
self.adk_tools.iter().map(|tool| (tool.name().to_string(), Arc::clone(tool))).collect();
Ok(super::IntegratedRealtimeRunner {
inner: Arc::new(super::Inner {
runner,
session_service: self.session_service,
memory_service: self.memory_service,
plugin_manager: self.plugin_manager,
aggregator: tokio::sync::RwLock::new(super::transcript::TranscriptAggregator::new()),
identity,
config: self.integration_config,
adk_tools: adk_tools_by_name,
request_context: self.request_context,
pending_events: std::sync::Mutex::new(std::collections::VecDeque::new()),
connected_calls: std::sync::Mutex::new(std::collections::HashSet::new()),
concurrent_dispatch: self.concurrent_tool_dispatch,
#[cfg(feature = "guardrails")]
output_guardrails: self.output_guardrails,
}),
})
}
}