Create, manage, version, deploy, and build agents from source code
Agents
Agents are the core configuration unit in 9thSense. An agent defines which document types to collect, how to classify them, what cross-matching rules apply, and what pipeline steps to run. All agent state is version-snapshotted on every update.
Agent Object
idstringUUID of the agent.
tenant_idstringTenant this agent belongs to.
goalstringUnique slug identifier (e.g. "kyc_verification"). Used to route cases and pipeline runs.
namestringHuman-readable display name.
versionstringSemantic version string (e.g. "1", "1.2").
definitionobjectAgent configuration JSONB. Contains doc_type_map, classify_aliases, cross_match, pipeline_per_type, intelligence_level, and other keys.
allow_cloudbooleanWhether this agent may route to cloud models when local models are unavailable.
deployedbooleanWhether the agent is active. Only deployed agents can receive new cases or pipeline runs.
created_atstringISO 8601 timestamp.
updated_atstringISO 8601 timestamp of last update.
CRUD Endpoints
Create Agent
POST /v1/agents
Requires scope: write. Returns 409 if an agent with the same goal and tenant_id already exists.
Request body:
goalstringrequiredUnique slug for this agent (snake_case, e.g. "kyc_verification").
namestringrequiredHuman-readable name.
tenant_idstringTenant to associate this agent with.
definitionobjectAgent definition JSONB. See definition schema below.
versionstringVersion string. Defaults to "1".
allow_cloudbooleanAllow routing to cloud models. Default false.
deployedbooleanWhether to activate the agent immediately. Default false.
Example request:
{
"goal": "kyc_verification",
"name": "KYC Verification",
"tenant_id": "acme-corp",
"definition": {
"doc_type_map": { "pan_card": "pan_card", "aadhaar": "aadhaar" },
"classify_aliases": { "pan": "pan_card", "aadhaar card": "aadhaar" },
"cross_match": {
"enabled": true,
"match_fields": ["name", "date_of_birth"],
"min_doc_types": 2
},
"pipeline_per_type": ["classify", "extract", "validate"]
},
"deployed": true
}
Response (201): Agent object.
List Agents
GET /v1/agents
Requires scope: read.
Query parameters:
tenant_idstringFilter by tenant. Returns all tenants if empty.
Response (200): Array of Agent objects.
Get Agent
GET /v1/agents/{agent_id}
Requires scope: read. Returns 404 if not found.
Path parameters:
agent_idstringrequiredUUID of the agent.
Update Agent
PUT /v1/agents/{agent_id}
Requires scope: write. Automatically snapshots the current state before applying the update. Returns 404 if not found.
Request body: Same fields as Create (all optional on update).
namestringdefinitionobjectversionstringallow_cloudbooleandeployedbooleanDelete Agent
DELETE /v1/agents/{agent_id}
Requires scope: write. Returns 204 No Content. Removes the agent from the in-memory cache and prevents new cases from routing to it.
Deploy / Undeploy Agent
PATCH /v1/agents/{agent_id}/deploy?deploy=true
Requires scope: write. Toggles the deployed flag without a full update.
Query parameters:
deploybooleanrequiredtrue to deploy, false to undeploy.
Version Endpoints
Every PUT (update) and rollback automatically snapshots the prior state. Snapshots accumulate in the agent_versions table.
List Agent Versions
GET /v1/agents/{agent_id}/versions
Requires scope: read.
Response (200): Array of version objects.
idstringagent_idstringtenant_idstringversionstringnamestringdefinitionobjectnotestring"auto-snapshot before rollback to version 2").created_atstringRollback Agent
POST /v1/agents/{agent_id}/rollback/{version_id}
Requires scope: write. Restores the agent to a prior snapshot. Automatically snapshots the current state before rolling back so the rollback is itself reversible. Returns the updated Agent object.
Path parameters:
agent_idstringrequiredversion_idstringrequiredBuilder Endpoints
The builder endpoints provide automated agent creation workflows — either from existing document types or from raw document samples.
Build Agent from Document Types
POST /v1/agents/build
Requires scope: write. Generates a complete agent definition from a list of existing document type IDs. Auto-generates doc_type_map, classify_aliases, and detects cross-match fields from the document types' output schemas.
Request body:
namestringrequiredAgent display name.
context_idsstring[]requiredList of document type IDs to include (must exist in the system).
tenant_idstringgoalstringOverride the auto-generated goal slug.
cross_match_fieldsstring[]Override auto-detected cross-match fields.
pipelinestring[]Pipeline steps per document type. Default: ["classify", "extract", "validate"].
deploybooleanDeploy the agent immediately after creation. Default false.
Example request:
{
"name": "KYC Verification",
"context_ids": ["pan_card", "aadhaar"],
"tenant_id": "acme-corp",
"deploy": true
}
Response (200):
{
"agent": { ... },
"contexts_existing": ["pan_card", "aadhaar"],
"contexts_created": []
}
Discover and Build Agent
POST /v1/agents/discover
Requires scope: write. Upload raw document samples — 9thSense uses a VLM to classify and extract each document, discovers their types, creates any missing document type configurations, and builds a complete agent automatically.
Request body:
documentsobject[]requiredArray of document objects, each with data (base64) and mime_type.
tenant_idstringnamestringOverride the auto-generated agent name.
cross_match_fieldsstring[]Override auto-detected cross-match fields.
pipelinestring[]Pipeline steps. Default: ["classify", "extract", "validate"].
deploybooleanDeploy the agent immediately. Default false.
Response (200):
{
"agent": { ... },
"contexts_created": ["driving_license"],
"contexts_existing": ["pan_card"]
}
Builder Wizard Endpoints
The wizard is a stateful, multi-step builder session for interactive agent construction.
Start Builder Session
POST /v1/agents/builder/start
Requires scope: write. Returns 201.
tenant_idstringmodestring"guided", "expert").Get Builder Session
GET /v1/agents/builder/{builder_id}
Requires scope: read.
Perform Builder Action
POST /v1/agents/builder/{builder_id}/action
Requires scope: write.
actionstringrequiredparamsobjectBuilder Chat
POST /v1/agents/builder/{builder_id}/chat
Requires scope: write. Conversational turn within a builder session.
messagestringrequiredattachmentsobject[]Response:
replystringstateobject