> ## Documentation Index
> Fetch the complete documentation index at: https://docs.poly.ai/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.poly.ai/feedback

```json
{
  "path": "/extend/introduction",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# Extend with code

> Write Python functions to integrate APIs, validate input, and add custom business logic to your agent.

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.

<Info>
  **Python familiarity is required.** If you are a non-technical operator, see [Configure agents in the UI](/get-started/introduction) for the no-code path, or share this page with your developer.
</Info>

<Tip>Before writing custom API code, check if a [pre-built integration](/integrations/introduction) already exists for your platform (e.g., Salesforce, Zendesk, OpenTable, Stripe). Pre-built integrations handle authentication, environment configuration, and common operations out of the box.</Tip>

## What you can build

<CardGroup cols={3}>
  <Card title="API integrations" icon="plug" href="/tools/classes/conv-api">
    Call external APIs to look up bookings, check availability, or retrieve account details
  </Card>

  <Card title="Business logic" icon="gears" href="/tools/introduction">
    Validate input, calculate pricing, or enforce rules that the LLM cannot handle alone
  </Card>

  <Card title="CRM and data writes" icon="database" href="/tools/how-to-setup">
    Create records, update customer profiles, or log interactions in external systems
  </Card>

  <Card title="Dynamic routing" icon="phone-arrow-right" href="/call-handoff/introduction">
    Route calls to the right team based on real-time data or custom logic
  </Card>

  <Card title="Multi-step workflows" icon="diagram-project" href="/flows/transition-functions">
    Build code-driven flows with transition functions for complex conversation paths
  </Card>

  <Card title="Real-time configuration" icon="wrench" href="/configuration-builder/introduction">
    Define schemas that adapt agent behavior based on external config data
  </Card>
</CardGroup>

## Get started

<Steps>
  <Step title="Write your first function">
    Follow the [create a function](/tools/how-to-setup) guide to set up a Python function with parameters, code, and a description the LLM can use to trigger it.
  </Step>

  <Step title="Understand the tools system">
    Read the [tools overview](/tools/introduction) to learn how functions integrate with the LLM, how to use `conv` objects, and best practices for naming and triggering.
  </Step>

  <Step title="Explore advanced patterns">
    Dive into [flows](/flows/introduction), [call handoffs](/call-handoff/introduction), and [secrets management](/secrets/introduction) to build production-ready integrations.
  </Step>
</Steps>

## 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.

<CardGroup cols={2}>
  <Card title="Create a function" icon="plus" href="/tools/how-to-setup">
    Set up a function with naming conventions, parameters, and Python code
  </Card>

  <Card title="Start tool" icon="play" href="/tools/start-tool">
    Initialize conversation context before the greeting plays
  </Card>

  <Card title="End tool" icon="stop" href="/tools/end-tool">
    Run post-call processing after a conversation ends
  </Card>

  <Card title="Return values" icon="reply" href="/tools/return-values">
    Control agent behavior with string and dictionary returns
  </Card>

  <Card title="Variables" icon="database" href="/tools/variables">
    Define, update, and persist values across turns
  </Card>

  <Card title="Libraries" icon="book" href="/tools/import-library">
    Standard and non-standard libraries available in your functions
  </Card>

  <Card title="Delay control" icon="clock" href="/tools/delay-control">
    Add filler phrases to avoid silence during slow functions
  </Card>

  <Card title="Use functions in topics" icon="link" href="/tools/using-tools-in-knowledge-base">
    Trigger functions from managed topics
  </Card>
</CardGroup>

## Reference

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

<CardGroup cols={2}>
  <Card title="conv object" icon="code" href="/tools/classes/conv-object">
    Conversation states, flows, and telephony attributes
  </Card>

  <Card title="conv.log" icon="file-lines" href="/tools/classes/conv-log">
    Structured diagnostics and PII-scoped logging
  </Card>

  <Card title="conv.utils" icon="wrench" href="/tools/classes/conv-utils">
    Built-in helpers for addresses, cities, and structured data
  </Card>

  <Card title="conv.api" icon="plug" href="/tools/classes/conv-api">
    Call configured API integrations
  </Card>

  <Card title="Agent memory" icon="brain" href="/tools/classes/agent-memory">
    Persistent data across conversations for repeat callers
  </Card>

  <Card title="Function classes" icon="cube" href="/tools/classes">
    VoiceWeighting, TTSVoice, and provider classes
  </Card>
</CardGroup>

## Advanced capabilities

<CardGroup cols={2}>
  <Card title="Secrets" icon="key" href="/secrets/introduction">
    Store API keys and credentials securely
  </Card>

  <Card title="Call handoffs" icon="phone-arrow-right" href="/call-handoff/introduction">
    Configure call transfers and routing rules
  </Card>

  <Card title="Configuration builder" icon="wrench" href="/configuration-builder/introduction">
    Define real-time config schemas for dynamic agent behavior
  </Card>

  <Card title="Call data export" icon="database" href="/call-data/introduction">
    Access transcripts and recordings through the API
  </Card>

  <Card title="Code-driven flows" icon="diagram-project" href="/flows/transition-functions">
    Build flows with transition functions and programmatic control
  </Card>

  <Card title="Script agent configuration" icon="wand-magic-sparkles" href="/api-reference/agents/introduction">
    Use the Agents API to create, configure, and deploy agents from code
  </Card>

  <Card title="API reference" icon="square-terminal" href="/api-reference/introduction">
    Integrate with PolyAI REST APIs for chat, conversations, alerts, and more
  </Card>
</CardGroup>
