copyWith method

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

Creates a shallow-cloned context with selected overrides.

Implementation

InvocationContext copyWith({
  BaseAgent? agent,
  String? branch,
  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,
    isolationScope: identical(isolationScope, _sentinel)
        ? this.isolationScope
        : isolationScope as String?,
    agent: agent ?? this.agent,
    userContent: userContent ?? this.userContent?.copyWith(),
    session: session,
    agentStates: agentStates.map(
      (String key, Map<String, Object?> value) =>
          MapEntry<String, Map<String, Object?>>(
            key,
            Map<String, Object?>.from(value),
          ),
    ),
    endOfAgents: Map<String, bool>.from(endOfAgents),
    endInvocation: endInvocation,
    liveRequestQueue: liveRequestQueue,
    activeStreamingTools: activeStreamingTools == null
        ? null
        : Map<String, ActiveStreamingTool>.from(activeStreamingTools!),
    transcriptionCache: transcriptionCache == null
        ? null
        : List<Object?>.from(transcriptionCache!),
    liveSessionResumptionHandle: liveSessionResumptionHandle,
    inputRealtimeCache: inputRealtimeCache == null
        ? null
        : List<Object?>.from(inputRealtimeCache!),
    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 == null
        ? null
        : List<BaseTool>.from(canonicalToolsCache!),
    credentialByKey: credentialByKey.map(
      (String key, AuthCredential value) =>
          MapEntry<String, AuthCredential>(key, value.copyWith()),
    ),
    callbackContextData: callbackContextData,
  ).._numberOfLlmCalls = _numberOfLlmCalls;
}