Ai knowledge and logicHelpers

set_conversation_metadata

Store a key-value pair as metadata on the current conversation.

set_conversation_metadata(context: dict, key: str, value: str) -> dict

Stores a metadata key-value pair on the conversation. If the key already exists, the value is updated.


Parameters

NameTypeDescription
contextdictThe context object passed to your action
keystrThe metadata key (max 200 characters)
valuestrThe value to store (max 50,000 characters)

Returns

dict{"success": bool, "message": str, "key": str, "value": str}

Limits

  • Maximum key length: 200 characters
  • Maximum value length: 50,000 characters
  • Maximum 200 key-value pairs per conversation

Behavior

  • If the key already exists, its value is overwritten.
  • In test/mock environments, returns a mock success response without persisting.

Examples

Track a refund amount for analytics

def execute_action(context):
    # ... process refund ...
    set_conversation_metadata(context, "refund_amount", "49.99")
    set_conversation_metadata(context, "refund_reason", "damaged_product")
    return {"success": True, "amount": 49.99}

Store a computed value for later use

def execute_action(context):
    order = fetch_order(context["args"]["orderId"])
    risk_score = calculate_risk(order)

    set_conversation_metadata(context, "risk_score", str(risk_score))

    return {"riskScore": risk_score, "order": order}

On this page