Overview
The Event class represents an event in a conversation between agents and users. It extends LlmResponse and stores conversation content, function calls, and actions taken by agents during interactions.
Events are the fundamental building blocks of agent conversations in ADK-TS, capturing both user inputs and agent responses with associated metadata and actions.
Class Definition
import { Event } from '@iqai/adk' ;
Constructor
Configuration options for creating an Event Show EventOpts properties
The author of the event - either 'user' or the name of the agent
The invocation ID associated with this event
The actions attached to this event (state changes, transfers, etc.)
Set of IDs for long-running function calls. Used by the agent client to track which function calls are still executing.
The branch of the event in hierarchical agent conversations. Format: agent_1.agent_2.agent_3 where each agent is a parent of the next. Used when sub-agents shouldn’t see peer agents’ conversation history.
Unique identifier for the event. Auto-generated if not provided.
Unix timestamp in seconds. Auto-generated if not provided.
The content payload of the event
Whether this is a partial event (streaming in progress)
Properties
The invocation ID of the event
The author who created this event - 'user' or agent name
actions
EventActions
default: "new EventActions()"
Actions associated with this event. See EventActions for details.
IDs of long-running function calls. Only valid for function call events.
Hierarchical branch path for multi-agent scenarios (e.g., "agent_1.agent_2")
Unique 8-character identifier for the event
Unix timestamp in seconds when the event was created
Methods
isFinalResponse()
Determines if this event represents the final response from an agent.
isFinalResponse (): boolean
Returns: true if the event is a final response (no function calls, not partial, no pending code execution)
Example:
const event = new Event ({ author: 'assistant' });
if ( event . isFinalResponse ()) {
console . log ( 'Agent has completed its response' );
}
getFunctionCalls()
Extracts all function calls from the event content.
getFunctionCalls (): any []
Returns: Array of function call objects from the event’s content parts
Example:
const functionCalls = event . getFunctionCalls ();
for ( const call of functionCalls ) {
console . log ( `Function: ${ call . name } ` , call . args );
}
getFunctionResponses()
Extracts all function responses from the event content.
getFunctionResponses (): any []
Returns: Array of function response objects from the event’s content parts
hasTrailingCodeExecutionResult()
Checks if the event ends with a code execution result.
hasTrailingCodeExecutionResult (): boolean
Returns: true if the last content part is a code execution result
Event.newId() (static)
Generates a new random 8-character ID for an event.
Returns: A unique 8-character identifier
Example:
const eventId = Event . newId (); // e.g., "a3f5c89d"
Usage Examples
Creating a User Event
import { Event } from '@iqai/adk' ;
const userEvent = new Event ({
author: 'user' ,
content: {
role: 'user' ,
parts: [{ text: 'What is the weather today?' }]
}
});
Creating an Agent Event with Actions
import { Event , EventActions } from '@iqai/adk' ;
const agentEvent = new Event ({
author: 'WeatherAgent' ,
invocationId: 'inv-123' ,
actions: new EventActions ({
stateDelta: { location: 'San Francisco' },
transferToAgent: 'WeatherDetailAgent'
}),
content: {
role: 'model' ,
parts: [{ text: 'Checking weather for San Francisco...' }]
}
});
Processing Events in Agent Flow
for await ( const event of agent . runAsync ( invocationContext )) {
console . log ( `Event from: ${ event . author } ` );
console . log ( `Event ID: ${ event . id } ` );
// Check for function calls
const calls = event . getFunctionCalls ();
if ( calls . length > 0 ) {
console . log ( 'Function calls:' , calls . map ( c => c . name ));
}
// Check if this is the final response
if ( event . isFinalResponse ()) {
console . log ( 'Agent completed' );
break ;
}
}
Branching in Multi-Agent Systems
const subAgentEvent = new Event ({
author: 'SubAgent' ,
branch: 'MainAgent.SubAgent' ,
content: {
role: 'model' ,
parts: [{ text: 'Processing sub-task...' }]
}
});
Type Reference
EventOpts Interface
interface EventOpts {
invocationId ?: string ;
author : string ;
actions ?: EventActions ;
longRunningToolIds ?: Set < string >;
branch ?: string ;
id ?: string ;
timestamp ?: number ;
content ?: any ;
partial ?: boolean ;
}
EventActions Learn about event actions and state management
BaseLlmFlow Understand how events flow through agent execution
Source Code
View the source: event.ts