AI doesn't assist the workflow — it drives it. Below is how the system is designed.
Next.js 16
App Router, API Routes, Middleware Auth
Auth Layer
NextAuth JWT, per-route validation, role hierarchy
AI Engine
LLM with tool_use for agentic workflows
Tool Execution
8 tools: search, update, remind, note, query, bulk ops
Supabase
Postgres, RLS, Storage, real-time
The AI agent uses tool_use to reason and act in a loop. Each iteration: the AI decides what to do, the system validates and executes the tool, then returns the result for the next reasoning step.
while (iterations < MAX_TOOL_CALLS) {
response = ai.messages.create(tools, messages)
if (no tool_use) return response.text
for (tool in response.tool_use) {
validate(tool.name) // reject hallucinated tools
result = executeTool(tool) // try/catch with error recovery
messages.push(tool_result)
}
}
JWT Auth
Every API route validates NextAuth token before processing
Zod Validation
Request bodies validated against strict schemas — rejects malformed input
Tool Whitelist
Agent can only call 7 predefined tools — hallucinated tool names are rejected
Error Recovery
Tool failures return structured errors to the AI — agent recovers gracefully
Field Whitelist
Only specific claim fields can be modified — no arbitrary DB writes
Audit Trail
Every agent action logged with timestamp, tool name, and outcome
What I'd add before deploying to enterprise customers: