Skip to main content
Go beyond the visual interface by writing Python functions that connect your agent to APIs, databases, and business logic. This path is for developers who want to add custom capabilities that the UI alone cannot provide.
Python familiarity is required. If you are a non-technical operator, see Configure agents in the UI for the no-code path, or share this page with your developer.

What you can build

API integrations

Call external APIs to look up bookings, check availability, or retrieve account details

Business logic

Validate input, calculate pricing, or enforce rules that the LLM cannot handle alone

CRM and data writes

Create records, update customer profiles, or log interactions in external systems

Dynamic routing

Route calls to the right team based on real-time data or custom logic

Multi-step workflows

Build code-driven flows with transition functions for complex conversation paths

Real-time configuration

Define schemas that adapt agent behavior based on external config data

Get started

1

Write your first function

Follow the create a function guide to set up a Python function with parameters, code, and a description the LLM can use to trigger it.
2

Understand the tools system

Read the tools overview to learn how functions integrate with the LLM, how to use conv objects, and best practices for naming and triggering.
3

Explore advanced patterns

Dive into flows, call handoffs, and secrets management to build production-ready integrations.

Tools and functions

Write Python scripts that run when your agent needs to take action. Functions are the bridge between conversation and your business systems.

Create a function

Set up a function with naming conventions, parameters, and Python code

Start function

Initialize conversation context before the greeting plays

End function

Run post-call processing after a conversation ends

Return values

Control agent behavior with string and dictionary returns

Variables

Define, update, and persist values across turns

Libraries

Standard and non-standard libraries available in your functions

Delay control

Add filler phrases to avoid silence during slow functions

Use functions in topics

Trigger functions from managed topics

Reference

Access conversation data and built-in utilities from within your functions.

conv object

Conversation states, flows, and telephony attributes

conv.log

Structured diagnostics and PII-scoped logging

conv.utils

Built-in helpers for addresses, cities, and structured data

conv.api

Call configured API integrations

Agent memory

Persistent data across conversations for repeat callers

Function classes

VoiceWeighting, TTSVoice, and provider classes

Advanced capabilities

Secrets

Store API keys and credentials securely

Call handoffs

Configure call transfers and routing rules

Configuration builder

Define real-time config schemas for dynamic agent behavior

Call data export

Access transcripts and recordings via API

Code-driven flows

Build flows with transition functions and programmatic control

API reference

Integrate with PolyAI REST APIs for chat, conversations, alerts, and more
Last modified on March 21, 2026