Documentation

How ClarityAnchor turns an intrusive urge into a guided, model-driven grounding process you can watch unfold.

Overview

ClarityAnchor is an AI “Reality Anchor” for OCD and anxiety. You describe a trigger or urge; a Strands agent loads your anchors (objective facts you wrote while calm), checks the urge against them, names the cognitive distortion at play, and — for compulsive urges — pauses for a timed Exposure & Response Prevention (ERP) delay before giving a calm, grounded answer. The agent’s entire chain-of-thought is streamed live onto a diagnostic map.

Architecture

The browser posts the urge (and your saved anchors) to a Node API route that runs the Strands agent and streams every lifecycle event back over SSE. Tools run one at a time so the UI can reveal each step as a guided walkthrough.

Browser
Next.js · React Flow diagnostic map · Zustand
chat + tracelive mapERP timer
POST { urge, anchors }
AWS Strands Agent
model-driven loop · streamed over SSE from /api/agent (Node)
fetchBaselineRulesanalyzeDistortionrequestErpDelay
invokes the model
Amazon Bedrock — Claude
or built-in heuristic model (no key needed)
streams tool_start / tool_complete / done
Human-in-the-loop pause
a tool call blocks the loop → user confirms → /api/agent/resume continues it

Every lifecycle event is streamed back over SSE and drawn on the map as it happens.

The same Strands agent is also packaged for Amazon Bedrock AgentCore Runtime (serverless, session-isolated agent hosting) as a standalone /ping + /invocations service — the request/response counterpart to the streaming web app.

Full system diagram

Click the diagram to view it full size.

The agent & its tools

The agent is model-driven: it decides which tools to call. Three tools shape the process:

  • Your anchors — loads your Calm baseline facts and flags the one most relevant to the urge.
  • The thinking trap — identifies the cognitive distortion (e.g. intolerance of uncertainty, magnification) and offers the objective counter.
  • Pause & sit with it — the ERP delay; it pauses the agent until you choose to continue.

The ERP pause (human-in-the-loop)

When the agent recommends a delay, its tool call blocks the agent loop and the SSE stream goes quiet — the app shows a 3-minute countdown and a “Commit to Delay” button. Committing (or the timer finishing) hits /api/agent/resume, which releases the loop so it can finish with a grounded answer. Sitting with the urge before acting is the therapeutic point.

Your anchors

Anchors are objective facts you set while calm (e.g. “Checking the lock once is sufficient”). They’re saved in your browser and sent with every analysis, so the agent grounds urges against your own agreed reality rather than generic advice. No anchors set? Sensible defaults are used.

Running it

It works with zero configuration on a built-in, credential-free heuristic model. To drive it with a real LLM, add Amazon Bedrock credentials (IAM keys or a Bedrock API key) to .env.local or paste a key into the in-app settings — the app auto-detects them and the status pill turns green.

Stack

Agent frameworkAWS Strands Agents SDK (@strands-agents/sdk)
ModelAmazon Bedrock (Claude) · built-in heuristic fallback
FrontendNext.js (App Router), React 19
CanvasReact Flow (@xyflow/react)
StateZustand
StylingTailwind CSS, next-themes
StreamingServer-Sent Events