AgentsLiveWire

run_app

View as MarkdownOpen in Claude

run_app

run_app(server) -> None

The main entry point for a LiveWire application. It prints the ASCII banner, runs the setup function (if registered on the server), creates a JobContext, invokes the registered entrypoint, prints a random tip, and starts the underlying SignalWire agent.

This mirrors livekit.agents.cli.run_app. It is also available as cli_ns.run_app.

Parameters

server
AgentServerRequired

The AgentServer instance with a registered entrypoint.

Returns

None — This function blocks while the agent is running.

Lifecycle

  1. Prints the LiveWire ASCII banner to stderr.
  2. If server.setup_fnc is set, calls it with a fresh JobProcess instance.
  3. Creates a JobContext.
  4. Calls the entrypoint registered via @server.rtc_session(). If the entrypoint is a coroutine, it is awaited.
  5. Prints a random “Did you know?” tip to stderr.
  6. Starts the underlying SignalWire agent (blocking).

Example

1from signalwire.livewire import (
2 Agent,
3 AgentSession,
4 AgentServer,
5 JobContext,
6 JobProcess,
7 function_tool,
8 run_app,
9)
10
11@function_tool
12def lookup_order(order_id: str) -> str:
13 """Look up an order by ID."""
14 return f"Order {order_id} shipped yesterday."
15
16server = AgentServer()
17
18def on_setup(proc: JobProcess):
19 proc.userdata["db_url"] = "postgres://localhost/orders"
20
21server.setup_fnc = on_setup
22
23@server.rtc_session()
24async def entrypoint(ctx: JobContext):
25 await ctx.connect()
26 agent = Agent(
27 instructions="You are an order tracking assistant.",
28 tools=[lookup_order],
29 )
30 session = AgentSession()
31 await session.start(agent, room=ctx.room)
32 session.say("Hello! I can help you track your orders.")
33
34run_app(server)