### Clone Repository and Install Dependencies Source: https://github.com/livekit-examples/outbound-caller-python/blob/main/README.md Clone the LiveKit outbound caller Python repository and set up a virtual environment with necessary dependencies. ```shell git clone https://github.com/livekit-examples/outbound-caller-python.git cd outbound-caller-python python3 -m venv venv source venv/bin/activate pip install -r requirements.txt python agent.py download-files ``` -------------------------------- ### Run the Agent in Development Mode Source: https://github.com/livekit-examples/outbound-caller-python/blob/main/README.md Execute the agent script to start the outbound caller agent, which will then wait for dispatches to initiate calls. ```shell python3 agent.py dev ``` -------------------------------- ### Python Function Tool Definition Source: https://github.com/livekit-examples/outbound-caller-python/blob/main/_autodocs/README.md Example of defining a function tool within the OutboundCaller class. This method is exposed to the LLM for invocation during a conversation. Ensure the function is decorated with `@function_tool()` and includes a docstring explaining its purpose. ```python from livekit_agents.outbound_caller import OutboundCaller, RunContext class OutboundCaller: @function_tool() async def transfer_call(self, ctx: RunContext) -> str: """Transfer the call to a human agent""" pass @function_tool() async def end_call(self, ctx: RunContext) -> str: """Terminate the call""" pass @function_tool() async def look_up_availability(self, ctx: RunContext) -> str: """Check appointment slots""" pass @function_tool() async def confirm_appointment(self, ctx: RunContext) -> str: """Book an appointment""" pass @function_tool() async def detected_answering_machine(self, ctx: RunContext) -> str: """Handle voicemail""" pass ``` -------------------------------- ### Dispatch an Agent to Make an Outbound Call Source: https://github.com/livekit-examples/outbound-caller-python/blob/main/README.md Use the LiveKit CLI to dispatch the 'outbound-caller' agent to initiate a call. Specify the target phone number and an optional number to transfer the call to. ```shell lk dispatch create \ --new-room \ --agent-name outbound-caller \ --metadata '{"phone_number": "+1234567890", "transfer_to": "+9876543210"}' ``` -------------------------------- ### Python Error Handling with TwirpError Source: https://github.com/livekit-examples/outbound-caller-python/blob/main/_autodocs/README.md This snippet demonstrates how to catch and log specific Twirp API errors, accessing metadata for details like SIP status, and shutting down the context upon error. ```python try: await ctx.api.sip.create_sip_participant(request) except api.TwirpError as e: logger.error(f"SIP error: {e.metadata.get('sip_status')}") ctx.shutdown() ```