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

from signalwire.livewire import (
Agent,
AgentSession,
AgentServer,
JobContext,
JobProcess,
function_tool,
run_app,
)
@function_tool
def lookup_order(order_id: str) -> str:
"""Look up an order by ID."""
return f"Order {order_id} shipped yesterday."
server = AgentServer()
def on_setup(proc: JobProcess):
proc.userdata["db_url"] = "postgres://localhost/orders"
server.setup_fnc = on_setup
@server.rtc_session()
async def entrypoint(ctx: JobContext):
await ctx.connect()
agent = Agent(
instructions="You are an order tracking assistant.",
tools=[lookup_order],
)
session = AgentSession()
await session.start(agent, room=ctx.room)
session.say("Hello! I can help you track your orders.")
run_app(server)