Routes

Routes are the event processing pipelines. They connect events to processing logic.

What is a Route?

Routes connect events to processing logic. They create pipelines where data flows through operations.

Basic Example

1# Simple event routing
2bridge.on(UserTranscriptionReceived).map(node.add_event)

Routes are built using a fluent API, where operations can be chained together:

1# Generate responses when user stops speaking.
2(
3 bridge.on(UserStoppedSpeaking) # Trigger route on UserStoppedSpeaking event.
4 .stream(chat_node.generate) # Process the event using `node.generate()`. Stream (i.e. yield) output events.
5 .broadcast() # Broadcast the output events.
6 .interrupt_on( # If UserStartedSpeaking event occurs while route is running, cancel the route and run the handler.
7 UserStartedSpeaking,
8 handler=chat_node.on_interrupt_generate,
9 )
10)

Core Operations

OperationDescription
on(Event)Listen for specific event types
map(function)Transform data by applying a function
filter(condition)Continue processing only if condition is met
stream(generator)Process async generators that yield multiple values
broadcast()Send results to other components (terminal operation)

Key Features

  • Declarative Processing: Define what happens when events occur
  • Pipeline Chaining: Link operations to transform and route data
  • Interrupt Handling: Gracefully handle conversation interruptions
  • Multi-Agent Coordination: Route events between different agents

Routes enable event processing patterns and agent coordination. See Agent Patterns for pipeline examples.