set_conversation_metadata
Store a key-value pair as metadata on the current conversation.
set_conversation_metadata(context: dict, key: str, value: str) -> dictStores a metadata key-value pair on the conversation. If the key already exists, the value is updated.
Parameters
| Name | Type | Description |
|---|---|---|
context | dict | The context object passed to your action |
key | str | The metadata key (max 200 characters) |
value | str | The 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}