Overview
The EventActions class represents actions attached to an event. These actions control agent behavior, manage state changes, handle agent transfers, request authentication, and support advanced features like event compaction.
EventActions enable sophisticated agent workflows by allowing events to carry side effects beyond simple message content.
Class Definition
import { EventActions } from '@iqai/adk' ;
Constructor
options
EventActionsOptions
default: "{}"
Optional configuration for event actions Show EventActionsOptions properties
If true, prevents the model from summarizing function responses. Only used for function_response events.
Object containing state updates to apply. Keys are state variable names, values are the new values.
Indicates artifact updates. Key is the filename, value is the version number.
Name of the agent to transfer control to
If true, escalates to a higher-level agent
Authentication configurations requested by the event
Event compaction information indicating this event represents a summarized range of events
Invocation ID to rewind to. Only set for rewind events.
Properties
Controls whether function responses should be summarized by the model
stateDelta
Record<string, any>
default: "{}"
State changes to apply when this event is processed
artifactDelta
Record<string, number>
default: "{}"
Artifact updates with filename-to-version mapping
Target agent name for transfer operations
Flag indicating escalation to a higher-level agent
Authentication configurations needed for this event
Compaction metadata for summarized event ranges
Target invocation ID for conversation rewind operations
Usage Examples
State Management
Update agent state when processing events:
import { Event , EventActions } from '@iqai/adk' ;
const event = new Event ({
author: 'ShoppingAgent' ,
actions: new EventActions ({
stateDelta: {
cart: [ 'item1' , 'item2' ],
totalPrice: 49.99 ,
checkoutReady: true
}
}),
content: {
role: 'model' ,
parts: [{ text: 'Added items to cart' }]
}
});
Agent Transfer
Transfer control from one agent to another:
const transferEvent = new Event ({
author: 'RouterAgent' ,
actions: new EventActions ({
transferToAgent: 'PaymentAgent' ,
stateDelta: {
transferReason: 'checkout_initiated'
}
}),
content: {
role: 'model' ,
parts: [{ text: 'Transferring to payment processing...' }]
}
});
Escalation
Escalate to a higher-level agent when needed:
const escalationEvent = new Event ({
author: 'SupportAgent' ,
actions: new EventActions ({
escalate: true ,
stateDelta: {
escalationReason: 'complex_issue' ,
issueDescription: 'User request requires supervisor approval'
}
}),
content: {
role: 'model' ,
parts: [{ text: 'Escalating to supervisor...' }]
}
});
Artifact Management
Track changes to artifacts (files, documents, etc.):
const artifactEvent = new Event ({
author: 'DocumentAgent' ,
actions: new EventActions ({
artifactDelta: {
'report.pdf' : 2 ,
'summary.txt' : 1
},
stateDelta: {
lastModified: Date . now ()
}
}),
content: {
role: 'model' ,
parts: [{ text: 'Updated documents' }]
}
});
Function Response Control
Control how function responses are processed:
import { BaseTool , ToolContext } from '@iqai/adk' ;
class LongRunningTool extends BaseTool {
async execute ( context : ToolContext ) {
const result = await this . performLongOperation ();
// Skip summarization for large data responses
context . eventActions . skipSummarization = true ;
return result ;
}
}
Authentication Requests
Request authentication during agent execution:
const authEvent = new Event ({
author: 'APIAgent' ,
actions: new EventActions ({
requestedAuthConfigs: {
'github' : {
type: 'oauth' ,
scopes: [ 'repo' , 'user' ]
}
}
}),
content: {
role: 'model' ,
parts: [{ text: 'GitHub authentication required' }]
}
});
Event Compaction
Create a compacted event summarizing a range of events:
import { EventActions , EventCompaction } from '@iqai/adk' ;
const compactionData : EventCompaction = {
startTimestamp: 1704067200 ,
endTimestamp: 1704153600 ,
compactedContent: {
role: 'model' ,
parts: [{
text: 'Summary of 50 events from the last session...'
}]
}
};
const compactedEvent = new Event ({
author: 'system' ,
actions: new EventActions ({
compaction: compactionData
}),
content: compactionData . compactedContent
});
Conversation Rewind
Rewind conversation to a previous state:
const rewindEvent = new Event ({
author: 'system' ,
actions: new EventActions ({
rewindBeforeInvocationId: 'inv-12345' ,
stateDelta: {
rewindReason: 'user_requested'
}
}),
content: {
role: 'model' ,
parts: [{ text: 'Rewinding conversation...' }]
}
});
Type Reference
EventCompaction Interface
Data structure for event compaction:
interface EventCompaction {
startTimestamp : number ; // Unix timestamp in seconds
endTimestamp : number ; // Unix timestamp in seconds
compactedContent : Content ; // Summarized content from @google/genai
}
EventActionsOptions Interface
interface EventActionsOptions {
skipSummarization ?: boolean ;
stateDelta ?: Record < string , any >;
artifactDelta ?: Record < string , number >;
transferToAgent ?: string ;
escalate ?: boolean ;
requestedAuthConfigs ?: Record < string , any >;
compaction ?: EventCompaction ;
rewindBeforeInvocationId ?: string ;
}
Common Patterns
Chaining Actions
Combine multiple actions in a single event:
const complexEvent = new Event ({
author: 'OrchestratorAgent' ,
actions: new EventActions ({
stateDelta: {
phase: 'processing' ,
progress: 0.5
},
artifactDelta: {
'temp_file.json' : 1
},
transferToAgent: 'ProcessorAgent'
}),
content: {
role: 'model' ,
parts: [{ text: 'Processing and transferring...' }]
}
});
Conditional State Updates
Update state based on tool execution results:
class ConditionalTool extends BaseTool {
async execute ( context : ToolContext ) {
const result = await this . checkCondition ();
if ( result . success ) {
context . eventActions . stateDelta = {
status: 'complete' ,
result: result . data
};
} else {
context . eventActions . escalate = true ;
context . eventActions . stateDelta = {
status: 'failed' ,
error: result . error
};
}
return result ;
}
}
Event Learn about the Event class structure
BaseLlmFlow See how events flow through agent execution
Source Code
View the source: event-actions.ts