Skip to content

Operation Scratchpad Tool

The manage_assistant_operation tool gives the assistant persistent working memory for bulk operations. When a user asks “send a follow-up to 50 contacts,” the assistant tracks which contacts have been processed, which failed, and where to resume — even after earlier messages leave the context window.

FieldValue
Tool namemanage_assistant_operation
PermissionsNone (manages assistant’s own state, not user data)
DirectionRead/Write
Always availableYes — no ABAC gate

The scratchpad has three layers:

  1. Database tableassistant_operation stores canonical state per conversation
  2. Toolmanage_assistant_operation lets the assistant read and write its own state
  3. System prompt injection — a compact operation summary is rebuilt from the database every turn, so it’s never evicted from context

The tool supports six actions:

Start a new bulk operation. If an active operation already exists in the conversation, it’s automatically paused.

{
"action": "create",
"operation_type": "send_sms",
"total_items": 25,
"item_ids": ["id-1", "id-2", "..."],
"batch_size": 5,
"query_params": { "tag": "Lead", "status": "active" },
"notes": "Follow-up campaign for Q2 leads"
}
ParameterTypeRequiredDescription
operation_typestringYesLabel like "send_sms", "update_contacts"
total_itemsintegerYesTotal item count — must match item_ids length
item_idsstring[]YesFull list of IDs to process
batch_sizeintegerNoItems per batch (default: 5)
query_paramsobjectNoOriginal filter params for pause/resume
notesstringNoFreeform notes

Get the current state and the next batch of IDs to process.

{
"action": "progress",
"operation_id": "optional — auto-detects the active operation if omitted"
}

Returns the next batch of IDs sliced from item_ids starting at the current cursor position, plus counts for completed, failed, and remaining items.

Record results after processing a batch.

{
"action": "update",
"operation_id": "uuid",
"completed_ids": ["id-1", "id-2"],
"failed": [{ "id": "id-3", "reason": "invalid phone number" }]
}

Advances the cursor, increments completed_count and failed_count, and merges results into state_json.

Mark the operation as done. Removes it from the system prompt.

{
"action": "complete",
"operation_id": "uuid"
}

Reactivate a paused operation. Auto-pauses the currently active operation if one exists.

{
"action": "resume",
"operation_id": "uuid"
}

Abort the operation. Returns final counts for completed, failed, and abandoned items.

{
"action": "cancel",
"operation_id": "uuid"
}

The assistant_operation table:

ColumnTypeDescription
idUUID (PK)Operation ID
conversation_idUUID (FK)Links to assistant_conversation
organization_idUUID (FK)Links to organization
operation_typeVARCHAR(64)Human-readable label
statusVARCHAR(32)active, paused, completed, or cancelled
total_itemsINTEGERTotal items in the operation
completed_countINTEGERItems processed successfully
failed_countINTEGERItems that failed
state_jsonJSONBFull state: item_ids, cursor, completed_ids, failed, batch_size, query_params
created_atTIMESTAMPTZCreation timestamp
updated_atTIMESTAMPTZLast update timestamp

Indexes:

  • idx_assistant_operation_conversation — B-tree on conversation_id
  • idx_assistant_operation_org_active — partial index on (organization_id, status) where status = 'active'

Both foreign keys cascade on delete.

  • The assistant must create an operation for any bulk action involving more than 5 items
  • Only one operation can be active per conversation — creating or resuming one auto-pauses the current
  • The system prompt includes a compact summary of active and paused operations on every turn
  • After context eviction, the assistant reads the injected summary to know where to resume
  1. User asks: “Send a follow-up SMS to all contacts tagged Lead”
  2. Assistant searches contacts → gets 30 results
  3. Assistant calls create with all 30 contact IDs
  4. Assistant calls progress → gets the first batch of 5 IDs
  5. Assistant processes the batch (sends SMS to each)
  6. Assistant calls update with completed and failed IDs
  7. Repeat steps 4–6 until all items are processed
  8. Assistant calls complete

If the user says “continue” after context eviction, the assistant reads the operation summary from the system prompt and resumes from the correct cursor position.