Docs
Agent

System Prompt and Context

Documents the context the MarkDocket agent receives at the start of each turn, including portfolio state, user preferences, session history, and how the agent's turn lifecycle shapes what information is available.

The MarkDocket agent is a stateless service. Every turn is self-contained: the agent receives a fully assembled context bundle at the start of each turn and uses that information — plus its available tools — to produce a response. Nothing persists inside the agent process between turns. Durability lives in the database.

This page explains what makes up that context bundle, how session history is maintained, and what role the turn lifecycle plays in determining what the agent can access.


How the Agent Receives Context

When you send a message, the API layer assembles the context for that turn and forwards it to the agent. The agent does not fetch your portfolio or preferences itself — it receives a prepared snapshot. Any data the agent needs beyond that snapshot is retrieved on demand through its tool registry, which calls back to the API on your behalf using a delegated token scoped to your identity.

This architecture means the agent's context is always consistent with what the API layer has authorized for your session, and the agent cannot access anything outside the scope of that delegation.


Session History

Each agent conversation belongs to a session. Sessions persist across browser reloads and device switches — your conversation history is stored server-side, not in browser storage.

At the start of each turn, the prior messages in the session are included in the context window sent to the language model. This gives the agent continuity within a conversation: it can refer back to earlier questions, previously retrieved trademark records, draft content it generated, and tool results from prior turns.

Context window limits apply. For very long sessions, earlier messages may be summarized or omitted to fit within the model's context window. If you notice the agent losing track of earlier details, starting a new session gives it a clean, full context window.

Sessions are associated with your user account. If you use MarkDocket through the StartWise partner embed, sessions are scoped to your embed context and are isolated from sessions created in the main app.


Portfolio Context

The agent can access your portfolio — trademarks, patents, deadlines, watches, and related items — through its tools. Portfolio data is not bulk-loaded into the system prompt at the start of every turn. Instead, the agent retrieves specific records as needed during the turn.

This approach keeps the context bundle lean and ensures the agent always reads the latest state of your portfolio rather than a snapshot that may be seconds or minutes old by the time the agent uses it.

If you ask the agent about a specific trademark or patent, it will call the appropriate tool to fetch current data. The result of that fetch is added to the model's context for the rest of that turn.


Uploaded Files and Attachments

Files you attach to a message are available to the agent within that turn and in subsequent turns in the same session. Attachments are stored in your Vault and referenced by a stable identifier.

The turn lifecycle enforces an upload gate: files must be uploaded and confirmed before the agent turn begins processing. Once a turn is running, the agent has access to any attachments associated with that turn's message, as well as attachments from prior messages in the session history.

For multimodal content — such as trademark specimen images or patent figures — the agent can receive image data directly as part of its context when those files are referenced.


User and Account Context

The agent is aware of context relevant to your account:

  • Identity: Your user account identity is bound to the delegated token the agent uses for tool calls. The agent always acts on your behalf and cannot act on behalf of another user.
  • Billing and plan state: If a tool call or action would exceed your plan's limits, the agent receives a billing signal mid-turn and surfaces this to you before any restricted action proceeds. The agent does not have access to your raw billing figures or payment details.
  • BYOK configuration: If you have configured your own AI provider keys for use in Automation runs, those keys are used only in that specific context — not in interactive agent chat. The agent session always uses the platform's AI Gateway.

The Turn Lifecycle

Each message you send initiates a turn. Understanding the turn lifecycle clarifies when context is locked in and when errors can occur.

Turn States

StateMeaning
authorizingBilling reservation is being created for this turn.
authorizedReservation confirmed; file uploads are now allowed.
uploadingAttachments are being transferred and bound to the turn.
runningThe agent is processing your message.
completedThe agent turn finished successfully.
deniedThe turn was rejected, typically due to a billing limit.
failedAn error occurred during processing.
expiredThe turn was not completed within its allowed window.
cancelledYou or the system cancelled the turn before completion.

Billing authorization happens before any message content or files are committed, so a denied turn means no content was processed and no usage was charged.

Idempotent Retries

If your connection drops mid-turn, the client can safely retry. Each turn is identified by a stable key generated when you press send. Retrying with the same key resumes the same turn rather than creating a duplicate — including re-uploading the same files without creating duplicate records.


Tool Calls and Context Accumulation

During a single turn, the agent may call multiple tools in sequence — for example, searching for conflicting marks, then fetching the details of specific results, then retrieving your portfolio's existing coverage in that class. Each tool result is appended to the model's context for that turn.

This means the agent's effective context grows during a turn as it gathers information. The final response draws on both the initial context bundle and everything retrieved during the turn.

Tool calls always go through the API, which enforces your permissions and records each action. The agent cannot make direct calls to external services — all access is mediated.


Automation Runs vs. Interactive Sessions

The agent context described on this page applies to interactive chat sessions — conversations you have directly in the MarkDocket interface or via the MCP integration.

Automation runs use the same agent tooling but operate differently:

  • Each automation node has its own bounded context, defined by the node's configuration and the variables passed into it.
  • Automation nodes can use your BYOK AI provider keys if configured.
  • Automation runs are durable and checkpointed — if a run is interrupted, it resumes from the last completed node, not from the beginning.
  • Automation runs are not interactive; there is no back-and-forth with a session history.

See the Automations documentation for details on how automation context and variable passing works.


Agent-Only Tools

The interactive agent has access to a superset of the tools available through the CLI and MCP integrations. Tools such as web search and goods-and-services classification are available only within the interactive agent session — they are not exposed through the public tool catalog used by the CLI, MCP server, or the /v1/tools API gateway.

This distinction is intentional: agent-only tools depend on the agent's session context and the platform AI Gateway in ways that are not appropriate for programmatic API-key or OAuth-token callers.


Session Isolation for Embedded and Partner Contexts

If you access MarkDocket through the StartWise partner embed, your agent sessions are fully isolated from sessions in the main application. The embed uses a scoped bearer token rather than your full session credentials, and global services such as analytics and the billing-block dialog are not mounted in the embedded context.

Sessions created in the embed are stored under your account but are scoped to that embed context. They will not appear in your main MarkDocket conversation history.

On this page