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(
6 content="Hello, how are you?"
7)
8agent_reply = AgentResponse(content="I'm doing well, thank you!")
9
10
11# Custom events
12class CustomerInsight(BaseModel):
13 customer_id: str
14 sentiment: str
15 priority_level: str
16
17
18insight = CustomerInsight(
19 customer_id="123", sentiment="positive", priority_level="high"
20)

Built-in Event Types

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

| Category | Events | |----------|--------| | User Events | UserTranscriptionReceived, UserStartedSpeaking, UserStoppedSpeaking | | Agent Events | AgentResponse, AgentStartedSpeaking, AgentStoppedSpeaking | | System Events | ToolCall, 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
3
4class MyEvent(BaseModel):
5 field1: str
6 field2: int

Messages

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

| Field | Description | |-------|-------------| | event | The event object | | source | The node that sent the event | | timestamp | The time the event was sent |

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