Skip to content
Tinbox

Automation & agents

The four AI surfaces in Tinbox — the interactive assistant, autopilot, dedicated agents, and agentic skills — plus how the assistant drives your inbox over chat, MCP, and the CLI through one shared tool manifest.

Tinbox is built agent-first, human-supervised. There are four distinct AI surfaces, and the single biggest thing to get right is telling them apart. They all stand on the same shared tool manifest, but they differ in who drives and when they run.

The four surfaces

SurfaceWhat it isConfigure with
AssistantThe interactive chat agent (in-app chat, /mcp, CLI) a human drives, turn by turn.config.assistant
AutopilotThe assistant put on a cron with standing orders — it works the inbox on a schedule, within the tools you opt it into.config.autopilot + Settings → Autopilot
AgentsDedicated autonomous agents, each bound to one inbox, with their own prompt + tool allowlist + optional human-in-the-loop.config.agents via defineAgents({...})
Agentic skillsThe tools the three above call — an agenticSkill() you author.config.skills (see Skills)

Put simply: the assistant is interactive (you drive it); autopilot is that same assistant on a timer with a brief; agents are separate autonomous workers each owning an inbox; and an agentic skill is a tool any of them invoke. A defineAgents agent and autopilot can both run unattended, so each gates outbound sends behind approval (HITL) — irreversible actions stay human-gated.

// tinbox.config.ts — the surfaces are separate config keys
import { defineAgents } from "tinbox/cf/agents";

const config: TinboxConfig = {
  assistant: { systemPrompt: "Be concise; cite thread ids." },   // interactive
  autopilot: {                                                   // the assistant on a cron
    enabled: true,
    instructions: "Triage overnight; draft replies; never send.",
    tools: ["search_emails", "summarize_thread"],
    principal: "owner",                                          // who it acts as (default)
  },
  agents: defineAgents({                                         // a dedicated agent per inbox
    supportBot: {
      inboxId: "inbox_support",
      name: "Support Bot",
      systemPrompt: "You are a helpful support agent…",
      tools: ["search_emails", "create_draft"],
      hitl: { required: true, ttl: 3600, expirationAction: "reject" },
    },
  }),
  // skills: defineSkill([...]) — the agentic tools all of the above call
};

Declaring an agent doesn't create it (yet). Today config.agents / defineAgents(...) is a typed declaration only — nothing reads it at deploy or boot. The per-inbox agent runs from an agents row in your D1 database, which you create through onboarding or the agents.create API (api.agents.create in the SDK); Settings → Agents then lets you turn it on and off. The recipes/support-desk/provision.ts script in the public examples shows the idempotent version: it finds the inbox, then creates or updates the agent row from the same fields you'd declare. Syncing config.agents into D1 automatically is tracked in TBX-87.

For the full decision map ("I want X → use Y"), see Core concepts → Extend & automate.

Who autopilot acts as — the designated principal

The interactive assistant runs with your grants — the session user driving it. Autopilot has no session, so when it calls a core inbox tool (search, list, summarize — the ones that authorize per-grant) it needs an identity to act as. You designate one with autopilot.principal:

autopilot: {
  enabled: true,
  tools: ["search_emails", "summarize_thread"],
  principal: "owner",                       // ← the default
  // principal: { user: "user_abc" },        // a specific user's grants
  // principal: { tokenEnv: "AUTOPILOT_TOKEN" }, // a scoped API key (least privilege)
}
  • "owner" (default) — the loop runs as the org super-user (you, the deployer), so it reaches every inbox you can. Zero config; a fresh deploy just works.
  • { user } — runs as a specific user, scoped to that user's inbox grants.
  • { tokenEnv } — runs as an API key read from a Settings → Secrets variable. Least privilege: mint a tbx_… key (Settings → API keys) granted only the inboxes and scopes the loop needs, store it as a secret, and name the variable here. Only the variable name lives in your config — never the key itself.

Autopilot's reach is then exactly that principal's reach, and the audit trail attributes its actions to a real identity. Two guarantees hold regardless of which principal you pick:

  • It proposes; a human commits. Autopilot may run any reversible tool — reads (search/summarize/list), drafting (create_draft/update_draft), contact updates (upsert_contact, tag_contact, … — the registry has undo), and campaign planning (create_campaign/update_campaign/create_template). Anything irreversible — send_email, send_campaign, schedule_campaign, approve_campaign, remove_subscriber, forwarding/notification dispatch — is always held for human approval, even when the principal could do it.
  • No principal ⇒ no core tools. If the principal can't resolve (e.g. nobody has signed in yet, or the token secret is unset), autopilot simply skips core tools that tick and logs why — it never falls back to running unauthorized. Your reversible tenant skills still run, since they carry their own auth.

You can see exactly what it did each run in Settings → Autopilot → Recent activity — the last runs, their summaries, the tools each touched, and how much was held for you.

principal lives in tinbox.config.ts (git-reviewed), not the runtime Settings — changing who the autopilot is, is a privilege decision. Settings still own its behavior (on/off, tools, brief).

The rest of this page covers the assistant surface — how it (and the MCP server and CLI) drives your inbox through the shared tool manifest.

One manifest, three ways to reach the assistant

The companion app is the supervision surface, not the only way in. Three surfaces let you (or an agent) operate your inbox through the assistant, and they all share one tool manifest, so a tool behaves identically wherever it is called.

Tools share one manifest, and each entry declares which surfaces expose it. Many tools are available on all three; send_email is chat/MCP-only:

  • The in-app chat assistant. A conversational panel in the companion app that operates the inbox through tools. It runs with the session user's grants, so it can never see or do more than the human driving it.
  • The MCP server. Your deployment exposes a Model Context Protocol endpoint at /mcp. The Claude app, Claude Code, or another MCP client discovers the tools exposed to that connection through tools/list. See Connect an MCP client.
  • The tinbox CLI. The agent's hands in a terminal. A coding agent in any repo can search mail and draft through generated or dedicated inbox commands. Sending uses the explicit tinbox send SDK path with a sending-scoped key; there is no generated send-email counterpart to the inbox tool.

Inbox tools retain the underlying authorize(caller, inbox, action) checks. The separate SDK send path checks sending-key authority instead; neither grants the other's permissions. Chat adds zero new data-access paths. Browse every tool in the tool reference.

Read-only vs. destructive tools

Each tool carries annotations. Read-only tools (search, summarize, list) are safe to auto-run: search_emails, get_thread, summarize_thread, list_threads. Destructive tools write or send and are flagged so the surface asks first: send_email and the campaign-send path.

  • Tinbox chat enforces its approval gate for destructive tools.
  • MCP publishes destructiveHint so the client can present consent controls. Consent handling belongs to that client; the MCP server does not verify a separate human-confirmation receipt before an authorized tool call.
  • Generated CLI commands marked destructive require explicit --yes when exposed there. The separate tinbox send SDK command follows its own explicit send contract and sending-key checks.

Server-side grants and scopes structurally limit every operation. Approval handling differs by surface; MCP annotations alone are not an approval gate.

The CLI as the agent's hands

The CLI emits machine-readable output with --json on every command and meaningful exit codes, so an agent parses results and branches on failures precisely. Auth is a capability token (tbx_…) via TINBOX_TOKEN or a config file. A few of the commands an agent reaches for:

tinbox search "invoice overdue" --inbox support --json
tinbox threads --unanswered --json
tinbox draft create --thread thr_… --text "On it, sending today." --json
tinbox send --to ada@example.com --subject "Update" --text "..." --json

The freshness probe (tinbox threads --changed-since and tinbox draft version) lets a long-running or branch-based agent check whether state moved before it acts, and a draft update is a compare-and-swap that rejects a stale write with a conflict the agent can rebase on.

Plan and review a fixed follow-up

Discover the tools exposed by the current connection first. MCP tools/list is runtime authority for that server; an old cached list is not proof a newly published tool is absent. Refresh the client's tool inventory or reconnect when it is stale. tinbox --help lists generated commands in the installed CLI; it does not establish that a different server version supports them. Do not invent a tool-inventory command or silently replace missing tools. In particular, do not substitute instruction-driven set_thread_directive automation for a reviewed literal fixed-body plan.

An agent can prepare one literal conditional follow-up in a new-message or reply draft using create_draft and update_draft. Both accept followUp: { afterDays, body } | null. Omit the field to preserve the saved plan; use explicit null to remove it. Saving a draft does not send or schedule mail. The draft can retain an unfinished body while editing; actual sending requires nonblank fixed text. Draft delays are whole 24-hour days (1–365), and the body limit is 16000 characters. The tenant's expiry and auto-send policy still constrain what can actually be scheduled.

Use get_draft to read the saved message and plan before editing or approving. Select part: "message" or part: "follow-up"; the default chunk is 2000 Unicode code points and the maximum is 4000. Continue using data.nextOffset and the numeric data.revision.version as expectedVersion. If the version changes, restart and reconcile rather than combining parts from different revisions. The metadata's 280-code-point follow-up preview is only a summary. Use that reviewed version as baseVersion when updating.

tinbox create-draft --inboxId ibx_example --to person@example.test \
  --subject "A specific question" --bodyText "Initial message" \
  --followUp '{"afterDays":3,"body":"One fixed follow-up question."}' --json
tinbox get-draft --id drf_example --part follow-up --expectedVersion 1 --json
tinbox update-draft --id drf_example --baseVersion 1 --followUp null --json

Before sending, call check_follow_up_readiness with the chosen inbox, sender, recipient and exact reviewed followUp text. Without a plan it checks only scope eligibility and limits (planValidated: false). It does not create a draft, reserve authority or send; an eventual send rechecks live state. The generated CLI is check-follow-up-readiness, with the same camelCase input flags.

These are generated CLI commands with the same schemas as MCP and chat; their camelCase flags are intentional. Draft writes are reversible proposals, while sending stays a separate, human-approved action with its own current authority and policy checks. A scheduled result means pending conditional work, not successful delivery. Read the thread's live followUps and use list_thread_directives / cancel_thread_directive to inspect or cancel it. Cancellation cannot recall a message already accepted by a transport.

The structured tool results expose these checkpoints. Read the result rather than inferring success from the tool name:

ActionFields to inspect
Review a saved draftdata.content, data.nextOffset, data.revision.version, data.followUp
Check an exact candidatedata.ready, data.planValidated, data.limits, data.rejections
Send the initial messagedeliveryStatus, idempotencyKey, followUp.status, followUp.directiveStatus, followUp.directiveId
Browse scheduled workdirectives, nextCursor
Read a selected saved plandirectives[0].body.content, directives[0].body.nextOffset, directives[0].deliveryStatus, directives[0].canCancel

Reuse a stable idempotencyKey when retrying the same send_email operation, including its original follow-up. Changing the message or plan under that key conflicts. If the initial send was accepted but scheduling failed, inspect the thread before acting; do not resend the original merely to obtain a schedule.

Sending-only SDK credentials and inbox-runtime credentials are different surfaces. A sending key does not grant draft, conversation or cancellation access; an inbox tool still checks its caller's real grants and scopes. Do not replace the caller identity when a check fails.

Agents can read these docs

The MCP server ships a built-in, read-only search_docs tool. An agent connected to your deployment can search these very guides and the tool reference at action time. Ask it: "what params does send_email take?" and it answers from the reference without you pasting anything.

Next steps

Contacts and communication history

Use the same tools through chat, MCP, or the generated CLI commands. Reads and writes still call the authenticated deployment API; a tool grant does not expand the caller's inbox or sender authority. Start with compact evidence and open only the conversations or messages needed for the task.

NeedChat / MCP toolCLI command
Resolve a recipient quicklysearch_contactssearch-contacts
Browse saved CRM identities and labelslist_contactslist-contacts
Resolve exact ID/email and merged addressesget_contactget-contact
Read selected source facts and labelsget_contact with includeProfile:trueget-contact --includeProfile
Read or append relationship noteslist_crm_notes, add_crm_notelist-crm-notes, add-crm-note
Save contact factsupsert_contactupsert-contact
Add/remove labels or set lifecycletag_contact, untag_contact, set_contact_lifecycletag-contact, untag-contact, set-contact-lifecycle
Browse actual stored conversation choiceslist_contact_messageslist-contact-messages
Inspect outbound ledger evidencelist_contact_sendslist-contact-sends
Browse message metadata or a short full exchangelist_thread_messageslist-thread-messages
Read one selected body chunkread_message_bodyread-message-body

list_contacts searches saved CRM records. search_contacts is recipient completion, including recent correspondents; it does not replace the CRM inventory. Exact email reads do not create contacts. upsert_contact saves by canonical identity, and add_contacts accepts up to 50 rows per batch. These reversible writes do not send mail. Record a source URL, confidence and useful labels when saving research; put attributed working context in CRM notes.

tinbox list-contacts --query DSP --limit 10 --json
tinbox get-contact --email maker@example.test --includeProfile --json
tinbox list-crm-notes --contactId cnt_example --limit 1 --json
tinbox upsert-contact --email maker@example.test --name "Example Maker" --labels dsp --sourceUrl https://example.test/about --confidence 90 --attribs '{"topic":"pitch shifting"}' --json
tinbox list-contact-messages --contactId cnt_example --limit 5 --json
tinbox list-thread-messages thr_example --view full --limit 5 --bodyLimit 2000 --bodyBudget 8000 --json
tinbox read-message-body --threadId thr_example --messageId msg_example --offset 2000 --limit 2000 --json

list_contact_messages defaults to conversation summaries with counts, not repeated messages. Choose view:"messages" for envelopes. Its counts cover actual stored, authorized email, including archived/spam/trash mail but excluding drafts and internal notes. list_contact_sends is separate evidence from the send ledger, including sends without a stored thread. A dispatch or delivery status does not prove a reply. Its suppression result applies only to the returned suppressionAddress and scope; it is not a consent claim for every address attached to a contact.

Continue nextCursor unchanged with the same identity, filters and view. Cursors for stored communication/thread history are opaque strings. The send-ledger cursor is a structured {createdAt,id} object in MCP; the CLI accepts the exact JSON object as a quoted string, for example:

tinbox list-contact-sends --contactId cnt_example --limit 10 --cursor '{"createdAt":1750000000000,"id":"send_example"}' --json

Thread pages are oldest first. Compact view omits bodies and reports availability; full view includes stored bodies within the explicit per-message and page budget. Use message row IDs for body reads, never RFC Message-ID headers. Body offsets are Unicode code points: use nextOffset unchanged rather than calculating it from JavaScript string length. HTML-only storage is labelled HTML; request format:"html" explicitly when the text body is unavailable. Missing content and raw-only storage are distinguished from an empty stored body. Do not fetch a raw archive or a live provider automatically.

The legacy get_thread / get-thread tool preserves its original numeric message offsets, UTF-16 body offsets, and HTML-to-text excerpt formatting. It remains an all-thread fetch followed by excerpt slicing; prefer the new bounded history and body tools for efficient reads. Saved legacy offsets remain usable. Lists report omitted recipients/attachments/labels when their compact descriptor caps apply; oversized profile attribute bags are marked omitted rather than silently dumped. Fetch the exact additional facts through the authorized API when needed. Internal notes remain explicitly marked and must not be represented as replies from the other party.