Python helpers

Human decision helpers

Ask a teammate for one decision from Python while the bot keeps the conversation.

request_human_decision(context: dict, key: str, summary: str, decisions: list, info: dict = None, timeout_hours: int = None) -> dict
get_human_decision_result(context: dict, key: str) -> dict
resolve_human_decisions(context: dict, answers: list, conversation_id: str = None) -> dict

These helpers let the bot ask your team for one specific decision, such as approving an exchange, without handing over the conversation. An agent answers on a card in the conversation. The bot is then triggered again, reads the outcome and continues with the customer.

This page is the reference. For the complete setup with the request and check actions, workflow instructions and testing, read Human-in-the-loop decisions. To let someone outside Octocom decide, for example from a link in Slack, follow the external decisions playbook.

HelperWhere you call itWhat it does
request_human_decisionUsually a bot actionCreates the decision card, or returns the existing one
get_human_decision_resultUsually a bot actionReads the pending, resolved or expired outcome
resolve_human_decisionsOnly HTTP endpoints, recurring jobs, event handlers and sidebar actionsRecords a decision made outside the dashboard

request_human_decision

Registers a request for a decision, shown to agents as an Action requested card with buttons. The customer never sees it. The helper returns immediately; Python does not wait for the decision.

ParameterTypeDescription
contextdictThe action's context, including the current conversation
keystrStable identifier for this request within the conversation, 1 to 100 characters
summarystrWhat the agent needs to decide. Must not be empty
decisionslistOne or more buttons, each {"key": ..., "label": ...} with an optional input (see below)
infodictOptional read-only fields shown on the card, as {label: value}. Values are sent as strings
timeout_hoursint or NoneHours a pending request may wait before it expires, 1 to 336. Defaults to 48

A decision can ask the agent to type one value:

{"key": "reject", "label": "Reject", "input": {"label": "Reason", "type": "text", "required": True}}

Returns {"status": ..., "requestId": str, "decision": str | None, "inputs": dict | None}.

  • One request per key. Calling again with the same conversation and key returns the existing request, including a resolved result. It doesn't reset the request or change its summary, buttons or fields. Use a new key only for a genuinely new review.
  • Pending requests keep the conversation open. It is not auto-closed for inactivity while a request is pending.
  • Expiry hands off. If nobody answers within timeout_hours, the request expires and the conversation is handed off to an agent. Expiry is final.
  • Testing: without context["conversation"], it returns pending with requestId: None and creates no card.

get_human_decision_result

Reads the current state of the request with this key in the current conversation. It never creates or resolves a request.

StatusMeaning
pendingWaiting for a decision
resolvedRead decision (the button's key) and inputs (keyed by input label)
expiredNobody answered in time and the conversation was handed off
noneNo request with this key exists in the conversation
{
  "status": "resolved",
  "requestId": "<request UUID>",
  "decision": "reject",
  "inputs": { "Reason": "This item is outside the exchange window." }
}

Without context["conversation"], it returns {"status": "none"}.

resolve_human_decisions

Records a decision a human made outside the Octocom dashboard, for example on a review page backed by a custom HTTP endpoint. The card shows the outcome as if an agent had answered it, and the bot is triggered within about a minute to read it.

ParameterTypeDescription
contextdictThe function's context
answerslistOne {"key": ..., "decision": ..., "inputs": {...}} per request. inputs is optional
conversation_idstr or NoneConversation UUID or public ID. Defaults to the current conversation; required in HTTP endpoints and recurring jobs
  • Partial answers: answers can cover some or all of the conversation's pending requests. The rest stay pending, and the bot's turn covers only the requests answered in this call. Answer requests decided together in one call so the customer gets one reply.
  • Inputs: include the label of every required input. Extra labels, such as who reviewed the case, are stored and shown on the card.
  • All or nothing: a refused call saves none of its answers. Recording a decision is final.
  • Only HTTP endpoints, recurring jobs, event handlers and sidebar actions can call it. Anywhere else, including bot actions, it raises RuntimeError, so the bot can never approve its own request. Without conversation_id or a current conversation, it raises ValueError.

Returns {"success": True, "conversationId": str} once recorded, or {"success": False, "error": str, "code": str} when refused:

CodeMeaning
invalidThe decision isn't offered by the request, or required text is missing
not_foundThe conversation or request key doesn't exist
already_resolvedSomeone already answered
expiredThe request passed its timeout and the conversation was handed off
importedImported conversations can't be changed

Only record a decision from a caller you have verified. HTTP endpoint URLs have no built-in authentication, so check a signed or stored token before calling this helper, and take the conversation ID from that token rather than from the request body.


Example: request and check actions

# requestExchangeReview
def execute_action(context):
    order_id = context["args"]["orderId"]
    return request_human_decision(
        context,
        key=f"exchange_review:{order_id}",
        summary=f"Review exchange request for order {order_id}",
        decisions=[
            {"key": "approve", "label": "Approve exchange"},
            {
                "key": "reject",
                "label": "Reject exchange",
                "input": {"label": "Reason", "type": "text", "required": True},
            },
        ],
        info={"Order": str(order_id)},
    )
# checkExchangeReview
def execute_action(context):
    order_id = context["args"]["orderId"]
    return get_human_decision_result(context, key=f"exchange_review:{order_id}")

Both actions must build the same key. Enable both in the workflow, and tell the bot to call the check action when it is notified that the review is resolved. Human-in-the-loop decisions has the full workflow instructions.

On this page