agents / Exports / ActionTrackingEventService
Class: ActionTrackingEventService
ActionTrackingEventService - Enhanced EventService with automatic hierarchy tracking
Wraps any base EventService and adds automatic hierarchical context to all events. Uses Duck Typing pattern for zero-configuration integration with existing code.
Key Features:
- Automatic parent-child relationship tracking
- Execution level inference (Team=0, Agent=1, Tool=2)
- Bound emit functions with pre-filled context
- Full backward compatibility with base EventService
Example
const enhanced = new ActionTrackingEventService(new PlaygroundEventService());
// Track execution hierarchy
enhanced.trackExecution('agent-001', 'team-main', 1);
// Create bound emit with automatic context
const boundEmit = enhanced.createBoundEmit('agent-001');
boundEmit('execution.start', { sourceType: 'agent', sourceId: 'agent-001' });
// Automatically includes: parentExecutionId: 'team-main', executionLevel: 1Hierarchy
ActionTrackingEventService
Implements
Table of contents
Constructors
Methods
Constructors
constructor
• new ActionTrackingEventService(baseEventService?, logger?, executionContext?): ActionTrackingEventService
Parameters
| Name | Type |
|---|---|
baseEventService? | EventService |
logger? | SimpleLogger |
executionContext? | ToolExecutionContext |
Returns
Defined in
packages/agents/src/services/event-service.ts:289
Methods
emit
▸ emit(eventType, data): void
Standard emit method - forwards to base service with enriched hierarchy data
Parameters
| Name | Type |
|---|---|
eventType | string |
data | ServiceEventData |
Returns
void
Implementation of
Defined in
packages/agents/src/services/event-service.ts:298
trackExecution
▸ trackExecution(executionId, parentExecutionId?, level?): void
Track execution in the hierarchy Registers a new execution node with parent-child relationships
Parameters
| Name | Type |
|---|---|
executionId | string |
parentExecutionId? | string |
level? | number |
Returns
void
Implementation of
Defined in
packages/agents/src/services/event-service.ts:308
createBoundEmit
▸ createBoundEmit(executionId): (eventType: string, data: ServiceEventData) => void
Create bound emit function with automatic hierarchical context Returns a function that automatically includes parent/level information
Parameters
| Name | Type |
|---|---|
executionId | string |
Returns
fn
▸ (eventType, data): void
Parameters
| Name | Type |
|---|---|
eventType | string |
data | ServiceEventData |
Returns
void
Implementation of
Defined in
packages/agents/src/services/event-service.ts:337
createContextBoundInstance
▸ createContextBoundInstance(executionContext): EventService
🎯 [CONTEXT-BINDING] Create new EventService instance with injected context This enables automatic context propagation through the event system
Parameters
| Name | Type | Description |
|---|---|---|
executionContext | ToolExecutionContext | Context to inject into the new instance |
Returns
New EventService instance with context binding
Implementation of
EventService.createContextBoundInstance
Defined in
packages/agents/src/services/event-service.ts:360
getHierarchy
▸ getHierarchy(): Map<string, ExecutionNode>
Get current hierarchy state (for debugging)
Returns
Map<string, ExecutionNode>
Defined in
packages/agents/src/services/event-service.ts:741
clearHierarchy
▸ clearHierarchy(): void
Clear hierarchy state
Returns
void