# Zervice Chatbot — Agent-First Management Plane Zervice Chatbot is an agent-first platform for building, grounding, orchestrating, and testing AI assistants across websites and external A2A workflows. - **Canonical Documentation Source of Truth:** `https://chat.zervice.us/api/v1/admin/llms.txt` and `https://chat.zervice.us/docs` (applies identically to both Zervice Cloud and self-hosted deployments). - **Target Workspace Base URL:** Point `Authorization: Bearer zrv_pat_...` requests and MCP clients to `https://chat.zervice.us` (Managed Cloud) or `https://chat.zervice.us` / your custom self-hosted domain (`https://`). Every deployment exposes the exact same concepts, FlowSpecs, REST endpoints, and MCP tools. ## Documentation ### Guides & Mental Model - [5-Minute Agent Quickstart](https://chat.zervice.us/docs/quickstart.md): Create a workspace Personal Access Token, connect via MCP or REST, and run your first discovery and dry-run simulation. - [Core Concepts & Mental Model](https://chat.zervice.us/docs/concepts.md): How Workspaces, Bots, the Workspace Library, the 4-layer visitor turn pipeline, and Draft vs Published states work. - [Declarative FlowSpec Reference](https://chat.zervice.us/docs/flow-spec.md): Complete specification for validating, authoring, and exporting Dialog Flows as declarative JSON. - [Knowledge Base, Simulation & Quality Loop](https://chat.zervice.us/docs/knowledge-and-quality.md): How to structure Markdown knowledge for high search recall, run isolated multi-turn simulations, and diagnose quality gaps. - [REST API & MCP Reference](https://chat.zervice.us/docs/api.md): Authentication, capability scopes, error semantics, Streamable HTTP MCP usage, and full endpoint catalog. - [Autonomous Agent Playbooks](https://chat.zervice.us/docs/workflows.md): Step-by-step end-to-end playbooks for setup, CI doc sync, workflow authoring, and weekly quality tuning. ### Machine-Readable Discovery - [Full Handbook (/api/v1/admin/llms-full.txt)](https://chat.zervice.us/api/v1/admin/llms-full.txt): Single-fetch concatenation of all guides and references - [OpenAPI 3.1 Specification (/api/v1/admin/openapi.json)](https://chat.zervice.us/api/v1/admin/openapi.json): Complete typed REST API schema - [Docs Portal (/docs)](https://chat.zervice.us/docs): Human-browseable documentation hub ## Quick Integration Workflow (5-Step Autonomous Agent Playbook) 1. **Discover**: Call `GET /api/v1/admin/whoami` and `GET /api/v1/admin/discover` (or MCP `workspace_whoami` + `workspace_discover`) for a one-shot snapshot of bots, Knowledge Collections, Knowledge Sources, Dialog Flows, integrations, and 7-day quality signals. 2. **Idempotent Upsert**: Supply a stable `externalId` (`^[a-z0-9][a-z0-9_-]{1,62}$`) when creating bots, collections, sources, items, flows, or integrations so retries safely update in place. 3. **Author Declarative FlowSpecs**: Validate with `POST /api/v1/admin/flows/validate` before persisting with `PUT /api/v1/admin/flows/by-external-id/:externalId/spec`. Always give nodes concise human-readable `"name"` titles (2–5 words, especially `condition` routers and jump targets), give branches clear `"intentName"` labels, and stage drafts using `status: "build"` (`content:draft`). 4. **Dry-Run Simulation**: Test turns safely with `POST /api/v1/admin/bots/:botId/simulate` (`toolMode: "mock"`, `useDrafts: true`) in an isolated temporary session with zero writes to conversation logs, leads, or analytics. 5. **Close Quality Gaps**: Query `GET /api/v1/admin/analytics/gaps?days=7` and `GET /api/v1/admin/logs?bot_id=all&outcome=fallback`, fill missing Knowledge Items or review-queued Hot Questions, and re-verify in simulation. ## Key Concepts - **Workspace Isolation & Multi-Bot Library**: A PAT is strictly scoped to one Workspace (tenant) and filtered by capability scopes. Workspaces hold shared Knowledge Collections, Dialog Flows, Integrations, and Secrets bound flexibly to one or more Bots (e.g., Public Website Bot vs. Signed-In Customer Bot). - **4-Layer Visitor Turn Pipeline**: Every visitor query evaluates in order: (1) **Dialog Flows** (typed Saved Fields `{{slot_name}}`, deterministic branching, terminal `agent` handoffs, and mid-flow off-topic Q&A escape + resume), (2) **Hot Questions Instant Cache** (`review` draft queue vs `active` live FAQ), (3) **Business Integrations** (live lookups & visitor Confirmation Gates), and (4) **Knowledge Base Q&A** (grounded answers with citations, polite declines when ungrounded). - **Secrets Vault**: Outbound credentials live in write-only workspace storage and are interpolated only at runtime via `{{secret.NAME}}` inside Business Integrations. - **Common Mistakes to Avoid**: - Do NOT leave `condition` nodes or shared jump targets without a concise human-readable `"name"` (Flow Studio cards and Goto jumps render `name` instead of raw slot rules). - Do NOT mix `branches[]` and `next`/`end` on the same FlowSpec `bot` node. - Do NOT attach `branches[]`, `next`, or `end` to a FlowSpec `agent` node (`agent` is terminal). - Do NOT skip `flow_validate_spec` before `flow_put_spec`. - Do NOT try to publish (`status: "published"` / `"active"`) with a `content:draft` token; stage as `"build"` / `"review"` and test via `bot_simulate_turn`. ## Authentication & Scopes Granted PAT Scopes: - `bots:read` - `bots:write` - `bots:delete` - `content:read` - `content:draft` - `content:write` - `analytics:read` - `leads:read` - `integrations:read` - `integrations:write` - `api_keys:manage` - `users:manage` - `tenant:settings` Role Presets: - `draft_builder` (Draft Builder Agent (Safe Mode — Recommended)): bots:read, content:read, content:draft, analytics:read - `observer` (Observer / Analytics Agent): bots:read, content:read, analytics:read - `full_builder` (Full Workspace Builder Agent): bots:read, bots:write, bots:delete, content:read, content:draft, content:write, integrations:read, integrations:write, leads:read, analytics:read, tenant:settings - `ci_docs_sync` (CI Docs Sync): content:read, content:write ## MCP Client Configuration ```json { "mcpServers": { "zervice-admin": { "type": "http", "url": "https://chat.zervice.us/api/v1/admin/mcp", "headers": { "Authorization": "Bearer zrv_pat_YOUR_KEY" } } } } ``` ## Curated Tools & REST Endpoints (42 total) ### Domain: workspace - `workspace_whoami` (GET `/api/v1/admin/whoami`, scopes: none): Returns the authenticated workspace principal, authentication type (pat or session), role, and resolved capability scopes. - `workspace_discover` (GET `/api/v1/admin/discover`, scopes: none): Returns a single scope-filtered snapshot of all workspace resources: bots, Knowledge Collections, Knowledge Sources, Dialog Flows, integrations, secret names, Account Lead Notification Webhook status, starter templates, and 7-day quality metrics. - `workspace_embed_get` (GET `/api/v1/admin/workspace/embed`, scopes: `bots:read`): Reads the workspace embed key, URL routing rules, exclusion globs, and default bot fallback action for the single-line website widget. - `workspace_embed_put` (PUT `/api/v1/admin/workspace/embed`, scopes: `bots:write`): Updates global website widget URL routing rules, excluded path globs, and fallback bot selection. - `account_lead_webhook_get` (GET `/api/v1/admin/account/lead-webhook`, scopes: `tenant:settings`): Reads the account-wide outbound lead notification webhook configuration (enabled, target URL, and masked signing secret hint). - `account_lead_webhook_put` (PUT `/api/v1/admin/account/lead-webhook`, scopes: `tenant:settings`): Configures the account-wide outbound webhook URL and HMAC-SHA256 signing secret notified with lead.created JSON events whenever any bot captures a lead. - `account_lead_webhook_test` (POST `/api/v1/admin/account/lead-webhook/test`, scopes: `tenant:settings`): Sends a signed sample lead.created event to the configured (or candidate) Account Lead Notification Webhook URL and returns HTTP status telemetry. ### Domain: bots - `bot_list` (GET `/api/v1/admin/bots`, scopes: `bots:read`): Lists every chatbot agent in the current workspace along with configuration and stats. - `bot_get` (GET `/api/v1/admin/bots/{botId}`, scopes: `bots:read`): Fetches a single bot configuration record by botId. - `bot_upsert` (POST `/api/v1/admin/bots`, scopes: `bots:write`): Creates a bot or idempotently updates the existing bot when externalId already exists in the workspace. - `bot_patch` (PATCH `/api/v1/admin/bots/{botId}`, scopes: `bots:write`): Partially updates an existing bot’s name, description, persona prompt, greeting, fallback message, brand color, or settings by botId. - `bot_delete` (DELETE `/api/v1/admin/bots/{botId}`, scopes: `bots:delete`): Deletes a non-default bot from the workspace. - `bot_assign_assets` (PUT `/api/v1/admin/bots/{botId}/assets`, scopes: `content:write`): Replaces a bot’s assigned Knowledge Collections, Dialog Flows, and Integrations in a single atomic payload. Accepts internal IDs or external_id values. - `bot_simulate_turn` (POST `/api/v1/admin/bots/{botId}/simulate`, scopes: `bots:read`, `content:read`): Runs the deterministic production conversation pipeline (Dialog Flows, Hot Questions Instant Cache, Social turns, Business Tools, and Knowledge Base retrieval) in an isolated ephemeral session with zero writes to conversation logs, leads, or analytics. ### Domain: knowledge - `kb_collection_list` (GET `/api/v1/admin/knowledge/collections`, scopes: `content:read`): Lists all Knowledge Collections in the workspace along with document counts. - `kb_collection_upsert` (POST `/api/v1/admin/knowledge/collections`, scopes: `content:write`): Creates a Knowledge Collection or idempotently updates the existing collection matching externalId. - `kb_collection_delete` (DELETE `/api/v1/admin/knowledge/collections/{collectionId}`, scopes: `content:write`): Deletes a Knowledge Collection and all of its indexed Knowledge Items. - `kb_source_list` (GET `/api/v1/admin/knowledge/connectors`, scopes: `content:read`): Lists configured Knowledge Sources (sitemaps, website crawlers, and remote feeds) in the workspace. - `kb_source_upsert` (POST `/api/v1/admin/knowledge/collections/{collectionId}/connectors`, scopes: `content:write`): Creates or idempotently updates a Knowledge Source (crawler, sitemap, or document feed) under a Knowledge Collection using externalId or (kind, rootUrl). - `kb_source_sync` (POST `/api/v1/admin/knowledge/connectors/{connectorId}/sync`, scopes: `content:write`): Triggers a synchronous/manual sync run on a Knowledge Source and returns sync stats. Rate-limited to 20 calls/min per workspace. - `kb_item_list` (GET `/api/v1/admin/knowledge/collections/{collectionId}/items`, scopes: `content:read`): Lists Knowledge Items inside a Knowledge Collection along with status and chunk count. - `kb_item_get` (GET `/api/v1/admin/knowledge/items/{itemId}`, scopes: `content:read`): Returns a Knowledge Item record, stored document preview, and indexed sections. - `kb_item_upsert` (PUT `/api/v1/admin/knowledge/collections/{collectionId}/items`, scopes: `content:write`): Idempotently creates or updates a markdown/text Knowledge Item in a collection by externalId, id, or uri, skipping re-indexing and returning action="unchanged" when contentHash and title match. ### Domain: flows - `flow_list` (GET `/api/v1/admin/flows`, scopes: `content:read`): Lists Dialog Flows in the workspace (optionally filtered by botId) along with publish status. - `flow_get_spec` (GET `/api/v1/admin/flows/{flowId}/spec`, scopes: `content:read`): Exports an existing Dialog Flow and its node graph as a clean declarative JSON FlowSpec. - `flow_validate_spec` (POST `/api/v1/admin/flows/validate`, scopes: `content:read`): Runs structural, reachability, cycle, display-name, and variable checks against a declarative JSON FlowSpec without saving changes. Give nodes concise human-readable "name" titles so Studio cards and Goto jumps stay readable. - `flow_put_spec` (PUT `/api/v1/admin/flows/{flowId}/spec`, scopes: `content:draft`): Validates, compiles, and atomically writes a declarative JSON FlowSpec by flowId or externalId. Provide concise "name" display labels on bot, condition, agent, and call nodes. Publishing (status="published") or modifying botIds requires content:write. - `flow_delete` (DELETE `/api/v1/admin/flows/{flowId}`, scopes: `content:draft`): Deletes a Dialog Flow and unbinds it from workspace bots. ### Domain: hot_questions - `hot_question_list` (GET `/api/v1/admin/hot-questions`, scopes: `content:read`): Lists cached FAQ Hot Questions (active and review queue) for a bot. - `hot_question_upsert` (POST `/api/v1/admin/hot-questions`, scopes: `content:draft`): Creates a Hot Question or upserts by normalized question when upsert=true. Draft status "review" needs content:draft; active/pinned requires content:write. - `hot_question_delete` (DELETE `/api/v1/admin/hot-questions/{id}`, scopes: `content:draft`): Deletes a Hot Question FAQ entry from the cache or review queue. ### Domain: integrations - `integration_list` (GET `/api/v1/admin/integrations`, scopes: `integrations:read`): Lists HTTP REST Tool, MCP Server, and A2A Agent integrations registered in the workspace. - `integration_upsert` (POST `/api/v1/admin/integrations`, scopes: `integrations:write`): Registers an HTTP REST tool, remote MCP server, or A2A agent integration, idempotently updating existing records with the same externalId. - `integration_discover` (POST `/api/v1/admin/integrations/discover`, scopes: `integrations:write`): Queries a remote MCP server (tools/list) or A2A agent card to preview available tools and skills before saving an integration. - `integration_test` (POST `/api/v1/admin/integrations/test`, scopes: `integrations:write`): Executes a live test invocation against a saved integration (integrationId) or inline draft config and returns the response payload and HTTP status. - `integration_delete` (DELETE `/api/v1/admin/integrations/{integrationId}`, scopes: `integrations:write`): Deletes a Workspace Integration and removes its bot bindings. - `workspace_secret_list` (GET `/api/v1/admin/workspace/secrets`, scopes: `integrations:read`): Lists configured secret identifiers and masked value hints in the workspace vault (never returns plaintext secret values). - `workspace_secret_put` (PUT `/api/v1/admin/workspace/secrets`, scopes: `integrations:write`): Stores or updates a write-only encrypted credential in the workspace secrets vault (referenced via {{secret.NAME}}). Secret values are never returned. - `workspace_secret_delete` (DELETE `/api/v1/admin/workspace/secrets/{name}`, scopes: `integrations:write`): Deletes a named credential from the workspace secrets vault. ### Domain: analytics - `analytics_logs_query` (GET `/api/v1/admin/logs`, scopes: `analytics:read`): Queries conversation logs across a bot or entire workspace ("all") filtered by outcome tier, feedback, timeframe, session, or text search. - `analytics_gaps_report` (GET `/api/v1/admin/analytics/gaps`, scopes: `analytics:read`): Aggregates fallback rates, clustered unanswered visitor queries, negative feedback, failing tool calls, and Knowledge Source sync errors. - `leads_list` (GET `/api/v1/admin/leads`, scopes: `leads:read`): Lists captured leads for a bot (including contact details, inquiry, and flow metadata).