The Agent Context REST API under /api/agent/v1 returns ranked, deduplicated, cited evidence and governed context sets.
Agent Context API
The Agent Context API is served by the Bundata API server under /api/agent/v1. Every request authenticates with a scoped credential created in Settings → Agent access (Authorization: Bearer bdk_<16 hex>_<43 base64url>).
Credentials and scopes
Workspace owners and admins (agent_credential:manage) manage up to 50 active credentials per stored workspace (POST /api/w/:wsId/agent-credentials). Each credential expires after 1 to 365 days, acts with its creator’s live workspace membership (AGENT_CREDENTIAL_AUTHORITY_LOST if permissions are revoked), and refuses browser requests (Origin or Sec-Fetch-* headers return 403 AGENT_BROWSER_REQUEST_REFUSED).
| Scope | Minimum creator role | What it allows |
|---|---|---|
context:read | Viewer (collection:read, document:read) | Context packs, passage/graph/section/citation tools, temporal graph reads, context set lookups, and studied field tools (list_fields, query_fields) |
queries:run | Editor (document:read, agent:run) | Whole-document evidence in packs, vetted rule templates, and approved SQL query templates (run_query_template) |
replay:run | Viewer (document:read) | POST /api/agent/v1/replays/:replayId (verify or recompute) |
gaps:report | Viewer (library:read) | MCP report_context_gap (off by default when creating a credential) |
memory:read | Viewer (collection:read, document:read) | Recall and list the creator’s agent memories (off by default) |
memory:write | Editor (document:read, agent:run) | Remember and forget the creator’s agent memories (off by default) |
Context packs and replays
POST /api/agent/v1/context-packs (and /api/agent/v1/context-packs/stream for application/x-ndjson) builds a deterministic, ranked, deduplicated evidence pack within a token budget:
curl -sS "$BUNDATA_URL/api/agent/v1/context-packs" \
-H "Authorization: Bearer $BUNDATA_AGENT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"task": "Who is the current CFO, and since when?",
"budget": { "maxTokens": 2000, "coverage": "best_effort" },
"asOf": { "validTime": "2025-01-01T00:00:00Z" }
}'
- Request fields:
task(1–4,000chars),budget.maxTokens(256–32,000, default4,000),budget.maxLatencyMs(1,000–60,000, default15,000),budget.coverage(best_effortorrequire_complete),asOf(validTime,systemTime),filters(collectionIdsup to 8,documentIdsup to 20,sources:passages,graph,documents),retrieval(hybridorlexical), and optionalcontextSetId. - Set-first packing: When
contextSetIdis passed (or the credential is bound to one active Context set), the pack fills its budget in order:verified_answers,definitions,instructions(markedtrust: "approved"),required_evidence,evidence, andwhole_document. - Untrusted document text: Every item quoted from a document is marked
trust: "untrusted", includesvalidity,superseded, andcontradictionflags, and is re-checked for read access before release. - Replay (
POST /api/agent/v1/replays/:replayIdwith{ "mode": "verify" | "recompute", "task"?: string }): Re-verifies every recorded item against current documents (unchanged,changed,unavailable) or recomputes the pack at the recorded times and returns a diff. Replay records store hashes only and expire after 30 days (410 AGENT_REPLAY_EXPIRED).
Context set and library routes
All four routes require context:read, match words deterministically without spending provider embedding budget, and enforce context-set scope:
POST /api/agent/v1/context-sets/list({ query?, limit? })POST /api/agent/v1/context-sets/get({ contextSetId? })POST /api/agent/v1/definitions/lookup({ term, contextSetId?, limit? })POST /api/agent/v1/verified-answers/match({ question, contextSetId?, limit? })
Studied fields and query templates
- Studied fields (
POST /api/agent/v1/fields/listandPOST /api/agent/v1/fields/query, scopecontext:read): Inspect a collection’s normalized studied fields (number,money,date,boolean,text) and execute structured plans (up to 6fields, 6filters,sort,limitup to 200, andaggregatecount/min/max/sum/avgwithgroupByup to 50 groups, plus optionalknownAt: "YYYY-MM-DD"). Every returned value includes a live-checked passage span citation (citationornullwithuncitedReason), andcoverageLines/incompletereport whether any field is stated in fewer than 90% of documents. - Query templates (
POST /api/agent/v1/query-templates/run, scopequeries:run): Execute an approved PostgreSQL query template belonging to the active context set by passing{ templateId, parameters, contextSetId? }. Agents never send or receive raw SQL.