Human-in-the-loop decisions

Ask your team for one decision while the AI agent keeps the conversation and follows up.

A human decision request lets the AI agent ask your team for one specific decision without handing over the conversation. A person answers on a card, and the AI agent continues from the recorded outcome. For example, a customer asks to exchange an item outside the return window. A team lead approves the exception on the card, and the AI agent tells the customer and carries on with your exchange workflow.

Use it for any decision that needs human judgment while the AI agent handles the follow-up with the customer: a review of damage evidence, a credit limit approval, an exception to a policy. This page explains the concept and the API. If the person deciding works outside Octocom, such as a supplier, a warehouse or another system, follow the external decisions playbook, which builds a complete review link on top of this feature.

Decision request or full handoff?

Human decision requestFull handoff
What the human doesAnswers a specific question on a cardTakes over the conversation
Who handles the customerThe AI agent keeps the conversationA human agent
What happens after the decisionA new AI agent turn checks the result and follows the workflowThe conversation stays handed off
How to use itCustom Python actions using the helpers belowtransferConversation or hand_off_conversation

Creating a decision request does not hand off or assign the conversation. Your team needs a process for finding and answering these cards: conversations with a pending request match the Awaiting input filter in views, so you can keep a queue of open decisions. Use human escalation when the customer needs a person to take over instead.

How it works

  1. The AI agent calls a custom action that registers a decision request.
  2. The action returns immediately with the request's status. Python does not stay running while a person decides.
  3. Following your workflow instructions, the AI agent tells the customer it has submitted the request and will follow up. The helper does not send this message itself.
  4. The dashboard shows an internal Action requested card with the summary, supporting information and decision buttons. In the conversation timeline, it appears after the next bot message following the request, normally the announcement. The customer does not see the card.
  5. A person chooses an option and supplies any required text, either on the card or through your own page or system (see Record a decision outside the dashboard). The first decision wins and is final. The card shows the recorded decision and inputs.
  6. Resolving the request triggers a new AI agent turn, whatever the decision. The AI agent is told to call the matching check action, read the outcome and continue according to your workflow.

The continuation is a new AI agent turn, not a resumption of the original Python function. Clicking Approve records approval; it does not issue a refund, create an exchange or run the next business operation. Those steps belong in your configured actions and workflow.

While a request is pending, the conversation is not auto-closed for inactivity. If nobody answers before the request's timeout (48 hours by default), the request expires and the conversation is handed off to your team.

Several requests on one conversation

When a conversation has several pending requests, the dashboard shows them together as one stack. The agent picks an answer on every card and submits them at once; submit stays disabled until each card has an answer. The AI agent then runs one turn for all the answers, so the customer gets one reply instead of one per card. A single pending request works the same way: choosing an option submits it.

Decisions recorded outside the dashboard, through resolve_human_decisions or the REST API, can answer just some of the pending requests. The others stay pending, so different reviewers can each answer their own request on the same conversation. Each such call triggers one AI agent turn for the requests it answered, and the AI agent is told which requests are still waiting so it doesn't act on them yet. It is triggered again when those are answered.

Draft selections and written instructions are kept when a refresh adds or removes pending cards. The answers and the AI agent's continuation are saved together: if saving fails, no answers are saved and the agent can retry. Once saved, the continuation runs even if starting it immediately fails, without the agent submitting again.

When the AI agent continues

  • From the dashboard card: the AI agent's turn starts immediately.
  • From the REST API or resolve_human_decisions: the decision is saved immediately and the AI agent's turn starts within about a minute. If starting the turn fails, Octocom retries it.
  • If the customer writes in that short gap: their message starts a normal turn instead. The decision stays saved, but the AI agent is not told about it. Your workflow must therefore tell the AI agent to call the check action whenever the customer writes while a request is open.

Set up an exchange review

Create two custom Python actions: one to request the review and one to check its result. Both helpers are built in and need no imports.

1. Create the request action

Name the action requestExchangeReview. Give it a required string argument named orderId, and describe it as submitting an exchange for human review without performing the exchange.

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)},
    )

The summary is the question your agent sees. info adds read-only context. The decisions list defines the buttons: labels are for the agent, while keys such as approve are the values your workflow receives. A decision can ask for one text input, optionally required.

2. Create the check action

Name this action checkExchangeReview, also with a required string argument named orderId. Describe it as reading the review's status, chosen decision and any explanation from the reviewer.

def execute_action(context):
    order_id = context["args"]["orderId"]
    return get_human_decision_result(
        context,
        key=f"exchange_review:{order_id}",
    )

The two actions must use exactly the same request key for the same review.

3. Enable both actions in a workflow

Actions are only available to the AI agent when an active workflow enables them. Enable both requestExchangeReview and checkExchangeReview, plus any separate action needed to perform an approved exchange.

Example workflow instructions:

When an exchange requires human review, collect the order ID and the information needed by the reviewer, then call requestExchangeReview.

If the result is pending, tell the customer the request has been submitted for review and that you will follow up. Do not claim it is approved or perform the exchange yet.

When notified that the human review is resolved, and whenever the customer writes while a review is open, call checkExchangeReview for the same order. Always read the recorded result before deciding what to do next.

If the decision is approve, follow the approved exchange process using the configured exchange action. Confirm completion only after that action succeeds. If the decision is reject, explain the result using the reviewer's reason and offer the alternatives allowed by our policy.

If the check still returns pending, do not claim there is a decision. If it returns none, no request was found for that key; check the order ID before submitting a request.

If a business operation requires approval, its Python action should also verify the recorded decision before making changes. Make that operation safe to retry so a repeated AI agent turn cannot create a duplicate exchange.

Record a decision outside the dashboard

A reviewer doesn't need an Octocom login. A decision can come from:

  • A review page that a supplier opens from a link in Slack, a Google Sheet or an email. The page calls a custom HTTP endpoint, which records the decision with resolve_human_decisions.
  • Another system that calls the REST API (POST /rest/v1/conversations/human-decision-requests/resolve) with an Octocom API key, or sends a signed callback to a custom HTTP endpoint.
  • A recurring job that reads verdicts from a sheet or polls another system's API.

The Action requested card shows the same result as if an agent had clicked it, and the AI agent continues the same way. The external decisions playbook builds each of these end to end. The rules that keep them safe:

  1. In the request action, call get_human_decision_result first. If it returns none, call request_human_decision and send your notification, so a repeated AI agent turn doesn't notify anyone twice.
  2. Endpoint URLs have no built-in authentication. Verify the link's token or the caller's signature before doing anything else. The decision is only as trustworthy as this check.
  3. Take the conversation ID from your verified token or stored case, never from the request body.
  4. Opening a link must not record a decision, because chat apps and email scanners load links automatically. Show the case first and record the decision only when the reviewer confirms with a POST.

Helper reference

request_human_decision

request_human_decision(context, key, summary, decisions, info=None, timeout_hours=None)
ParameterMeaning
contextThe custom action's context, including the current conversation
keyA stable identifier within the conversation, between 1 and 100 characters
summaryA non-empty description of what the agent needs to decide
decisionsOne or more options with a key, label and optional input
infoOptional dictionary of read-only context fields shown on the card
timeout_hoursOptional hours a pending request may wait before it expires, from 1 to 336. Defaults to 48

While a request is pending, the conversation is not auto-closed for inactivity. If nobody answers before the timeout, the request expires and the conversation is handed off to an agent. Expiry is final: the request can no longer be resolved.

Calling this helper again with the same conversation and key returns the existing request, including an already-resolved result. It does not reset the request or replace its summary, buttons or information. Use a different key for a genuinely new review, such as a second review round; do not generate a fresh key on every retry.

get_human_decision_result

get_human_decision_result(context, key)

Returns the current state for that conversation and key. It only reads the request; it does not create or resolve one.

StatusMeaning
pendingA request exists and is waiting for a human decision
resolvedRead decision and inputs to determine the next step
expiredNobody answered in time; the conversation was handed off
noneNo request exists for this key

For an existing request, the result includes status, requestId, decision and inputs. A rejection with a required reason looks like this:

{
  "status": "resolved",
  "requestId": "<request UUID>",
  "decision": "reject",
  "inputs": { "Reason": "This item is outside the exchange window." }
}

The keys in inputs are the input labels you configured, such as Reason, plus any extra labels recorded with the decision.

resolve_human_decisions

resolve_human_decisions(context, answers, conversation_id=None)

Records a decision made outside the dashboard. Available in custom HTTP endpoints, recurring jobs, event handlers and sidebar actions. Custom actions cannot call it, so the AI agent can't approve its own request.

ParameterMeaning
contextThe function's context
answersA list of {"key": ..., "decision": ..., "inputs": {...}}, with inputs optional
conversation_idConversation UUID or public ID. Required when the context has no conversation

answers can cover one, several or all of the conversation's pending requests. Requests you leave out stay pending, and the AI agent's turn covers only the requests answered in this call. To have the AI agent reply once about several decisions, answer them in the same call. inputs must include the label of a required input. Extra labels, such as who reviewed the case, are stored and shown on the card. Input values must be strings.

Returns {"success": True, "conversationId": ...} once the decision is saved. The AI agent's turn starts within about a minute. A refused answer returns {"success": False, "error": ..., "code": ...} and saves nothing, including the other answers in the same call:

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. Recording a decision is final
expiredThe request passed its timeout and the conversation was handed off
importedImported conversations can't be changed

An HTTP endpoint behind a review link might record a decision like this. verify_review_token is your own function: either sign tokens with a key stored in secrets, for example using hmac, or use a random token and look up its hash in the organization store, as the playbook does.

def handle(context):
    case = verify_review_token(context["request"]["body"].get("token"))
    if case is None:
        return http_response({"error": "This link is not valid"}, status=401)

    body = context["request"]["body"]
    result = resolve_human_decisions(
        context,
        answers=[
            {
                "key": case["key"],
                "decision": body["decision"],
                "inputs": {"Reason": body.get("reason", "")},
            }
        ],
        conversation_id=case["conversationId"],
    )
    if not result["success"]:
        return http_response(result, status=409)
    return {"recorded": True}

REST API

The same operations are available over the REST API, for systems outside Octocom:

MethodPathPurpose
POST/rest/v1/conversations/human-decision-requestsRegister a request on a conversation. Same key returns the existing request
GET/rest/v1/conversations/human-decision-requestsRead a request's state, with conversationId and key query parameters
POST/rest/v1/conversations/human-decision-requests/resolveRecord decisions, with conversationId and answers in the body

The resolve endpoint refuses an answer with status 400, 404 or 409 and the same code values as resolve_human_decisions. API keys cover your whole organization, so keep them server-side and never put one in a web page.

Testing and operational behavior

  • Test with a conversation. Without context["conversation"], the request helper returns pending with a null requestId and creates no card; the check helper returns none. A pending response alone is not proof that a request was saved.
  • Check both outcomes. Confirm that the card appears, required text is enforced, and both approval and rejection trigger a follow-up that reads the result.
  • Check a conversation with several requests. The follow-up turn names every resolved request key; make sure your check action can read each of them and the workflow answers them in one reply.
  • Keep the check action available. The continuation tells the AI agent to check the outcome; your workflow must expose an action that can read the matching key.
  • A decision does not undo a handoff. If someone hands the conversation off while a request is pending, resolving the card does not return it to the normal AI agent workflow.
  • Plan how the team monitors requests. Creating a card is not a substitute for someone reviewing it. Decide who owns the review queue and when an unanswered request needs a full handoff.

On this page