/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { Content } from '@google/genai'; import { BaseAgent } from '../agents/base_agent.js'; import { LiveRequestQueue } from '../agents/live_request_queue.js'; import { RunConfig } from '../agents/run_config.js'; import { App } from '../apps/app.js'; import { ResumabilityConfig } from '../apps/resumability_config.js'; import { BaseArtifactService } from '../artifacts/base_artifact_service.js'; import { BaseCredentialService } from '../auth/credential_service/base_credential_service.js'; import { Event } from '../events/event.js'; import { BaseMemoryService } from '../memory/base_memory_service.js'; import { BasePlugin } from '../plugins/base_plugin.js'; import { PluginManager } from '../plugins/plugin_manager.js'; import { BaseSessionService } from '../sessions/base_session_service.js'; import { Session } from '../sessions/session.js'; import type { RunnableNode } from '../workflow/graph.js'; import { RunnableRoot } from '../workflow/run_node_as_invocation.js'; /** * The configuration parameters for the Runner. */ export interface RunnerConfig { /** * The application object. If provided, `appName`, `agent`, and `plugins` will default from this app. */ app?: App; /** * The application name. Required if `app` is not provided. */ appName?: string; /** * The agent or workflow to run. Required if `app` is not provided. * * A bare node — a `Workflow`, most usefully — is accepted as the root and * driven directly, so a graph does not have to be wrapped by hand to be run. * The accepted set is the one an edge takes: any other node-like value * becomes the single node of a one-node workflow. Mirrors adk-python, whose * `Runner.agent` is typed `BaseNode`. */ agent?: RunnableNode; /** * An optional list of plugins to apply globally across all agents. */ plugins?: BasePlugin[]; /** * An optional service for storing and retrieving artifacts. */ artifactService?: BaseArtifactService; /** * The service for managing sessions. */ sessionService: BaseSessionService; /** * An optional service for storing and querying agent memory. */ memoryService?: BaseMemoryService; /** * An optional service for managing authentication credentials. */ credentialService?: BaseCredentialService; /** * An optional resumability configuration applied to the runner. */ resumabilityConfig?: ResumabilityConfig; } /** * A unique symbol to identify ADK agent classes. * Defined once and shared by all Runner instances. */ declare const RUNNER_SIGNATURE_SYMBOL: unique symbol; /** * Type guard to check if an object is an instance of Runner. * @param obj The object to check. * @returns True if the object is an instance of Runner, false otherwise. */ export declare function isRunner(obj: unknown): obj is Runner; /** * Orchestrates agent execution for a given application. * * The Runner manages the full lifecycle of an agent invocation: it loads the * session, invokes plugin callbacks, runs the root agent, and yields the * resulting events. Use {@link InMemoryRunner} for quick prototyping without * external services. * * Example: * ```typescript * const runner = new Runner({ * appName: 'my_app', * agent: myAgent, * sessionService: new InMemorySessionService(), * }); * * for await (const event of runner.runAsync({ * userId: 'user1', * sessionId: 'session1', * newMessage: {parts: [{text: 'Hello'}]}, * })) { * console.log(event); * } * ``` */ export declare class Runner { readonly [RUNNER_SIGNATURE_SYMBOL] = true; readonly appName: string; /** * The root being run: an agent, or a bare node (a `Workflow`) that the * runner drives directly. */ readonly agent: RunnableRoot; readonly pluginManager: PluginManager; readonly artifactService?: BaseArtifactService; readonly sessionService: BaseSessionService; readonly memoryService?: BaseMemoryService; readonly credentialService?: BaseCredentialService; readonly resumabilityConfig?: ResumabilityConfig; /** * Creates a new Runner instance. * * @param input The configuration for the runner. */ constructor(input: RunnerConfig); /** * Runs the agent with a new, ephemeral session. * * @param params.userId The user ID of the session. * @param params.newMessage A new message to append to the session. * @param params.stateDelta An optional state delta to apply to the session. * @param params.runConfig The run config for the agent. * @yields The Events generated by the agent. */ runEphemeral(params: { userId: string; newMessage: Content; stateDelta?: Record; runConfig?: RunConfig; customMetadata?: Record; }): AsyncGenerator; /** * Runs the agent with the given message, and returns an async generator of * events. * * @param params.userId The user ID of the session. * @param params.sessionId The session ID of the session. * @param params.newMessage A new message to append to the session. * @param params.stateDelta An optional state delta to apply to the session. * @param params.runConfig The run config for the agent. * @yields The events generated by the agent. */ runAsync(params: { userId: string; sessionId: string; newMessage: Content; stateDelta?: Record; runConfig?: RunConfig; abortSignal?: AbortSignal; customMetadata?: Record; }): AsyncGenerator; /** * Runs whatever this runner was given as its root. * * An agent is run through `runAsync`, as always. A bare node — a `Workflow` * handed to the runner directly — is driven by {@link runNodeAsInvocation}. * * Only the execution differs. Everything around it (the run callbacks, event * persistence, cancellation) is shared, so the node path cannot drift from * the agent path on the things that are not about execution. adk-python has * two separate loops here and a TODO noting its node one lacks tracing and * plugins; there is nothing to lack if there is only one loop. */ private runRoot; /** * Saves artifacts from the message parts and replaces the inline data with * a file name placeholder and optional file reference. * * @param invocationId The current invocation ID. * @param userId The user ID of the session. * @param sessionId The session ID of the session. * @param message The message containing parts to process. */ private saveArtifacts; /** * Determines the next agent to run to continue the session. This is primarily * used for session resumption. */ /** * Determines the next agent to run to continue the session. This is primarily * used for session resumption across tool and LRO boundaries. */ private determineAgentForResumption; /** * Whether the agent to run can transfer to any other agent in the agent tree. * * @param agentToRun The agent to check for transferability. * @returns True if the agent can transfer, False otherwise. */ private isRoutableLlmAgent; /** * Runs the agent in the live (bidirectional streaming) mode. * * Model media events that carry raw inline bytes (audio, video, or image) * are yielded but not appended to the session to avoid persisting large * blobs; events with `fileData` references and most other live events * (transcriptions, tool calls, usage) are persisted as in `runAsync`. * * This feature is **experimental** and its API may change. * * @param params.userId The user ID of the session. * @param params.sessionId The session ID of the session. * @param params.liveRequestQueue The queue used to feed the live model. * @param params.runConfig The run config for the agent. * @param params.abortSignal Optional signal to abort the live run. * @param params.liveSessionResumptionHandle Optional session resumption * handle observed from a prior `runLive` cycle on the same conversation. * When set, the agent's live flow opens the connection with * `liveConnectConfig.sessionResumption.handle` so the server restores its * state instead of relying on client-side history replay. * @yields The events generated by the agent. */ runLive(params: { userId: string; sessionId: string; liveRequestQueue: LiveRequestQueue; runConfig?: RunConfig; abortSignal?: AbortSignal; liveSessionResumptionHandle?: string; }): AsyncGenerator; } /** * Determines the next agent to run to continue the session. This is primarily * used for session resumption across tool and LRO boundaries. */ export declare function determineAgentForResumption(session: Session, rootAgent: BaseAgent, resumabilityConfig?: ResumabilityConfig): BaseAgent; /** * Whether the agent to run can transfer to any other agent in the agent tree. * * An agent is transferable if: * - It is an instance of `LlmAgent`. * - All its ancestors are also transferable (i.e., they have * `disallowTransferToParent` set to false). * * @param agentToRun The agent to check for transferability. * @returns True if the agent can transfer, False otherwise. */ export declare function isRoutableLlmAgent(agentToRun: BaseAgent): boolean; /** * It iterates through the events in reverse order, and returns the event * containing a function call with a functionCall.id matching the * functionResponse.id from the last event in the session. */ export declare function findEventByLastFunctionResponseId(events: Event[]): Event | null; export {};