Package com.tnsai.events
Interface TnsAIEvent
- All Known Implementing Classes:
AgentHierarchyEvent,ApprovalRequestEvent,ArtifactEvent,BDIUpdateEvent,ErrorEvent,RunEndEvent,RunStartEvent,SkillActivationEvent,StatusEvent,TextDeltaEvent,ThoughtEvent,ToolCallEndEvent,ToolCallStartEvent,UiComponentEvent
public sealed interface TnsAIEvent
permits ThoughtEvent, TextDeltaEvent, ToolCallStartEvent, ToolCallEndEvent, BDIUpdateEvent, ArtifactEvent, ApprovalRequestEvent, RunStartEvent, RunEndEvent, ErrorEvent, StatusEvent, UiComponentEvent, AgentHierarchyEvent, SkillActivationEvent
Sealed interface representing internal TnsAI events.
This event hierarchy provides a type-safe way to represent all events that can occur during agent execution. Events are used for:
- Real-time streaming to frontends (via AG-UI protocol)
- Observability and logging
- Event sourcing patterns
- Human-in-the-loop workflows
Event types:
ThoughtEvent- Agent's reasoning/thinking processTextDeltaEvent- Streaming text chunksToolCallStartEvent- Tool execution startedToolCallEndEvent- Tool execution completedBDIUpdateEvent- BDI state change (belief, desire, intention)ArtifactEvent- Artifact creation (code, files, etc.)ApprovalRequestEvent- Human approval requiredRunStartEvent- Agent run startedRunEndEvent- Agent run completedErrorEvent- Error occurred
Example usage:
agent.chatWithEvents("Hello")
.subscribe(event -> {
switch (event) {
case TextDeltaEvent delta -> System.out.print(delta.content());
case ToolCallStartEvent tool -> System.out.println("Calling: " + tool.toolName());
case ErrorEvent error -> System.err.println("Error: " + error.message());
default -> {}
}
});
- Author:
- TnsAI Team
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioneventId()Returns the unique identifier of this event.default StringReturns the type of this event as a string.static StringGenerates a new unique event ID.static Instantnow()Returns the current timestamp.Returns the timestamp when this event was created.
-
Method Details
-
eventId
String eventId()Returns the unique identifier of this event.- Returns:
- event ID (never null)
-
timestamp
Instant timestamp()Returns the timestamp when this event was created.- Returns:
- event timestamp (never null)
-
eventType
Returns the type of this event as a string.- Returns:
- event type name (never null)
-
generateEventId
Generates a new unique event ID.- Returns:
- new UUID string
-
now
Returns the current timestamp.- Returns:
- current instant
-