Events

Events are Python objects that components use to communicate in the Line SDK.

What is an Event?

An event is a Python object that carries information between nodes, bridges, and the user.

Basic Example

1from pydantic import BaseModel
2from line.events import UserTranscriptionReceived, AgentResponse
3
4# Built-in events
5user_message = UserTranscriptionReceived(content="Hello, how are you?")
6agent_reply = AgentResponse(content="I'm doing well, thank you!")
7
8# Custom events
9class CustomerInsight(BaseModel):
10 customer_id: str
11 sentiment: str
12 priority_level: str
13
14insight = CustomerInsight(
15 customer_id="123",
16 sentiment="positive",
17 priority_level="high"
18)

Built-in Event Types

For a full list of built-in events and their descriptions, see line/events.py.

CategoryEvents
User EventsUserTranscriptionReceived, UserStartedSpeaking, UserStoppedSpeaking
Agent EventsAgentResponse, AgentStartedSpeaking, AgentStoppedSpeaking
System EventsToolCall, ToolResult, AgentHandoff, EndCall

Events let components communicate without being tightly coupled. See Agent Patterns for examples.

Defining Custom Event Types

Any object can be an event. This is useful for passing arbitrary data between components.

Use structured classes like Pydantic BaseModel or Python dataclasses for your custom events. This provides type safety and validation and makes your code more readable.

1from pydantic import BaseModel
2
3class MyEvent(BaseModel):
4 field1: str
5 field2: int

Messages

Messages are the wrappers around events. They contain the event, but also additional metadata:

FieldDescription
eventThe event object
sourceThe node that sent the event
timestampThe time the event was sent

Messages are automatically wrapped in Messages before being sent to the bus.