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

# Bloco de restrições

> O que um cliente quer, recusa e é, para as ferramentas deste turno; o mesmo bloco que `include: ["constraints"]` acrescenta a uma leitura de contexto, aqui renderizável para uma ferramenta. Funcionalidade `signals`.



## OpenAPI

````yaml openapi/pt/cell.json POST /v1/constraints
openapi: 3.1.0
info:
  title: API de dados da Niadra
  version: '1'
  description: >-
    Escrita, contexto, histórico, objetos, identidade, privacidade e governança
    de um espaço. Cada espaço tem um endereço estável, com o espaço e a região
    no nome.
servers:
  - url: https://{space}.{region}.api.niadra.com
    variables:
      space:
        default: acme-prod
        description: O espaço, que vem na chave de fonte.
      region:
        default: us-east-2
        description: A região do espaço, que também vem na chave.
security: []
paths:
  /v1/constraints:
    post:
      tags:
        - signals
      summary: Bloco de restrições
      description: >-
        O bloco de restrições de um cliente, o mesmo que `include:
        ["constraints"]` acrescenta a uma leitura de contexto; `for` pede o de
        um beneficiário.


        **Autenticação.** Chave de fonte: `Authorization: Bearer nia_sk_...`.
        Escopo exigido: `context`. Só responde num espaço com a funcionalidade
        `signals` ligada (o documento `features`); num espaço sem ela, 404.
      operationId: constraints_v1_constraints_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ConstraintsRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConstraintsBlock'
          description: Resposta de sucesso.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: O pedido não bate com o contrato.
      security:
        - sourceKey: []
      x-codeSamples:
        - lang: python
          label: Python
          source: |-
            # The block comes with the pack, in the same round trip
            context = conversation.context(include=["constraints"])
            block = context.constraints  # hard, soft, attributes, exclude, ask
        - lang: typescript
          label: TypeScript
          source: >-
            // The block comes with the pack, in the same round trip

            const ctx = await convo.context({ include: ["constraints"] });

            const block = ctx.constraints; // hard, soft, attributes, exclude,
            ask
components:
  schemas:
    ConstraintsRequest:
      additionalProperties: false
      properties:
        conversation_id:
          anyOf:
            - maxLength: 512
              minLength: 1
              type: string
            - type: 'null'
          title: Conversation Id
        for:
          default: self
          pattern: ^(?:self|gift|beneficiary:[A-Za-z0-9_-]{1,64})$
          title: For
          type: string
        subject:
          $ref: '#/components/schemas/Handle'
        tool:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: Renderizado para as vinculações desta ferramenta.
          title: Tool
      required:
        - subject
      title: ConstraintsRequest
      type: object
    ConstraintsBlock:
      additionalProperties: false
      description: >-
        O que um cliente quer, recusa e é, para as ferramentas deste turno
        (`constraints.v0`).
      properties:
        already_presented:
          items:
            $ref: '#/components/schemas/Shown'
          maxItems: 200
          title: Already Presented
          type: array
        ask:
          description: >-
            Perguntas que o agente deve fazer, como `for_whom`, antes de
            presumir.
          items:
            maxLength: 256
            minLength: 1
            type: string
          title: Ask
          type: array
        attributes:
          items:
            $ref: '#/components/schemas/AttributeEntry'
          maxItems: 50
          title: Attributes
          type: array
        conflicts:
          items:
            $ref: '#/components/schemas/Conflict'
          maxItems: 50
          title: Conflicts
          type: array
        exclude:
          items:
            pattern: ^[a-z][a-z0-9_]{0,39}:[^:\s]{1,256}:\S{1,512}$
            type: string
          maxItems: 200
          title: Exclude
          type: array
        hard:
          items:
            $ref: '#/components/schemas/HardConstraint'
          maxItems: 100
          title: Hard
          type: array
        precedence:
          items:
            enum:
              - current_utterance
              - stated_persistent
              - inferred
            type: string
          title: Precedence
          type: array
        relaxation_order:
          description: 'O que cede primeiro quando uma busca não acha nada: `soft`, ids.'
          items:
            type: string
          title: Relaxation Order
          type: array
        rendered:
          anyOf:
            - $ref: '#/components/schemas/Rendered'
            - type: 'null'
        rules:
          items:
            $ref: '#/components/schemas/CompanyRule'
          maxItems: 50
          title: Rules
          type: array
        soft:
          items:
            $ref: '#/components/schemas/SoftConstraint'
          maxItems: 100
          title: Soft
          type: array
        subject:
          $ref: '#/components/schemas/BlockSubject'
        text:
          description: >-
            O bloco em linhas para um modelo, no idioma do espaço, cada campo
            pelo rótulo dele e cada operador em palavras; uma string vazia
            quando o bloco não tem nada a dizer. Não entra em `version`.
          title: Text
          type: string
        version:
          description: Um digest do bloco, que o registro do turno cita.
          pattern: ^cv_[0-9a-f]{8,64}$
          title: Version
          type: string
      required:
        - version
        - text
      title: ConstraintsBlock
      type: object
    Problem:
      additionalProperties: false
      description: >-
        Detalhes do problema no formato da RFC 9457; `code` vem do catálogo de
        erros versionado.
      properties:
        code:
          title: Code
          type: string
        detail:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Detail
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Request Id
        status:
          title: Status
          type: integer
        title:
          title: Title
          type: string
        type:
          default: about:blank
          title: Type
          type: string
      required:
        - title
        - status
        - code
      title: Problem
      type: object
    Handle:
      additionalProperties: false
      description: >-
        Um identificador de um sujeito num canal ou sistema: um telefone, um
        e-mail, um id do CRM.
      properties:
        scope:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: >-
            Espaço de nomes dos identificadores com escopo: a conta do WhatsApp
            Business para `wa_bsuid`, o sistema para `system_id`, o país para
            `gov_id_hmac`.
          title: Scope
        subject_kind:
          anyOf:
            - $ref: '#/components/schemas/SubjectKind'
            - type: 'null'
          description: >-
            O padrão é `person`, exceto nos tipos de handle que só identificam
            organizações.
        type:
          $ref: '#/components/schemas/HandleType'
        value:
          maxLength: 320
          minLength: 1
          title: Value
          type: string
          description: >-
            O identificador. Normalizado no servidor: E.164 para telefone,
            minúsculas para e-mail.
      required:
        - type
        - value
      title: Handle
      type: object
    Shown:
      additionalProperties: false
      properties:
        last_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Last At
        ref:
          pattern: ^[a-z][a-z0-9_]{0,39}:[^:\s]{1,256}:\S{1,512}$
          title: Ref
          type: string
        times:
          minimum: 1
          title: Times
          type: integer
        values:
          additionalProperties:
            $ref: '#/components/schemas/ShownValue'
          description: >-
            Os números com que o objeto foi mostrado por último (um preço, um
            total, um desconto, uma parcela), por campo: cada campo que o tipo
            declara como `money`, `percent` ou `number`. A conferência de
            afirmações os toma como evidência da oferta que o agente repete.
          title: Values
          type: object
      required:
        - ref
        - times
      title: Shown
      type: object
    AttributeEntry:
      additionalProperties: false
      properties:
        apply:
          enum:
            - always
            - when_asked
          title: Apply
          type: string
        category:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: Category
        confidence:
          maximum: 1
          minimum: 0
          title: Confidence
          type: number
        id:
          pattern: ^z[0-9]{1,4}$
          title: Id
          type: string
        name:
          pattern: ^[a-z][a-z0-9_]{0,63}(?:\.[a-z0-9_]{1,64}){0,3}$
          title: Name
          type: string
        source:
          enum:
            - stated
            - correction
            - acquired
            - kept
            - returned_for_size
            - inferred
          title: Source
          type: string
        system:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: System
        value:
          anyOf:
            - type: boolean
            - type: integer
            - type: number
            - maxLength: 256
              type: string
          title: Value
      required:
        - id
        - name
        - value
        - confidence
        - source
        - apply
      title: AttributeEntry
      type: object
    Conflict:
      additionalProperties: false
      description: >-
        Duas entradas que não podem valer juntas, e a que venceu: a fala de
        agora sobre o que foi dito antes, e uma entrada declarada sobre uma
        inferida. Entre duas regras da empresa, é também um problema de dados.
      properties:
        by:
          enum:
            - current_utterance
            - precedence
            - rule_rank
          title: By
          type: string
        ids:
          items:
            type: string
          maxItems: 10
          minItems: 2
          title: Ids
          type: array
        kept:
          title: Kept
          type: string
      required:
        - ids
        - kept
        - by
      title: Conflict
      type: object
    HardConstraint:
      additionalProperties: false
      description: 'Só o que a pessoa disse: uma inferência nunca é rígida.'
      properties:
        attr:
          pattern: ^[a-z][a-z0-9_]{0,39}\.[a-z][a-z0-9_]{0,63}$
          title: Attr
          type: string
        category:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: Category
        expires_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Expires At
        id:
          pattern: ^h[0-9]{1,4}$
          title: Id
          type: string
        op:
          enum:
            - in
            - not_in
            - eq
            - ne
            - lt
            - lte
            - gt
            - gte
            - between
          title: Op
          type: string
        origin:
          $ref: '#/components/schemas/ConstraintOrigin'
        relax:
          default: never
          enum:
            - never
            - ask
          title: Relax
          type: string
        scope:
          enum:
            - turn
            - session
            - persistent
          title: Scope
          type: string
        source:
          enum:
            - stated
            - tool_args
            - correction
          title: Source
          type: string
        values:
          items:
            anyOf:
              - type: boolean
              - type: integer
              - type: number
              - maxLength: 256
                type: string
          maxItems: 50
          minItems: 1
          title: Values
          type: array
      required:
        - id
        - attr
        - op
        - values
        - source
        - scope
        - origin
      title: HardConstraint
      type: object
    Rendered:
      additionalProperties: false
      description: >-
        O bloco para uma ferramenta, pelas vinculações dela (`constraints.v0`,
        renderização).
      properties:
        args:
          additionalProperties: true
          description: Valores de argumento que levam restrições rígidas e atributos.
          title: Args
          type: object
        mode:
          enum:
            - advisory
            - apply
          title: Mode
          type: string
        post_filter:
          description: >-
            Ids residuais que o SDK filtra dos resultados de uma busca com
            sobra.
          items:
            type: string
          title: Post Filter
          type: array
        residual:
          description: Ids que nenhum argumento da ferramenta consegue expressar.
          items:
            type: string
          title: Residual
          type: array
        tool:
          maxLength: 256
          minLength: 1
          title: Tool
          type: string
      required:
        - tool
        - mode
        - args
      title: Rendered
      type: object
    CompanyRule:
      additionalProperties: false
      description: >-
        Uma regra da empresa entregue no bloco, com onde ela mora e a posição
        dela na ordem que a empresa declarou: o bloco nunca ordena duas origens
        por conta própria.
      properties:
        attr:
          anyOf:
            - pattern: ^[a-z][a-z0-9_]{0,39}\.[a-z][a-z0-9_]{0,63}$
              type: string
            - type: 'null'
          title: Attr
        id:
          pattern: ^r[0-9]{1,4}$
          title: Id
          type: string
        op:
          anyOf:
            - enum:
                - in
                - not_in
                - eq
                - ne
                - lt
                - lte
                - gt
                - gte
                - between
              type: string
            - type: 'null'
          title: Op
        origin:
          description: '`code`, `db:<tabela>`, `prompt:<versão>`, `policy:<versão>`...'
          maxLength: 256
          minLength: 1
          title: Origin
          type: string
        rank:
          maximum: 100
          minimum: 1
          title: Rank
          type: integer
        values:
          items:
            anyOf:
              - type: boolean
              - type: integer
              - type: number
              - maxLength: 256
                type: string
          maxItems: 50
          title: Values
          type: array
      required:
        - id
        - origin
        - rank
      title: CompanyRule
      type: object
    SoftConstraint:
      additionalProperties: false
      properties:
        attr:
          pattern: ^[a-z][a-z0-9_]{0,39}\.[a-z][a-z0-9_]{0,63}$
          title: Attr
          type: string
        category:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          title: Category
        confidence:
          maximum: 1
          minimum: 0
          title: Confidence
          type: number
        id:
          pattern: ^s[0-9]{1,4}$
          title: Id
          type: string
        polarity:
          default: prefer
          enum:
            - prefer
            - avoid
          title: Polarity
          type: string
        source:
          enum:
            - inferred
            - stated
          title: Source
          type: string
        value:
          anyOf:
            - type: boolean
            - type: integer
            - type: number
            - maxLength: 256
              type: string
          title: Value
        weight:
          maximum: 1
          minimum: 0
          title: Weight
          type: number
      required:
        - id
        - attr
        - value
        - weight
        - confidence
        - source
      title: SoftConstraint
      type: object
    BlockSubject:
      additionalProperties: false
      properties:
        for:
          default: self
          pattern: ^(?:self|gift|beneficiary:[A-Za-z0-9_-]{1,64})$
          title: For
          type: string
      title: BlockSubject
      type: object
    SubjectKind:
      enum:
        - person
        - account
        - partner
      title: SubjectKind
      type: string
      description: >-
        Uma pessoa, uma organização cliente (`account`) ou uma organização que
        participa sem ser cliente (`partner`).
    HandleType:
      enum:
        - phone_e164
        - wa_id
        - wa_jid
        - wa_lid
        - wa_bsuid
        - email
        - gov_id_hmac
        - app_user_id
        - system_id
        - org_registry_hmac
        - email_domain
        - anon_id
      title: HandleType
      type: string
      description: >-
        O tipo de identificador. O valor é classificado pelo formato, nunca pelo
        campo de onde veio.
    ShownValue:
      additionalProperties: false
      description: Um número que um objeto mostrou ao cliente, como ele foi mostrado.
      properties:
        claim_safe:
          description: >-
            Se pode ser afirmado agora: o tipo deixa afirmar o campo, e não
            passou mais do que a idade de afirmação do campo desde que foi
            mostrado.
          title: Claim Safe
          type: boolean
        role:
          anyOf:
            - maxLength: 256
              minLength: 1
              type: string
            - type: 'null'
          description: O papel do campo, para afirmações.
          title: Role
        v:
          title: V
          type: number
      required:
        - v
        - claim_safe
      title: ShownValue
      type: object
    ConstraintOrigin:
      additionalProperties: false
      properties:
        event_key:
          anyOf:
            - maxLength: 512
              minLength: 1
              type: string
            - type: 'null'
          title: Event Key
        kind:
          enum:
            - stated
            - tool_args
            - correction
          title: Kind
          type: string
        turn_id:
          anyOf:
            - maxLength: 512
              minLength: 1
              type: string
            - type: 'null'
          title: Turn Id
      required:
        - kind
      title: ConstraintOrigin
      type: object
  securitySchemes:
    sourceKey:
      type: http
      scheme: bearer
      description: nia_sk_...

````