What it does
This example demonstrates the @grantex/langchain integration by building a LangChain agent with Grantex-scoped tools:
- Register an agent and obtain a grant token via the sandbox flow
- Create scoped tools using
createGrantexTool — each tool is bound to a specific scope (calendar:read, email:send)
- Attach a
GrantexAuditHandler that automatically logs every tool invocation to the Grantex audit trail
- Invoke tools directly (or via an LLM if
OPENAI_API_KEY is set)
- Demonstrate scope enforcement — attempting to create a tool with
account:delete (a scope not in the grant) throws immediately
- Inspect the audit trail to see the logged actions
Prerequisites
- Node.js 18+
- Docker (Docker Desktop or Docker Engine with Compose)
Run
Start the local Grantex stack from the repository root:
In a separate terminal, run the example:
To use a real LLM for tool selection instead of direct invocation, set OPENAI_API_KEY:
Expected output
Environment variables
Source code
The full source is in examples/langchain-agent/src/index.ts.Last modified on February 28, 2026