update_agent

View as MarkdownOpen in Claude

Swap in a new Agent mid-session. The new agent’s instructions and tools replace the previous agent’s configuration on the underlying SignalWire platform.

Parameters

agent
AgentRequired

The new Agent to bind to this session.

Returns

None

Example

1from signalwire.livewire import Agent, AgentSession, AgentServer, JobContext, function_tool, run_app
2
3@function_tool
4def check_balance(account_id: str) -> str:
5 """Check an account balance."""
6 return f"Account {account_id} has $142.50."
7
8@function_tool
9def transfer_funds(from_acct: str, to_acct: str, amount: float) -> str:
10 """Transfer funds between accounts."""
11 return f"Transferred ${amount} from {from_acct} to {to_acct}."
12
13server = AgentServer()
14
15@server.rtc_session()
16async def entrypoint(ctx: JobContext):
17 await ctx.connect()
18 basic_agent = Agent(instructions="You help check balances.", tools=[check_balance])
19 session = AgentSession()
20 await session.start(basic_agent, room=ctx.room)
21 advanced_agent = Agent(instructions="You handle transfers.", tools=[transfer_funds])
22 session.update_agent(advanced_agent)
23
24run_app(server)