Handoff & Ticket

Level 3. The client's handoff — a fixed message, or a drafted ticket, a graph paused on interrupt(), and a POST from Python once the user confirms. Idempotency comes from the run, not the content.


When neither level can ground an answer, the turn goes to the client’s handoff (handoff.mode, D9 amended).

  • message (the default): the shared edge handoff.route sends the turn to decline, which replies with handoff.message. No model call, no ticket, outcome decline.
  • ticket: the rest of this page.

In ticket mode, escalate drafts a ticket with a structured-output call and offers it. The graph then pauses in ticket on interrupt(), and the turn ends. Filing happens only after the user confirms, when confirm_ticket() resumes the graph and Python POSTs the draft.

The route to this tier was chosen before any of it started. Nothing here, in either mode, can revisit whether the question was answerable.


The flow

decide_level2 (or decide_level1, with corrective off) → "escalate" + why
  │
  ├─ decline                           handoff.mode: message · the configured text · END
  │
  └─ escalate                          structured output · prompts/<client_id>/ticket_draft.md
       ├─ _normalise_draft()           subject fallback · category, product_area, priority defaults
       └─ stream `ticket_proposal`, then the offer as `text`
            ▼
     ticket                            interrupt()   ← the graph pauses; the turn ends
            │
            └─ [the user confirms]     POST /api/c/{id}/runs/{run_id}/ticket
                 └─ confirm_ticket()   right client · not already filed · an offer is pending
                      └─ Command(resume=True)
                           └─ stage_ticket()      Idempotency-Key: {run_id}:{stage_seq}
                                ├─ filed  → END · the reply names the ticket
                                └─ error  → back to `ticket` · pauses again for a retry

The draft call is given the message, the recent conversation and the guardrail’s reason string. It is never asked whether to escalate. There is no ticket tool: Python calls the ticket client, app/tickets.py, directly.


A worked example

“Can you raise my Cloud Run instance quota for europe-west1? It’s blocking a deploy.” A real run, continuing from the guardrail.

  • escalate drafts category: quota_or_billing, product_area: cloud_run, a subject and a body. The step records the Level 2 reason alongside them.
  • The draft is streamed as a ticket_proposal event, and the graph pauses. Nothing has been filed. The reply says what the ticket would be and offers to open it.
  • The user clicks through. confirm_ticket() resumes the graph, and stage_ticket POSTs with Idempotency-Key: {run_id}:7: six steps came before it.
  • The service returns PLATFORM-1042, queue platform-serverless, 8-hour ETA, in 18 ms. The confirmation is saved as its own assistant turn.
  • A second click returns already_filed: true and the same id. The mock service holds one ticket.

What the user sees:

Searched the documentation         5 passages · best match 0.50
Graded the evidence                confidence 0.05
Rewrote the question               3 rewrites · "Cloud Run quota europe-west1"
Searched again: keyword + semantic 5 passages
Graded the new evidence            confidence 0.05
Drafted a ticket for review        quota_or_billing

  ┌ Draft ticket · high · quota or billing ───────────────┐
  │ Cloud Run instance quota increase in europe-west1     │
  │ [ Open this ticket ]  [ Not now ]                     │
  └───────────────────────────────────────────────────────┘

Filed a ticket                     PLATFORM-1042      ← after they click

Design decisions

Python files the ticket, the model does not

The ticket client has no tool definition at all, so no model can see it.

Direct call from Python (built)Tool-use round trip
Call sites to make idempotentExactly oneAs many as the model has turns
Can the model decline to file?No, it is not askedYes
Extra round tripsNoneOne at minimum, more if it retries
What the trail recordsOne ticket step, alwaysWhatever the model happened to do

The pause is interrupt(), not a parked draft

The retired pipeline finished the turn, stored the draft on Run.state, and had the confirm endpoint read it back. The graph pauses instead.

Draft on Run.state (retired)interrupt() in the ticket node (built)
Where the draft livesA JSON column the endpoint readsThe graph’s checkpoint
”Is an offer pending?”ticket_draft present, ticket_id absentThe checkpoint has a pending interrupt
What confirm doesRebuilds the filing code path by handCommand(resume=True): the graph continues
Retry after a failed filingThe draft is still thereThe node loops back and pauses again
  • ticket is its own node because interrupt() re-runs its node from the top on resume. Anything placed before it in the same node would run twice.
  • confirm_ticket() still checks the run first: that it exists, belongs to this client, and has not already filed. A resume with nothing pending would silently do nothing, so the endpoint refuses it with a 404 instead.

The user files the ticket, not the turn

A user mid-deploy did not ask for a ticket. One that appears unrequested reads as the assistant giving up, and a corpus of public docs cannot answer anything about their project. So the turn drafts and offers; a confirmation files.

  • The queue is the product. A platform team only works a queue it trusts. Precision there is a property of what doesn’t reach it.
  • The request body is empty. The draft stays in the checkpoint. A client can accept an offer. It cannot author a ticket by posting a subject of its own.
  • A double-click is the realistic duplicate. The filed ticket_id in state short-circuits a second confirmation.
  • What is lost: a pending offer does not survive a page reload in the UI. The filed confirmation is its own assistant turn; an unanswered one is only a button.

Idempotency comes from the run, not the content

  • The key is {run_id}:{stage_seq}. Stable within a run, distinct across every other one.
  • A retry keeps its seq. When filing fails and the node runs again straight after itself, RunRecorder.next_seq() reuses the seq and replaces the failed step. A request that did land the first time replays instead of duplicating.
  • Never derived from content. Two people phrasing a request identically must not collide into one ticket.
  • The server assigns the ticket id. The service is a mock we wrote (Mock Ticket Service); the integration shape is not mocked.

Failing the ticket does not fail the turn

  • HTTP failures are returned, not raised. A 5xx comes back {"error": ..., "retryable": True}; a 4xx is our bug and is marked non-retryable.
  • The step is marked failed, and the offer stays open. The graph routes back to ticket and pauses, so the same button retries the same draft.
  • Retry with backoff is deliberately absent. It belongs next to a dead-letter decision, not inside a tool.
  • The user is told the truth. A failed filing says plainly that nothing was filed, never a fabricated id.

Configuration

KeyDefaultWhat it does
TICKET_API_URLhttp://localhost:9000Env var. Where the ticket service lives
agent.system_prompt_filenoneticket_draft.md is resolved beside it
agent.corrective.enabledtrueOff routes a turn that fails Level 1 straight here

Next: From Pipeline to Graph, why this template replaced a hand-written one, and what carried over.