rtc_session

View as MarkdownOpen in Claude

Decorator that registers the session entrypoint function. The entrypoint receives a JobContext and is responsible for creating an Agent, AgentSession, and calling session.start().

Parameters

func
Optional[Callable]Defaults to None

The entrypoint function. When used as @server.rtc_session() with parentheses, func is None and the decorator returns a wrapper. When used as @server.rtc_session without parentheses, the function is passed directly.

agent_name
strDefaults to ""

A name for the agent. Stored on the server for identification.

type
strDefaults to "room"

Session type. Only "room" is supported on SignalWire. Other values are accepted for API compatibility but log an informational message.

on_request
AnyDefaults to None

Callback for incoming requests. Accepted for API compatibility.

on_session_end
AnyDefaults to None

Callback for session end. Accepted for API compatibility.

Returns

Callable — The decorated function, unmodified.

Example

1from signalwire.livewire import (
2 Agent,
3 AgentSession,
4 AgentServer,
5 JobContext,
6 JobProcess,
7 run_app,
8)
9
10server = AgentServer()
11
12def setup(proc: JobProcess):
13 proc.userdata["api_key"] = "sk-..."
14
15server.setup_fnc = setup
16
17@server.rtc_session(agent_name="support-bot")
18async def entrypoint(ctx: JobContext):
19 await ctx.connect()
20 agent = Agent(instructions="You are a support bot.")
21 session = AgentSession()
22 await session.start(agent, room=ctx.room)
23
24run_app(server)