Skip to content

Agents

cemco-agents runs long-lived agents on Durable Objects with the Cloudflare Agents SDK and the AI SDK. Agents call the CRM only through env.API with an actor, so they obey the same roles, rules and audit log as people.

Agent Route What it does
AssistantAgent /agents/assistant-agent/<userId> (or /me) The in-app chat (AIChatAgent). One instance per staff user; messages persist in the Durable Object, streams resume after a reconnect, and every tool that changes data waits for the user’s approval. WebSocket from the app through app.cemco.app/agents/.... The app’s chat panel (apps/app/src/assistant) speaks these frames over a plain WebSocket
EmailAgent /agents/v1/email (status, sync, settings) One instance per staff user. Every 10 minutes it reads the user’s sent Gmail (token from AUTH), and it receives mail the user forwards or BCCs to crm@cemco.app. Matches the account, stores attachments as documents, logs each email once, and attaches signed quotes or creates review tasks. See Email filing
AccountWatcherAgent /agents/v1/watcher/run, /agents/v1/watcher/events One shared instance. Daily (and on CRM events from the cemco-agent-events queue) it turns what needs a person into tasks, once per finding: orders not yet valid or stalled, warranties ending within 60 days, overdue check-ins, accounts not contacted in 90 days. Sends a daily briefing email when BRIEFING_EMAIL_ENABLED is "true"
ImportWorkflow IMPORT_WORKFLOW binding Runs large imports as a durable Workflow: dry run, then apply in batches

Only signed-in staff (or a staff API key) may reach /agents/*; the Worker resolves the caller through AUTH and API before routing. The exceptions are GET /health and the watcher’s event webhook, which takes Authorization: Bearer <AGENTS_WEBHOOK_SECRET>.

Agent tools are built from the operation catalog, the same way MCP tools are, so the assistant can do anything the signed-in user can do and nothing more. Writes go through the dispatcher and are audited with the user, marked as made by the agent.

Model order:

  1. Anthropic (claude-opus-5-5, override with ANTHROPIC_MODEL) when ANTHROPIC_API_KEY is set.
  2. Otherwise Workers AI through the AI binding (WORKERS_AI_MODEL overrides the model). In local development the binding needs a Cloudflare login, so it is only used when AI_PROVIDER=workers-ai says so.
  3. With neither available, the assistant and the email classifier report not connected, and email filing runs on its rules alone.

AI_PROVIDER (anthropic, workers-ai or none) forces a provider. Model calls go through AI Gateway when AI_GATEWAY_ID is set (preview and production set default). GET /health on the agents Worker reports which provider is active.

Inbound mail reaches the Worker’s email() handler through Cloudflare Email Routing (set up in the dashboard for crm@cemco.app). It routes mail from an active admin or editor to that person’s EmailAgent, which checks that the sender is really them (header and envelope sender match, and the topmost Authentication-Results from INBOUND_AUTHSERV_ID shows DMARC or aligned DKIM/SPF passing); anything else is rejected. Outbound customer status emails are sent by cemco-api from its queue consumer with the EMAIL binding.