Copilot Agents
@cona/agents — Mastra-based agents routed through Vercel AI Gateway. Two entry points:
the CopilotKit runtime in the webapp, and a Temporal activity for reconciliation.
Wiring
Package surface
packages/agents/src/:
Consumers: webapp (10 imports),
@cona/temporal-workflows (3 imports).
Model routing
Every model id is forced through Vercel AI Gateway —agents.ts:27-29 prefixes with
vercel/ unless already prefixed. There is no direct provider SDK call anywhere in the
package.
Two invocation paths
Interactive — CopilotKit
apps/webapp/app/api/copilotkit/route.ts runs on the Node runtime with CopilotKit’s
InMemoryAgentRunner from @copilotkit/runtime/v2. Before anything else it calls
assertCopilotEnabled — the feature is flag-gated.
The route composes three inputs into the agent’s instructions:
- Copilot memory —
getCopilotMemory, persisted per organisation - Knowledge selection —
selectKnowledgepicks relevant instruction fragments - Task-specific instructions — e.g.
getReconciliationAgentInstructions
isConaCopilotAgentId before dispatch, so an arbitrary
agent name in the request envelope cannot reach the runner.
Background — Temporal
packages/temporal-workflows/src/activities/reconciliation/run-reconciliation-agent.ts
invokes the same agents from reconciliationAgentSuggestionsWorkflow, so suggestions are
generated in bulk rather than only on demand. See
Reconciliation & Payments.
Audit
Three tables in the Platform cluster:
The
copilot-audit core domain owns writes. reconciliation-agent imports it 7 times
— the strongest single edge into that domain, because every suggestion, approval, and
rejection is recorded.
Users can inspect and edit memory at
(settings)/(configuration)/settings/copilot-memory.
Notes
Agents propose, humans dispose. Nothing the reconciliation agent produces is applied automatically —execute-reconciliation-agent-suggestion.ts runs only after approval, and
reject-reconciliation-agent-suggestion.ts records the alternative.
There is a learning loop. learn-approved-candidate-allocation-iban.ts records the
IBAN association once a human approves, and get-manual-reconciliation-examples.ts feeds
prior manual work back as examples.
Copilot is flag-gated. assertCopilotEnabled guards the route, so the feature can be
disabled per environment.
Instructions are assembled, not hardcoded. buildAgentInstructions combines the
knowledge subtree, organisation memory, and task instructions at request time.