Skip to main content
Internal documentation for developers. This page documents the agents API endpoints, auth requirements, Prisma query patterns, and implementation notes. Not intended for end users.

Route Map


Auth Pattern

All agent endpoints use withPermissionRoute from @zappway/lib/create-route-handler.
READ endpoints: anyPermission: ['agents.read'] + authMode: 'lightweight' WRITE endpoints: anyPermission: ['agents.write'] (no authMode — uses full session) Org isolation: All queries must scope to req.session.organization.id.

Core CRUD

List Agents

Create Agent

Get Agent by ID


Skills Sub-API

Key Library Functions

Skill Scope Logic

Slug Uniqueness Constraint

When creating/updating a slug, always check for conflicts:

List Skills Response Type


Specialists Sub-API

Cycle Detection

The PUT /specialists handler detects cycles at depth-1 before creating a delegation:

specialistRule Config Structure

Deactivate: Removes specialistRule


Known Issues / Gotchas

  • assertAgentBelongsToOrganization — Always call this before any agent-specific DB operation to prevent cross-org data leaks. It throws if the agent doesn’t match the org.
  • propose-from-rag uses a skipped counter for proposals that closely match existing skills (by slug). The threshold is defined in @zappway/lib/agent-skills.
  • Specialists PUT is IDEMPOTENT but NOT STRICTLY ATOMIC at the DB level (see inline comment in code: IDEMPOTENT_BUT_NOT_ATOMIC). Under high concurrency, two parallel requests could both create a duplicate delegation. A DB-level unique index on (agent_id, type, config->>'targetAgentId') would fix this.
  • Status lastReviewedAt is only updated when status changes to active or archived, not on general PATCH updates.
  • Onboarding prompt generationPOST /api/agents/onboarding/generate-prompt calls the seeded RAG Builder agent first and uses the OpenRouter backup only after a no-tick timeout or a hard agent error. The backup request must use the current OpenAI-compatible output-token parameter and typed JSON/error handling.

Prisma Indexes Used


Error Reference