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

# Attach a tool to an agent

> Adds a tool to the agent's `tools[]`. `type` MUST be one of
`file_search`, `mcp`, or `function`. The tool name must match
`^[a-zA-Z0-9_-]+$` (OpenAI tool-name constraint). When the
agent is published, `has_draft_changes` is set to `true`.




## OpenAPI

````yaml /api-reference/agent-factory/swagger.yml post /v1/agents/{agentId}/tools
openapi: 3.0.3
info:
  version: 1.0.0
  title: Agent Factory API
  description: |
    Public REST API for the Agent Factory workspace - agents, conversations,
    messages, tools, artifacts, sharing, ratings, and discovery.
    Powered by Prisme.ai's runtime; all endpoints are exposed under each
    workspace's webhook namespace.
  contact:
    name: Prisme.ai
    url: https://prisme.ai
servers:
  - url: https://{host}/v2/workspaces/slug:agent-factory/webhooks
    description: Prisme.ai workspace webhooks
    variables:
      host:
        default: api.studio.prisme.ai
        description: API host (override for self-hosted or sandbox)
security:
  - BearerAuth: []
  - OrgApiKeyAuth: []
tags:
  - name: Agents
    description: Agent CRUD, discovery, AGENTS.md import/export.
  - name: Access
    description: Agent access bindings, sharing, and access requests.
  - name: ApiKeys
    description: Agent-scoped API key management (mint, revoke, rotate).
  - name: Publishing
    description: Publish or discard draft changes on an agent.
  - name: Ratings
    description: User ratings on published agents.
  - name: Profiles
    description: >-
      Agent profiles/presets catalog (simple, workflow, agent_light, agent_full,
      orchestrator).
  - name: Activity
    description: Activity feed for agents (events, errors, lifecycle changes).
  - name: Analytics
    description: Agent usage analytics (series + summary).
  - name: Conversations
    description: Conversations on an agent (CRUD, archive, star).
  - name: Messages
    description: Send messages to an agent (synchronous send + SSE stream).
  - name: Tasks
    description: Async task lifecycle (list, fetch, cancel, resolve, subscribe).
  - name: Artifacts
    description: Generated artifacts (files, code, content) attached to a task.
  - name: Shares
    description: Conversation, message, and artifact share-link snapshots.
  - name: A2A
    description: Agent-to-agent JSON-RPC 2.0 gateway (well-known agent.json + RPC).
  - name: Tools
    description: Per-agent tool catalogue (system tools, MCP servers, function tools).
  - name: Retention
    description: Per-agent and org-wide conversation retention policies.
  - name: Evaluations
    description: Agent evaluation runs and results.
paths:
  /v1/agents/{agentId}/tools:
    post:
      tags:
        - Tools
      summary: Attach a tool to an agent
      description: |
        Adds a tool to the agent's `tools[]`. `type` MUST be one of
        `file_search`, `mcp`, or `function`. The tool name must match
        `^[a-zA-Z0-9_-]+$` (OpenAI tool-name constraint). When the
        agent is published, `has_draft_changes` is set to `true`.
      operationId: addAgentTool
      parameters:
        - name: agentId
          in: path
          required: true
          schema:
            type: string
            maxLength: 64
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ToolAddInput'
            example:
              type: file_search
              name: test_file_search
              description: Test file search tool
              vector_store_id: vs_test_123
              catalog_id: template-file-search
      responses:
        '200':
          description: Tool added.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Tool'
        '400':
          description: Validation error (invalid type, bad tool name, missing fields).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Authentication required.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Agent not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '405':
          description: Method not allowed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: A tool with the same name already exists on this agent.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ToolAddInput:
      type: object
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - file_search
            - mcp
            - function
          maxLength: 64
        name:
          type: string
          maxLength: 128
          pattern: ^[a-zA-Z0-9_-]+$
        display_name:
          type: string
          maxLength: 256
        description:
          type: string
          maxLength: 4096
        catalog_id:
          type: string
          maxLength: 128
        auth:
          type: object
          additionalProperties: true
        icon_url:
          type: string
          maxLength: 2048
        vector_store_id:
          type: string
          maxLength: 128
          description: Required for `file_search`.
        server:
          type: string
          maxLength: 2048
          description: MCP server URL (for `mcp`).
        headers:
          type: object
          additionalProperties: true
        scope:
          type: string
          maxLength: 256
        url:
          type: string
          maxLength: 2048
          description: Required for `function`.
        parameters:
          type: object
          additionalProperties: true
          description: JSON Schema describing the function tool's parameters.
    Tool:
      type: object
      description: |
        Tool entry attached to an agent. Discriminated by `type` -
        `file_search` (requires `vector_store_id`), `mcp` (uses `server`,
        `headers`, `scope`), or `function` (uses `url`, `parameters`,
        `headers`).
      additionalProperties: true
      properties:
        id:
          type: string
        type:
          type: string
          enum:
            - file_search
            - mcp
            - function
        name:
          type: string
          pattern: ^[a-zA-Z0-9_-]+$
        display_name:
          type: string
        description:
          type: string
        catalog_id:
          type: string
        auth:
          type: object
          additionalProperties: true
        icon_url:
          type: string
        vector_store_id:
          type: string
          description: Required for `file_search`.
        server:
          type: string
          description: MCP server URL (for `mcp`).
        headers:
          type: object
          additionalProperties: true
        scope:
          type: string
        url:
          type: string
          description: Required for `function`.
        parameters:
          type: object
          additionalProperties: true
          description: JSON Schema describing the function tool's parameters.
    Error:
      type: object
      required:
        - error
        - message
      properties:
        error:
          type: string
          description: >-
            Stable PascalCase or SNAKE_CASE error code (e.g. AgentNotFound,
            VALIDATION_ERROR, FORBIDDEN, METHOD_NOT_ALLOWED).
        message:
          type: string
          description: Human-readable error message.
        details:
          type: object
          description: Optional structured context for the error.
          additionalProperties: true
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: |
        User-bound credential carrying an identity: either a session JWT
        or a user access token (`at:*`) generated from the user settings UI.
        Send as `Authorization: Bearer <token>`.
        Org API keys (`iak_*`) are **not** accepted here - they carry
        no user identity. Use the `x-prismeai-api-key` header instead
        (see `OrgApiKeyAuth`).
    OrgApiKeyAuth:
      type: apiKey
      in: header
      name: x-prismeai-api-key
      description: |
        Organization API key (`iak_{orgSlug}_{uuid}`). Unlike
        `Authorization: Bearer`, this credential is **not** tied to a user
        identity - it is bound to the org and its effective access is
        defined by the scopes / permission rules attached to it (it can
        be restricted to a single project, or kept broader).
        For Agent Factory, these keys can be generated directly from
        the Agent Factory UI (in addition to the AI Governance settings).
        Send as `x-prismeai-api-key: iak_...`.

````