Skip to content

Set up AI-filled attributes through MCP

Here is the whole loop for a Choice attribute the AI fills from the conversation, say a topic with the options Billing, Shipping and Returns, from an MCP client connected to Ray. The only stop outside the client is the approval link for the new definition and for publishing.

Read what exists

context_variables with the agent’s id lists the workspace’s attributes, each Choice attribute’s options in full, and how this agent uses each one. An enablement with source: "classified" is one the AI fills.

Create the attribute

prepare_context_variable with kind: "create" prepares the definition:

json
{
  "kind": "create",
  "agentId": "5b0f6a3e-2c1d-4f7a-9e8b-0c4d2a1b3f60",
  "name": "topic",
  "description": "What the visitor needs help with.",
  "valueType": "enum",
  "options": [
    { "key": "billing", "label": "Billing", "description": "Invoices, charges, refunds and payment methods." },
    { "key": "shipping", "label": "Shipping", "description": "Delivery times, tracking and parcels that have not arrived." },
    { "key": "returns", "label": "Returns", "description": "Sending a product back or exchanging it." }
  ],
  "trustTier": "unverified",
  "sensitivity": "normal",
  "defaultSurfacing": "on_reference"
}

A definition is shared by every agent in the workspace, so the review marks it lifecycle: "live" with publicationRequired: false, and its confirmation.approvalUrl asks you to approve it signed in. Approve it, then call execute_reviewed_proposal with the proposalId and reviewDigest. Its appliedRef carries the new variableId.

Have the AI fill it on the agent

prepare_context_variable again, with kind: "set_enablement", the variableId, and "enablement": { "source": "classified", "surfacing": "on_reference" }. This change goes to the agent’s draft (lifecycle: "agent_draft", publicationRequired: true) and, like a directive change, is confirmed in the conversation before execute_reviewed_proposal applies it.

The preparation fails with the reason when the AI can’t fill the attribute: it is not a Choice attribute, it is Private (sensitivity: sensitive), it is treated as proof (trustTier: signed), or the agent already has 8 attributes the AI fills. Read it back with context_variables: the enablement says source: "classified".

Try it in Test Chat

send_test_chat_message with no testExecutionId runs on a fresh candidate of the saved draft. Send a message such as “Why was I charged twice?”, then a second one in the same session. test_chat_turn_trace for a turn returns turnTrace.attributes: each attribute the AI fills, its value after that turn (an option key, or null), the option’s label, and writtenBy — classifier when the AI set it, operator when a Test Chat sample did. The AI never replaces a sample. A value the AI set on one turn is what the next turn’s rules and routine steps read.

Publish

prepare_agent_publication prepares the candidate; approve its review, then execute_reviewed_proposal publishes it. From then on every new customer conversation is classified after each reply; a conversation that started on an earlier release keeps that release’s attributes.

Read what the AI chose

conversation_history_search with "attribute": { "name": "topic", "option": "billing" } lists the conversations whose own topic is Billing, newest first; "option": "_not_set" lists those with no topic of their own. An archived option still finds the conversations that hold it. The name matches exactly as written. Ray refuses a name no attribute has, an option the attribute lacks, and an attribute that is not a Choice or is Private.

conversation_transcript for one of them returns its attributes beside the messages:

json
{
  "name": "topic",
  "valueType": "enum",
  "value": "billing",
  "option": { "label": "Billing", "archived": false },
  "redacted": false,
  "truncated": false,
  "scope": "conversation",
  "writtenBy": { "kind": "classifier", "ref": "context-classification/1" },
  "updatedAt": "2026-11-22T09:30:00.000Z",
  "classified": true
}

The list holds each attribute’s value for the conversation, the visitor’s chat session or the verified customer, whichever is most specific. The AI’s value is in the conversation scope with writtenBy.kind classifier. A Private attribute arrives with redacted: true and a value of null; who set it and when remain. A value longer than 500 characters arrives as its first 500, as text, with truncated: true. classified: true marks an attribute the conversation’s agent fills.

Correct a choice

When the AI picked the wrong option, set_conversation_attribute with the conversation’s id, "name": "topic" and "value": "shipping" sets it, as an option key, the way a teammate does from the Inbox. The value becomes the conversation’s own with writtenBy.kind operator, and the AI leaves it alone from then on. Setting the option the AI already picked keeps it the same way, and repeating a set changes nothing, so a retry is safe. reset_conversation_attribute with the conversation’s id and the name hands it back: the AI is asked to fill it again, and the result says classificationQueued: true. Both need the permission to take conversations over and refuse a Private attribute. A set also refuses an attribute that is not a Choice, while a reset clears the conversation’s own value of any type, such as a wrong Number a routine saved. Both return the attribute as conversation_transcript reads it next, or null when nothing holds a value. A set of an option the attribute lacks is refused with its option keys.

Change an attribute later

kind: "edit" changes an existing definition and, like a create, applies at once to every agent; its review lists them as usedBy, each with uses set to draft, published or both, because customers on the published release see the change too. A type change on an attribute that already has values is refused.

Have a routine save a field to an attribute

The AI fills Choice attributes only. A Text, Yes/no (boolean), Number, Date or JSON attribute is set by your API, your team, or a routine that collects the value. For a routine to save to one, the agent has to keep its value: create it with prepare_context_variable ("valueType": "number", say, for a party_size), then enable it with "enablement": { "source": "pushed", "surfacing": "on_reference" }.

Then name it on the routine’s field. propose_routine_edit sets it on an existing field:

json
{
  "agentId": "5b0f6a3e-2c1d-4f7a-9e8b-0c4d2a1b3f60",
  "routineId": "0c9e7d1a-4b2f-4e6a-8d3c-1f5a2b7e9c40",
  "changes": { "slots": [{ "key": "guests", "saveTo": { "contextVariable": "party_size", "scope": "conversation" } }] }
}

"scope": "person" saves to the visitor’s verified customer instead, and "saveTo": null stops saving. A new routine from prepare_routine_structure carries saveTo on its slots. routine_definition shows each field’s saveTo, and validate_routine reports a target the agent can’t save to with a save_to_* diagnostic, such as save_to_type_mismatch for a number field saved to a Text attribute. Publish the agent, and each conversation that finishes the routine holds the value; conversation_transcript lists it with writtenBy.kind routine. See Save a field to an attribute for when a value is saved.

  • MCP server — connect an MCP client to Ray through delegated Operator MCP access.
  • Attributes — every attribute setting, the scopes a value can have, and who may overwrite it.