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

# Tạo Tác nhân

> Tạo tác nhân AI mới với ví được bảo mật bằng MPC.

Tạo tác nhân mới với ví được bảo mật bằng MPC được cung cấp tự động. Địa chỉ ví được tạo bằng Tạo Khóa Phân tán (DKG) và sẵn sàng nhận quỹ ngay lập tức.

## Nội dung Yêu cầu

<ParamField body="agent_name" type="string" required>
  Tên hiển thị cho tác nhân. Phải là duy nhất trong tài khoản của bạn.
</ParamField>

<ParamField body="agent_description" type="string">
  Mô tả tùy chọn về mục đích của tác nhân.
</ParamField>

<ParamField body="chain" type="string" required>
  Định danh chuỗi CAIP-2 cho ví tác nhân. Xem [Các Chuỗi được Hỗ trợ](/vi/platform/supported-chains) để biết các tùy chọn có sẵn.

  Ví dụ: `eip155:1` (Ethereum), `eip155:8453` (Base), `eip155:84532` (Base Sepolia testnet)
</ParamField>

<ParamField body="metadata" type="string">
  Chuỗi metadata mã hóa JSON cho các cặp khóa-giá trị tùy chỉnh.
</ParamField>

## Phản hồi

<Expandable title="Các trường phản hồi">
  <ParamField body="id" type="string">
    Định danh tác nhân duy nhất (ví dụ: `agent_abc123`).
  </ParamField>

  <ParamField body="agent_name" type="string">
    Tên hiển thị tác nhân.
  </ParamField>

  <ParamField body="wallet" type="object">
    <Expandable title="Các trường wallet">
      <ParamField body="address" type="string">
        Địa chỉ ví on-chain.
      </ParamField>

      <ParamField body="chain" type="string">
        Định danh chuỗi CAIP-2.
      </ParamField>
    </Expandable>
  </ParamField>

  <ParamField body="status" type="string">
    Trạng thái tác nhân: `active` hoặc `inactive`.
  </ParamField>

  <ParamField body="created_at" type="string">
    Dấu thời gian tạo ISO 8601.
  </ParamField>
</Expandable>

## Ví dụ

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.agentwallex.com/api/v1/agents \
    -H "X-API-Key: awx_your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "agent_name": "research-bot",
      "agent_description": "Market research automation agent",
      "chain": "eip155:84532",
      "metadata": "{\"team\":\"growth\"}"
    }'
  ```

  ```typescript TypeScript theme={null}
  const agent = await aw.agents.create({
    name: "research-bot",
    chain: "eip155:84532",
    metadata: { team: "growth" },
  });
  ```

  ```python Python theme={null}
  agent = await aw.agents.create(
      name="research-bot",
      chain="eip155:84532",
      metadata={"team": "growth"},
  )
  ```
</CodeGroup>

```json Response theme={null}
{
  "id": "agent_abc123",
  "agent_name": "research-bot",
  "agent_description": "Market research automation agent",
  "wallet": {
    "address": "0x1234567890abcdef1234567890abcdef12345678",
    "chain": "eip155:84532"
  },
  "status": "active",
  "created_at": "2025-06-01T10:00:00Z"
}
```


## OpenAPI

````yaml POST /api/v1/agents
openapi: 3.1.0
info:
  title: AgentWallex API
  description: >-
    REST API for managing AI agent wallets, on-chain transactions, spending
    policies, webhooks, and x402 micropayments.
  version: 1.0.0
  contact:
    name: AgentWallex Support
    url: https://agentwallex.com
servers:
  - url: https://api.agentwallex.com
    description: Production
  - url: https://api-sandbox.agentwallex.com
    description: Sandbox
security:
  - ApiKeyAuth: []
  - BearerAuth: []
tags:
  - name: Agents
    description: Create and manage AI agent wallets.
  - name: Transactions
    description: Send payments and query transaction history.
  - name: Policies
    description: Configure spending limits and access controls.
  - name: Webhooks
    description: Register and manage webhook endpoints.
  - name: x402
    description: x402 micropayment negotiation and session management.
paths:
  /api/v1/agents:
    post:
      tags:
        - Agents
      summary: Create Agent
      description: >-
        Create a new agent with an automatically provisioned MPC-secured wallet.
        The wallet address is generated using Distributed Key Generation (DKG)
        and is ready to receive funds immediately.
      operationId: createAgent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - agent_name
                - chain
              properties:
                agent_name:
                  type: string
                  description: >-
                    Display name for the agent. Must be unique within your
                    account.
                agent_description:
                  type: string
                  description: Optional description of the agent's purpose.
                chain:
                  type: string
                  description: >-
                    CAIP-2 chain identifier for the agent's wallet (e.g.,
                    `eip155:1` for Ethereum, `eip155:8453` for Base,
                    `eip155:84532` for Base Sepolia testnet).
                metadata:
                  type: string
                  description: JSON-encoded metadata string for custom key-value pairs.
            example:
              agent_name: research-bot
              agent_description: Market research automation agent
              chain: eip155:84532
              metadata: '{"team":"growth"}'
      responses:
        '200':
          description: Agent created successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Agent'
              example:
                id: agent_abc123
                agent_name: research-bot
                agent_description: Market research automation agent
                wallet:
                  address: '0x1234567890abcdef1234567890abcdef12345678'
                  chain: eip155:84532
                status: active
                created_at: '2025-06-01T10:00:00Z'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    Agent:
      type: object
      description: An AI agent with an MPC-secured wallet.
      properties:
        id:
          type: string
          description: Unique agent identifier (e.g., `agent_abc123`).
        agent_name:
          type: string
          description: Agent display name.
        agent_description:
          type: string
          description: Agent description.
        wallet:
          $ref: '#/components/schemas/Wallet'
        status:
          type: string
          enum:
            - active
            - inactive
          description: Agent status.
        metadata:
          type: string
          description: JSON-encoded metadata string.
        created_at:
          type: string
          format: date-time
          description: ISO 8601 creation timestamp.
    Wallet:
      type: object
      description: An on-chain wallet associated with an agent.
      properties:
        address:
          type: string
          description: On-chain wallet address.
        chain:
          type: string
          description: CAIP-2 chain identifier.
    ErrorResponse:
      type: object
      description: Standard error response.
      required:
        - code
        - type
        - message
      properties:
        code:
          type: string
          description: Machine-readable error code.
        type:
          type: string
          enum:
            - invalid_request_error
            - authentication_error
            - authorization_error
            - not_found_error
            - rate_limit_error
            - internal_error
          description: Error type category.
        message:
          type: string
          description: Human-readable error description.
  responses:
    BadRequest:
      description: Invalid request body or parameters.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: invalid_request
            type: invalid_request_error
            message: The request body is missing required fields.
    Unauthorized:
      description: Missing or invalid credentials.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: authentication_failed
            type: authentication_error
            message: The provided API key is invalid or expired.
    Forbidden:
      description: Insufficient permissions.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: insufficient_permissions
            type: authorization_error
            message: You do not have permission to perform this action.
    RateLimited:
      description: Rate limit exceeded.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: rate_limit_exceeded
            type: rate_limit_error
            message: Too many requests. Please retry after a short delay.
    InternalError:
      description: Server-side error.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            code: server_error
            type: internal_error
            message: An unexpected error occurred. Please try again later.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: API key authentication. Keys are prefixed with `awx_`.
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT bearer token authentication.

````