Next.js integration
Mount the Agentronics SDK once in a Next.js App Router project.
Next.js integration
@agentronics/react is a thin wrapper around @agentronics/sdk. It exposes the client through Context, plus four hooks. This guide walks through wiring it into a Next.js App Router project.
1. Install
2. Mount the provider
The provider must run on the client. Create app/agentronics-provider.tsx:
Then wrap the root layout:
The SDK initializes once on first mount and persists across route changes.
3. Provide site memory
Site memory is enterprise-authored context every agent class can read. Provide it once in a 'use client' boundary near the root:
4. Register governed tools
Tools registered with useGovernedTool automatically register on mount and unregister on unmount.
5. React to identity changes
useAgentContext reads the current identity reactively — it re-renders when the SDK detects an agent, when a token is presented, or when clearIdentity() is called.
6. Read site memory reactively
useSiteMemory() returns the live snapshot. Pass a dot-path to subscribe to a slice.
7. Server-side considerations
@agentronics/react is client-only. Don't import its hooks from server components. The provider lives in a 'use client' file and the SDK initializes on the browser — there is no Next.js-specific server runtime needed.
For static analytics on traces, fetch them from the Agentronics gateway, not from the client SDK.