/** * @license * Copyright 2026 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { FunctionCall, FunctionResponse } from '@google/genai'; import { LlmResponse } from '../models/llm_response.js'; import { EventActions } from './event_actions.js'; /** * A unique symbol identifying ADK Event objects. * * Events are plain objects produced by {@link createEvent} rather than class * instances, so they carry this signature as a brand and `isEvent` checks for * it — mirroring the `Symbol.for('google.adk.*')` guards used across ADK (e.g. * `isBaseTool`, `isBaseAgent`). */ declare const EVENT_SIGNATURE_SYMBOL: unique symbol; /** * A single route key emitted by a routing node and matched against graph edge * routes. Mirrors the graph's `RouteValue`. */ export type RouteKey = string | number | boolean; /** * The route(s) a routing node emits: a single key fires one branch; an array * fires every branch whose route matches any listed key (multi-route dispatch). */ export type Route = RouteKey | RouteKey[]; /** * Workflow-node provenance attached to an event. * * Mirrors `google/adk-python` `Event.node_info`. Present only on events emitted * from within a workflow node. */ export interface NodeInfo { /** The workflow node path that produced this event (e.g. `wf.child.0`). */ path?: string; /** * The node paths this event's output serves as the output for: the emitting * node first, then any ancestor that delegated its own output to it. * * A node that runs a child with `useAsOutput` takes the child's output as its * own, so one event is the result for several nodes at once. Recording that * on the event is what lets a resumed run tell which nodes already produced a * result, instead of re-running an ancestor whose output only ever existed on * a descendant's event. * * Mirrors adk-python's `node_info.output_for`, which is likewise a list. */ outputFor?: string[]; /** * Whether the event's textual content should be promoted to the node's * structured output. */ messageAsOutput?: boolean; } /** * Represents an event in a conversation between agents and users. It is used to store the content of the conversation, as well as the actions taken by the agents like function calls, etc. */ export interface Event extends LlmResponse { /** * Signature brand identifying this object as an ADK {@link Event}. * * Set by {@link createEvent} and checked by `isEvent`. Optional because * events are also reconstructed from storage/session payloads, where the * (non-serializable) brand is absent. */ readonly [EVENT_SIGNATURE_SYMBOL]?: true; /** * The unique identifier of the event. * Do not assign the ID. It will be assigned by the session. */ id: string; /** * The invocation ID of the event. Should be non-empty before appending to a * session. */ invocationId: string; /** * "user" or the name of the agent, indicating who appended the event to the * session. */ author?: string; /** * The actions taken by the agent. */ actions: EventActions; /** * Set of ids of the long running function calls. Agent client will know from * this field about which function call is long running. Only valid for * function call event */ longRunningToolIds?: string[]; /** * The branch of the event. * The format is like agent_1.agent_2.agent_3, where agent_1 is the parent of * agent_2, and agent_2 is the parent of agent_3. * * Branch is used when multiple sub-agent shouldn't see their peer agents' * conversation history. */ branch?: string; /** * The timestamp of the event. */ timestamp: number; /** * Workflow: the structured output produced by the emitting node, if any. * * First-class field mirroring `google/adk-python` `Event.output`. Used by the * workflow engine to carry a node's return value alongside its content. */ output?: unknown; /** * Workflow: the route key(s) emitted by a routing node, used by the graph to * select the matching outgoing edge(s). A single value fires one branch; an * array fires every branch whose route matches any listed value (multi-route * dispatch). Mirrors Python `Event.route`. */ route?: Route; /** * Workflow: provenance of the emitting node. Mirrors Python `Event.node_info`. */ nodeInfo?: NodeInfo; /** * Workflow: scope tag used to isolate multi-agent conversations so peer * scopes don't see each other's events. Mirrors Python * `Event.isolation_scope`. */ isolationScope?: string; } /** * Parameters for creating an event with partial fields. */ export interface CreateEventParams extends Omit, 'actions'> { actions?: Partial; } /** * Creates an event from a partial event. * * @param params The partial event to create the event from. * @returns The event. */ export declare function createEvent(params?: CreateEventParams): Event; /** * Returns whether the event is the final response of the agent. */ export declare function isFinalResponse(event: Event): boolean; /** * Returns the function calls in the event. */ export declare function getFunctionCalls(event: Event): FunctionCall[]; export declare const AF_FUNCTION_CALL_ID_PREFIX = "adk-"; export declare function generateClientFunctionCallId(): string; /** * Populates client-side function call IDs. * * It iterates through all function calls in the event and assigns a * unique client-side ID to each one that doesn't already have an ID. */ export declare function populateClientFunctionCallId(modelResponseEvent: Event): void; /** * Returns the function responses in the event. */ export declare function getFunctionResponses(event: Event): FunctionResponse[]; /** * Returns whether the event has a trailing code execution result. */ export declare function hasTrailingCodeExecutionResult(event: Event): boolean; /** * Extracts and concatenates all text from the parts of a `Event` object. * @param event The `Event` object to process. * * @returns A single string with the combined text. */ export declare function stringifyContent(event: Event): string; /** * Estimates the number of tokens in the event based on usage metadata or characters. */ export declare function getEventTokens(event: Event): number; /** * Returns whether the event contains any thought parts. */ export declare function hasThoughts(event: Event): boolean; /** * Returns a copy of the event with all thought parts removed. */ export declare function pruneThoughts(event: Event): Event; /** * Type guard to check if an object is an instance of Event. * * @param obj The object to check. * @returns True if the object matches the Event structure. */ export declare function isEvent(obj: unknown): obj is Event; /** * Generates a new unique ID for the event. */ export declare function createNewEventId(): string; /** * Transforms a snake_cased event object to a camelCased Event object. * * @param event The snake_cased event object. * @returns The camelCased Event object. */ export declare function transformToCamelCaseEvent(event: Record): Event; /** * Transforms a camelCased event object to a snake_cased Event object. * * @param event The camelCased event object. * @returns The snake_cased Event object. */ export declare function transformToSnakeCaseEvent(event: Event): Record; export {};