copyWith method

InvocationContext copyWith({
  1. BaseAgent? agent,
  2. String? branch,
  3. Object? nodePath = _sentinel,
  4. Object? isolationScope = _sentinel,
  5. Content? userContent,
  6. String? invocationId,
  7. RunConfig? runConfig,
  8. AdkAbortSignal? abortSignal,
})

Creates a shallow-cloned context with selected overrides.

Implementation

InvocationContext copyWith({
  BaseAgent? agent,
  String? branch,
  Object? nodePath = _sentinel,
  Object? isolationScope = _sentinel,
  Content? userContent,
  String? invocationId,
  RunConfig? runConfig,
  AdkAbortSignal? abortSignal,
}) {
  return InvocationContext(
    artifactService: artifactService,
    sessionService: sessionService,
    memoryService: memoryService,
    credentialService: credentialService,
    contextCacheConfig: contextCacheConfig,
    invocationId: invocationId ?? this.invocationId,
    branch: branch ?? this.branch,
    nodePath: identical(nodePath, _sentinel)
        ? this.nodePath
        : nodePath as String?,
    isolationScope: identical(isolationScope, _sentinel)
        ? this.isolationScope
        : isolationScope as String?,
    agent: agent ?? this.agent,
    userContent: userContent ?? this.userContent?.copyWith(),
    session: session,
    agentStates: agentStates,
    endOfAgents: endOfAgents,
    endInvocation: endInvocation,
    liveRequestQueue: liveRequestQueue,
    activeStreamingTools: activeStreamingTools,
    activeNonBlockingToolTasks: activeNonBlockingToolTasks,
    activeBackgroundTools: activeBackgroundTools,
    transcriptionCache: transcriptionCache == null
        ? null
        : List<Object?>.from(transcriptionCache!),
    liveSessionResumptionHandle: liveSessionResumptionHandle,
    inputRealtimeCache: inputRealtimeCache == null
        ? null
        : List<Object?>.from(inputRealtimeCache!),
    inputVisualCache: inputVisualCache == null
        ? null
        : List<Object?>.from(inputVisualCache!),
    outputRealtimeCache: outputRealtimeCache == null
        ? null
        : List<Object?>.from(outputRealtimeCache!),
    runConfig: runConfig ?? this.runConfig?.copyWith(),
    resumabilityConfig: resumabilityConfig,
    eventsCompactionConfig: eventsCompactionConfig,
    abortSignal: abortSignal ?? this.abortSignal,
    tokenCompactionChecked: tokenCompactionChecked,
    pluginManager: pluginManager,
    canonicalToolsCache: canonicalToolsCache,
    credentialByKey: credentialByKey,
    callbackContextData: callbackContextData,
    privateMetadata: privateMetadata,
  )
    ..parentInvocationId = parentInvocationId
    .._invocationCostManager = _invocationCostManager
    .._liveEventController = _liveEventController
    .._abortState =
        (abortSignal == null || identical(abortSignal, this.abortSignal))
        ? _abortState
        : (_InvocationAbortState(abortSignal)
            ..aborted = _abortState.aborted
            ..abortEventSynthesized = _abortState.abortEventSynthesized);
}