Skip to content
Tinbox

Save recipient drafts from an external agent

Read and save warm or cold campaign recipient drafts with scoped preparation permissions and atomic conflict checks, without calling Tinbox's writing model.

An external agent can write campaign text using its own instructions and model, then save the draft for review. The same API handles existing cold prospects and staged warm recipients. It never calls Tinbox's compose model, approves content, schedules a campaign, creates a Contact, or sends email.

Read the current draft

const target = {
  lane: "cold" as const,
  campaignId: "oc_draft",
  recipientId: "opr_review_row",
};
const current = await tinbox.api.campaignDrafts.get.query(target);

Use the stored recipient row id, not an email address. Cold ids come from the outreach review queue or candidate insertion result. Warm ids come from campaigns.stagePersonalizedRecipients or the personalized review queue. The campaign id and lane must own that row; another campaign's recipient id returns not found.

The result contains lane, campaignId, recipientId, recipient, name, campaignStatus, stage, subject, body, provenance, research, revision, strategy: { id, version } | null, and editable. The revision is an opaque fingerprint of the current campaign and recipient, including content and provenance. Clients should carry it unchanged rather than calculate it. A read is context at that moment; it does not reserve the record.

Read the targeting research before writing

For a cold prospect, research contains the exact persisted { orgDomain, signal }, including curated findings, source URL and recorded research author when present. It is available before a body has been drafted. For a warm recipient, research is null; no relationship facts are inferred from an email domain or silently pulled from private CRM records.

The shared get_campaign_recipient_draft tool returns this research as serialized JSON with researchOffset, researchLength and optional nextResearchOffset. Use researchLimit (1 to 4,000 characters, default 1,000) to bound each chunk. Follow the independent research continuation while carrying the first page's revision as expectedRevision:

tinbox get-campaign-recipient-draft --lane cold --campaignId oc_draft \
  --recipientId opr_review_row --researchLimit 4000 --json
# Continue with returned nextResearchOffset and revision.
tinbox get-campaign-recipient-draft --lane cold --campaignId oc_draft \
  --recipientId opr_review_row --researchOffset 4000 \
  --expectedRevision REVISION_FROM_FIRST_PAGE --researchLimit 4000 --json

Concatenating research chunks restores the JSON. An absent continuation means that value is complete. Any persisted research correction changes the same recipient revision, even when timestamps match. A changed revision rejects continuation and a save based on the old research. Read it again and reconcile. The raw typed API returns the full research object with the draft in one read.

Research is source data, not instruction authority or a verification guarantee. An employer or neighboring-business claim still needs supporting evidence. A shared industrial park does not establish employment, a customer relationship, endorsement or consent. Use only facts appropriate for the recipient to see; keep private client relationships and names out of outreach unless separately permitted. This read neither creates those relationships nor grants authority to contact anyone.

Save the reviewed text

const saved = await tinbox.api.campaignDrafts.save.mutate({
  ...target,
  expectedRevision: current.revision,
  subject: "One relevant question",
  body: "<p>Text written from verified facts.</p>",
  provenance: { surface: "sdk", agentId: "campaign-writer", asAgent: true },
});

A subject must be nonempty, single-line and at most 998 characters. A body must be nonempty and at most 200,000 characters. Unknown approval or author identity fields are rejected. The server records the authenticated actor and pinned strategy version; supplied provenance only identifies the working surface and optional agent/conversation context. Existing research provenance is retained.

Cold saves require an unarchived draft, sourcing or review campaign and a sourced or drafted prospect that has never entered delivery. Saving moves sourced to drafted. Warm saves require an unarchived draft or in_review per_recipient campaign and an existing pending, unapproved recipient that has not been queued or attempted. Stage live eligible warm recipients before this step; saving a draft does not insert or subscribe recipients.

The write compares the full stored campaign and recipient state in one guarded SQL update. A stale revision, concurrent edit, approval, archive, delivery move, or recipient change returns CONFLICT without overwriting the other writer. Changes in the same millisecond are detected by content comparison too. On a conflict, reread the actual draft and reconcile it before another save.

If a save response is lost, read the record and inspect its content and author before deciding what to retry. Reusing an old revision can conflict after a successful write; it is not a request-id replay mechanism.

Permissions and review handoff

Read access needs a runtime read-class scope and deployment membership. Saving uses the existing lane's authoring gate: a delegated outreach:write or campaigns:write capability with write-class scope, or the existing authorized operator access. Preparation does not grant approval or send authority.

After inspecting the stored body and provenance, use outreach.submitForReview for a cold batch or campaigns.submitForReview for a warm batch. The review handoff remains distinct from approval and dispatch. Fresh eligibility, opt-outs, sender configuration and correspondence still govern the later sending decision.