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

# Export Agent

> Export an AI agent as a reusable template with configuration and knowledge bases

Export an agent into a portable template that can be shared across organizations. The template packages all agent components including configuration, tools, sub-agents, and optionally knowledge bases with their documents.

## Path Parameters

<ParamField path="agent_id" type="string" required>
  The unique identifier (UUID) of the agent to export
</ParamField>

## Request Body

<ParamField body="name" type="string" required>
  Display name for the template
</ParamField>

<ParamField body="description" type="string">
  Description of what the template does
</ParamField>

<ParamField body="icon" type="string">
  Emoji icon for the template (e.g., "🎧", "🚀")
</ParamField>

<ParamField body="with_knowledge_bases" type="boolean" default={true}>
  Controls whether knowledge bases and their document files are included in the export

  * `true`: Includes all knowledge bases with their documents and files
  * `false`: Exports only agent configuration without knowledge bases
</ParamField>

## Response

Returns an `AgentTemplate` object:

<ResponseField name="id" type="string">
  Unique identifier for the template (UUID)
</ResponseField>

<ResponseField name="name" type="string">
  Template display name
</ResponseField>

<ResponseField name="description" type="string">
  Template description
</ResponseField>

<ResponseField name="icon" type="string">
  Emoji icon representing the template
</ResponseField>

<ResponseField name="organization_id" type="string">
  UUID of the organization that created the template
</ResponseField>

<ResponseField name="agent_definition" type="object">
  Complete agent configuration

  <Expandable title="Agent Definition Object">
    <ResponseField name="id" type="string">
      Original agent ID
    </ResponseField>

    <ResponseField name="name" type="string">
      Agent name
    </ResponseField>

    <ResponseField name="description" type="string">
      Agent description
    </ResponseField>

    <ResponseField name="instructions" type="object">
      Agent instructions (role, goal, general)
    </ResponseField>

    <ResponseField name="custom_functions" type="array">
      Array of custom functions
    </ResponseField>

    <ResponseField name="connectors" type="array">
      Array of connected tools
    </ResponseField>

    <ResponseField name="sub_agents" type="array">
      Array of sub-agent definitions
    </ResponseField>

    <ResponseField name="knowledge_bases" type="array">
      Array of knowledge bases (if with\_knowledge\_bases is true)
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Request

```bash theme={"dark"}
curl -X POST -H "x-api-key: <your-api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Customer Support Agent Template",
    "description": "Pre-configured agent for customer support workflows",
    "icon": "🎧",
    "with_knowledge_bases": true
  }' \
  https://api.xpander.ai/v1/agents/<agent-id>/export
```

## Example Response

```json theme={"dark"}
{
  "id": "<template-id>",
  "name": "Customer Support Agent Template",
  "description": "Pre-configured agent for customer support workflows",
  "icon": "🎧",
  "organization_id": "<org-id>",
  "agent_definition": {
    "id": "<agent-id>",
    "name": "Customer Support Agent",
    "description": "Handles customer inquiries and provides support",
    "instructions": {
      "role": ["Customer support specialist"],
      "goal": ["Resolve customer issues efficiently"],
      "general": "Be helpful and professional"
    },
    "custom_functions": [],
    "connectors": [
      {
        "name": "Ticket System",
        "type": "api"
      }
    ],
    "sub_agents": [],
    "knowledge_bases": [
      {
        "name": "Product Documentation",
        "description": "Product guides and FAQs"
      }
    ]
  }
}
```

## Use Cases

* **Cross-Organization Sharing**: Share agent templates with other organizations
* **Backup & Version Control**: Create snapshots of agent configurations
* **Standardization**: Distribute pre-built agents across teams
* **Reusability**: Create templates for frequently used agent patterns

## Notes

* **Cross-Organization Sharing**: Templates can be shared across different organizations - the template ID works universally
* **Knowledge Base Size**: When `with_knowledge_bases: true`, the export includes all document content which may result in larger payloads
* **Tool Credentials**: Tool configurations are exported without credentials - recipients will need to provide their own API keys
* **Template Immutability**: Exported templates are snapshots and won't update if the original agent changes

## See Also

* [Import Agent](/api-reference/v1/agents/import-agent) - Create a new agent from a template
* [Create Agent](/api-reference/v1/agents/create-agent) - Create a new agent from scratch
* [Get Agent](/api-reference/v1/agents/get-agent) - Retrieve agent details


## OpenAPI

````yaml POST /v1/agents/{agent_id}/export
openapi: 3.1.0
info:
  title: xpander.ai API Service
  description: |2-

        The xpander.ai API Service provides a unified REST API for managing AI agents,
        executing tasks, managing knowledge bases, and integrating with external systems.
        
        Features:
        - Agent Management: Create, update, deploy, and delete AI agents
        - Task Execution: Invoke agents with support for sync, async, and streaming modes
        - Knowledge Bases: Manage knowledge bases and documents for RAG workflows
        - Tools: Discover, connect, and attach tools (connectors, custom functions, MCP servers, sub-agents, workflows) to agents and workflows
        - MCP Integration: Model Context Protocol support for standardized AI interactions
        
        Authentication: All endpoints require authentication via either an API key (`x-api-key`) or an OAuth2 JWT (`Authorization: Bearer <jwt>`).
        
  version: '0.001'
servers:
  - url: https://api.xpander.ai
security: []
paths:
  /v1/agents/{agent_id}/export:
    post:
      tags:
        - API v1
        - Agents
        - Agents Import/Export
      summary: Export Agent
      description: >-
        Exports an AI agent into a reusable template with configuration and
        knowledge bases
      operationId: Export_Agent_v1_agents__agent_id__export_post
      parameters:
        - name: agent_id
          in: path
          required: true
          schema:
            type: string
            title: Agent Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExportAgentRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentTemplate'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    ExportAgentRequest:
      properties:
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        icon:
          anyOf:
            - type: string
            - type: 'null'
          title: Icon
        with_knowledge_bases:
          anyOf:
            - type: boolean
            - type: 'null'
          title: With Knowledge Bases
          default: true
      type: object
      required:
        - name
      title: ExportAgentRequest
    AgentTemplate:
      properties:
        id:
          type: string
          title: Id
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        icon:
          type: string
          title: Icon
        organization_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Organization Id
        agent_definition:
          anyOf:
            - $ref: '#/components/schemas/AgentDefinition'
            - type: 'null'
      type: object
      required:
        - id
        - name
        - icon
      title: AgentTemplate
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    AgentDefinition:
      properties:
        id:
          type: string
          title: Id
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          default: ''
        unique_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Unique Name
          default: ''
        icon:
          anyOf:
            - type: string
            - type: 'null'
          title: Icon
          default: 🚀
        avatar:
          anyOf:
            - type: string
            - type: 'null'
          title: Avatar
          default: male-avatar
        type:
          anyOf:
            - $ref: '#/components/schemas/AgentType'
            - type: 'null'
        prompts:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Prompts
          default: []
        source_nodes:
          anyOf:
            - items:
                $ref: '#/components/schemas/AIAgentSourceNode'
              type: array
            - type: 'null'
          title: Source Nodes
          default: []
        attached_tools:
          anyOf:
            - items:
                $ref: '#/components/schemas/Connector'
              type: array
            - type: 'null'
          title: Attached Tools
          default: []
        access_scope:
          anyOf:
            - $ref: '#/components/schemas/AIAgentAccessScope'
            - type: 'null'
          default: organizational
        instructions:
          anyOf:
            - $ref: '#/components/schemas/AIAgentInstructions'
            - type: 'null'
          default:
            role: []
            goal: []
            general: ''
        oas:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Oas
          default: {}
        graph:
          anyOf:
            - items:
                $ref: '#/components/schemas/AIAgentGraphItem-Output'
              type: array
            - type: 'null'
          title: Graph
          default: []
        status:
          anyOf:
            - $ref: '#/components/schemas/AgentStatus'
            - type: 'null'
          default: ACTIVE
        version:
          anyOf:
            - type: integer
            - type: 'null'
          title: Version
          default: 1
        model_provider:
          anyOf:
            - $ref: '#/components/schemas/LLMModelProvider'
            - type: 'null'
          default: openai
        model_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Model Name
          default: gpt-5.2
        custom_functions:
          items:
            $ref: '#/components/schemas/CustomFunction'
          type: array
          title: Custom Functions
        connectors:
          items:
            $ref: '#/components/schemas/ConnectedConnector'
          type: array
          title: Connectors
        sub_agents:
          items:
            $ref: '#/components/schemas/AgentDefinition'
          type: array
          title: Sub Agents
          default: []
        knowledge_bases:
          items:
            $ref: '#/components/schemas/ExportedKnowledgeBase'
          type: array
          title: Knowledge Bases
          default: []
      type: object
      required:
        - id
        - name
        - custom_functions
        - connectors
      title: AgentDefinition
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    AgentType:
      type: string
      enum:
        - manager
        - regular
        - a2a
        - curl
        - orchestration
      title: AgentType
      description: |-
        Enumeration of the agent types.

        Attributes:
            Manager: marks the agent as a Managing agent.
            Regular: marks the agent as a regular agent.
            A2A: marks the agent as an external agent used via A2A protocol.
            Curl: marks the agent as an external agent used via a CURL.
            Orchestration: marks the agent as an Orchestration object.
    AIAgentSourceNode:
      properties:
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
        type:
          $ref: '#/components/schemas/SourceNodeType'
        targets:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Targets
        metadata:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Metadata
          default: {}
      type: object
      required:
        - type
      title: AIAgentSourceNode
    Connector:
      properties:
        id:
          type: string
          title: Id
        operation_ids:
          items:
            type: string
          type: array
          title: Operation Ids
      type: object
      required:
        - id
        - operation_ids
      title: Connector
      description: >-
        Connector model representing the structure of a connector with an ID and
        associated operation IDs.


        Attributes:
            id (str): The unique identifier for the connector.
            operation_ids (list[str]): A list of operation IDs associated with the connector.
    AIAgentAccessScope:
      type: string
      enum:
        - personal
        - organizational
      title: AIAgentAccessScope
    AIAgentInstructions:
      properties:
        role:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Role
          default: []
        goal:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Goal
          default: []
        general:
          anyOf:
            - type: string
            - type: 'null'
          title: General
          default: ''
      type: object
      title: AIAgentInstructions
    AIAgentGraphItem-Output:
      properties:
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
        item_id:
          type: string
          title: Item Id
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        type:
          $ref: '#/components/schemas/AIAgentGraphItemType'
        sub_type:
          anyOf:
            - $ref: '#/components/schemas/AIAgentGraphItemSubType'
            - type: 'null'
        targets:
          items:
            type: string
          type: array
          title: Targets
        settings:
          anyOf:
            - $ref: '#/components/schemas/AIAgentGraphItemSettings-Output'
            - type: 'null'
        is_first:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Is First
          default: false
      type: object
      required:
        - item_id
        - type
        - targets
      title: AIAgentGraphItem
    AgentStatus:
      type: string
      enum:
        - DRAFT
        - ACTIVE
        - INACTIVE
      title: AgentStatus
      description: |-
        Enumeration of possible agent statuses.

        Attributes:
            DRAFT: Agent is in a draft state.
            ACTIVE: Agent is active and operational.
            INACTIVE: Agent is inactive and not operational.
    LLMModelProvider:
      type: string
      enum:
        - openai
        - nim
        - amazon_bedrock
        - azure_ai_foundary
        - huggingFace
        - friendlyAI
        - anthropic
        - gemini
        - fireworks
        - google_ai_studio
        - helicone
        - bytedance
        - tzafon_lightcone
        - open_router
        - nebius
        - cloudflare_ai_gw
      title: LLMModelProvider
    CustomFunction:
      properties:
        id:
          type: string
          title: Id
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        input_schema:
          additionalProperties: true
          type: object
          title: Input Schema
        technical_description:
          anyOf:
            - type: string
            - type: 'null'
          title: Technical Description
        status:
          $ref: '#/components/schemas/CustomFunctionStatus'
        limits:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Limits
          default: {}
        source_code:
          type: string
          title: Source Code
      type: object
      required:
        - id
        - name
        - input_schema
        - status
        - source_code
      title: CustomFunction
    ConnectedConnector:
      properties:
        id:
          type: string
          title: Id
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
          default: ''
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          default: ''
        open_api_spec_id:
          type: string
          title: Open Api Spec Id
        general_params:
          anyOf:
            - items:
                $ref: '#/components/schemas/GeneralParam'
              type: array
            - type: 'null'
          title: General Params
          default: []
        operation_ids:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Operation Ids
          default: []
        operations_with_details:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          title: Operations With Details
          default: []
        cc_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Cc Id
        root_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Root Id
        code:
          anyOf:
            - type: string
            - type: 'null'
          title: Code
        openapi_spec:
          anyOf:
            - type: string
            - type: 'null'
          title: Openapi Spec
        is_custom:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Is Custom
          default: false
        owner:
          anyOf:
            - type: string
            - type: 'null'
          title: Owner
        version:
          anyOf:
            - type: number
            - type: 'null'
          title: Version
        total_operations:
          anyOf:
            - type: integer
            - type: 'null'
          title: Total Operations
        operations_map:
          anyOf:
            - additionalProperties:
                $ref: '#/components/schemas/ConnectorOperation'
              type: object
            - type: 'null'
          title: Operations Map
      type: object
      required:
        - id
        - open_api_spec_id
      title: ConnectedConnector
    ExportedKnowledgeBase:
      properties:
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        documents:
          anyOf:
            - items:
                $ref: '#/components/schemas/ExportedKnowledgeBaseDocument'
              type: array
            - type: 'null'
          title: Documents
          default: []
      type: object
      required:
        - name
      title: ExportedKnowledgeBase
    SourceNodeType:
      type: string
      enum:
        - workbench
        - sdk
        - task
        - assistant
        - webhook
        - mcp
        - a2a
        - telegram
        - slack
      title: SourceNodeType
    AIAgentGraphItemType:
      type: string
      enum:
        - source_node
        - agent
        - workflow
        - tool
        - human_in_the_loop
        - xpsleep-agent-delay
        - custom_agent
        - storage
        - local_db
        - coding_agent
        - mcp
        - skills
      title: AIAgentGraphItemType
    AIAgentGraphItemSubType:
      type: string
      enum:
        - sdk
        - task
        - assistant
        - webhook
        - operation
        - custom_function
        - local_tool
      title: AIAgentGraphItemSubType
    AIAgentGraphItemSettings-Output:
      properties:
        instructions:
          anyOf:
            - type: string
            - type: 'null'
          title: Instructions
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        schemas:
          anyOf:
            - $ref: '#/components/schemas/AIAgentGraphItemSchema'
            - type: 'null'
        advanced_filtering_options:
          anyOf:
            - $ref: '#/components/schemas/AIAgentGraphItemAdvancedFilteringOption'
            - type: 'null'
        hitl_options:
          anyOf:
            - $ref: '#/components/schemas/AIAgentGraphItemHITLSettings'
            - type: 'null'
        a2a_options:
          anyOf:
            - $ref: '#/components/schemas/AIAgentGraphItemA2ASettings'
            - type: 'null'
        coding_agent_settings:
          anyOf:
            - $ref: '#/components/schemas/AIAgentGraphItemCodingAgentSettings'
            - type: 'null'
        mcp_settings:
          anyOf:
            - $ref: '#/components/schemas/AIAgentGraphItemMCPSettings'
            - type: 'null'
        skills_settings:
          anyOf:
            - $ref: '#/components/schemas/AIAgentGraphItemSkillsSettings'
            - type: 'null'
        use_cache:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Use Cache
          default: false
      type: object
      title: AIAgentGraphItemSettings
    CustomFunctionStatus:
      type: string
      enum:
        - draft
        - analysing
        - ready
        - error
      title: CustomFunctionStatus
    GeneralParam:
      properties:
        name:
          type: string
          title: Name
        description:
          type: string
          title: Description
        location:
          type: string
          enum:
            - path
            - query
            - header
            - cookie
          title: Location
        value:
          anyOf:
            - type: string
            - type: 'null'
          title: Value
      type: object
      required:
        - name
        - description
        - location
      title: GeneralParam
    ConnectorOperation:
      properties:
        path:
          type: string
          title: Path
        method:
          type: string
          title: Method
      type: object
      required:
        - path
        - method
      title: ConnectorOperation
    ExportedKnowledgeBaseDocument:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
        content:
          anyOf:
            - type: string
            - type: 'null'
          title: Content
      type: object
      title: ExportedKnowledgeBaseDocument
    AIAgentGraphItemSchema:
      properties:
        input:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Input
        output:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Output
      type: object
      title: AIAgentGraphItemSchema
    AIAgentGraphItemAdvancedFilteringOption:
      properties:
        returnables:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Returnables
        searchables:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Searchables
        globally_enabled:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Globally Enabled
          default: false
      type: object
      title: AIAgentGraphItemAdvancedFilteringOption
    AIAgentGraphItemHITLSettings:
      properties:
        title:
          anyOf:
            - type: string
            - type: 'null'
          title: Title
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        recipients:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Recipients
        hitl_type:
          anyOf:
            - $ref: '#/components/schemas/AIAgentHITLType'
            - type: 'null'
        slack_app:
          anyOf:
            - type: string
            - type: 'null'
          title: Slack App
        should_approve_with_current_user:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Should Approve With Current User
          default: true
      type: object
      title: AIAgentGraphItemHITLSettings
    AIAgentGraphItemA2ASettings:
      properties:
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
      type: object
      title: AIAgentGraphItemA2ASettings
    AIAgentGraphItemCodingAgentSettings:
      properties:
        type:
          anyOf:
            - type: string
              const: codex
            - type: 'null'
          title: Type
          default: codex
      type: object
      title: AIAgentGraphItemCodingAgentSettings
    AIAgentGraphItemMCPSettings:
      properties:
        type:
          anyOf:
            - $ref: '#/components/schemas/MCPServerType'
            - type: 'null'
          default: remote
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        command:
          anyOf:
            - type: string
            - type: 'null'
          title: Command
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
        transport:
          anyOf:
            - $ref: '#/components/schemas/MCPServerTransport'
            - type: 'null'
          default: streamable-http
        auth_type:
          anyOf:
            - $ref: '#/components/schemas/MCPServerAuthType'
            - type: 'null'
          default: none
        api_key:
          anyOf:
            - type: string
            - type: 'null'
          title: Api Key
        use_secrets_manager:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Use Secrets Manager
          default: false
        client_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Client Id
        client_secret:
          anyOf:
            - type: string
            - type: 'null'
          title: Client Secret
        additional_scopes:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Additional Scopes
          default: []
        headers:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Headers
          default: {}
        env_vars:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Env Vars
          default: {}
        allowed_tools:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Allowed Tools
          default: []
        share_user_token_across_other_agents:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Share User Token Across Other Agents
          default: true
      type: object
      title: AIAgentGraphItemMCPSettings
    AIAgentGraphItemSkillsSettings:
      properties:
        enabled_skills:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Enabled Skills
          default: []
      type: object
      title: AIAgentGraphItemSkillsSettings
    AIAgentHITLType:
      type: string
      enum:
        - slack
      title: AIAgentHITLType
    MCPServerType:
      type: string
      enum:
        - local
        - remote
      title: MCPServerType
    MCPServerTransport:
      type: string
      enum:
        - stdio
        - sse
        - streamable-http
      title: MCPServerTransport
    MCPServerAuthType:
      type: string
      enum:
        - api_key
        - oauth2
        - custom_headers
        - none
      title: MCPServerAuthType
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: API Key for authentication
      in: header
      name: x-api-key

````