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

# Update function

> Partially update a function on a branch: name, description, code, parameters, or latency control. Renaming also rewrites the `def` name inside the code body. Returns 409 Conflict if the rename would orphan flow-step references — pass `force: true` in the body to rename anyway. Changes are drafts until the branch is deployed.



## OpenAPI

````yaml api-reference/agents/openapi.json PATCH /v1/agents/{agentId}/branches/{branchId}/functions/{functionId}
openapi: 3.1.0
info:
  title: PolyAI Agents API
  version: 1.0.11
  description: Manage PolyAI agents, telephony, deployments, and real-time configs.
servers:
  - url: https://api.us.poly.ai
    description: US region
  - url: https://api.eu.poly.ai
    description: EU region
  - url: https://api.uk.poly.ai
    description: UK region
  - url: https://api.studio.poly.ai
    description: Studio region
security:
  - polyApiKey: []
paths:
  /v1/agents/{agentId}/branches/{branchId}/functions/{functionId}:
    parameters:
      - name: agentId
        in: path
        required: true
        schema:
          type: string
      - name: branchId
        in: path
        required: true
        schema:
          type: string
      - name: functionId
        in: path
        required: true
        schema:
          type: string
    patch:
      tags:
        - Functions
      summary: Update a function
      description: >-
        Partially update a function on a branch: name, description, code,
        parameters, or latency control. Renaming also rewrites the `def` name
        inside the code body. Returns 409 Conflict if the rename would orphan
        flow-step references — pass `force: true` in the body to rename anyway.
        Changes are drafts until the branch is deployed.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateFunctionPublicBody'
      responses:
        '200':
          description: Updated function
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FunctionPublicResponse'
        '404':
          description: Function not found
components:
  schemas:
    UpdateFunctionPublicBody:
      title: UpdateFunctionPublicBody
      description: Partial update to a custom function.
      type: object
      properties:
        name:
          type: string
          minLength: 1
        description:
          type: string
        code:
          type: string
        parameters:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
                minLength: 1
              description:
                type: string
              type:
                type: string
                enum:
                  - string
                  - number
                  - boolean
                  - integer
            required:
              - name
              - description
              - type
            additionalProperties: false
        latencyControl:
          type: object
          properties:
            enabled:
              type: boolean
              default: false
            randomize:
              type: boolean
              default: false
            initialDelay:
              type: number
              default: 0
            interval:
              type: number
              default: 0
            delayResponses:
              type: array
              default: []
              items:
                type: object
                properties:
                  message:
                    type: string
                  duration:
                    type: number
                required:
                  - message
                  - duration
                additionalProperties: false
          additionalProperties: false
        force:
          type: boolean
      additionalProperties: false
    FunctionPublicResponse:
      title: FunctionPublicResponse
      description: >-
        A custom function on a branch, including its code, parameters, and any
        simulated-latency configuration.
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        description:
          type: string
        code:
          type: string
        parameters:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              name:
                type: string
              description:
                type: string
              type:
                type: string
            required:
              - id
              - name
              - description
              - type
            additionalProperties: false
        errors:
          type: array
          items:
            type: object
            properties:
              lineno:
                type: number
              message:
                type: string
              text:
                type: string
            required:
              - lineno
              - message
            additionalProperties: false
        latencyControl:
          type: object
          properties:
            enabled:
              type: boolean
            randomize:
              type: boolean
              default: false
            initialDelay:
              type: number
            interval:
              type: number
            delayResponses:
              type: array
              items:
                type: object
                properties:
                  message:
                    type: string
                  duration:
                    type: number
                required:
                  - message
                  - duration
                additionalProperties: false
          required:
            - enabled
            - initialDelay
            - interval
            - delayResponses
          additionalProperties: false
        archived:
          type: boolean
      required:
        - id
        - name
        - description
        - code
        - parameters
        - errors
        - archived
      additionalProperties: false
  securitySchemes:
    polyApiKey:
      type: apiKey
      in: header
      name: X-API-KEY

````