Skip to content

anchor-engine/anchor-sdk

Repository files navigation

@anchor-engine/sdk

npm version MIT License

Anchor is an open-source intent preservation layer for LLM agents. It monitors agent actions in real-time, detecting and correcting "intent drift" before it leads to hallucinations or out-of-bounds behavior.

Important

Validated Performance (CNN/DailyMail Benchmark):

  • +9.2% High-Fidelity Lift: Significantly improves the grounding of agent-generated summaries.
  • 0% IFEval Regression: Zero impact on instruction-following capabilities.
  • 0% Tau2 Regression: Maintains absolute stability in sequential reasoning.

Get Started: Sign up at anchor-app-one.vercel.app to get your free API key.


Quickstart

Add Anchor to any AI agent project in just three lines of code.

1. Register & Get API Key

Sign up at anchor-app-one.vercel.app and generate your key from the Settings dashboard.

Note: The SDK is a cloud-first library and will securely communicate with the Anchor Engine via this API key. No local deployment is required.

2. Install

npm install @anchor-engine/sdk

2. Guard Your Agent

import { Anchor } from '@anchor-engine/sdk';

// 1. Initialize with your API key
const anchor = new Anchor({ apiKey: process.env.ANCHOR_API_KEY });

// 2. Define an intent contract for the task
const contract = await anchor.contract({ 
  task: "Build the project in /projects/myapp only. Do not touch core library files." 
});

// 3. Score agent actions in real-time
const result = await anchor.score(agentAction, contract.id);

if (!result.allow) {
  console.log(`Action blocked: ${result.intervention.message}`);
}

}


---

## Why Anchor?

Current LLM evaluation frameworks (like HHEM or IFEval) are generally applied *post-hoc*, assessing a system's quality long after a session has ended. 

**Anchor** brings evaluation into the *execution loop*. We call this **Intent Preservation**. By scoring agent actions in real-time, Anchor actively prevents divergence (drift) from the user's original objective safely and transparently.

---

## Features

- **Real-time Drift Monitoring**: Catch hallucinations the moment they occur.
- **Auto-Correction (Critique Loop)**: Automatically rewrites drifted actions to stay within contract scope.
- **Framework Native**: First-class support for LangChain, Claude Code, and more.
- **Zero Latency Overhead**: Asynchronous monitoring keeps your agents fast.

## Adapters

### LangChain
```typescript
import { LangChainAnchorCallback } from '@anchor-engine/sdk/adapters/langchain';

const executor = await initializeAgentExecutorWithOptions(tools, model, {
  callbacks: [new LangChainAnchorCallback({ anchor, contractId: contract.id })],
});

Claude Code / Generic Interception

Use the watch() proxy to automatically wrap any agent object:

const guardedAgent = anchor.watch(myAgent, contract.id);

// Automatically scores every .act(), .run(), or .execute() call
await guardedAgent.act({ type: 'file_write', target: '/src/main.ts', ... });

Examples

We provide robust examples containing copy-pasteable scripts for integrating Anchor into your existing workflows:


Troubleshooting & FAQ

Q: I get Missing ANCHOR_API_KEY when initializing the SDK. What do I do? A: Anchor requires a valid API key to communicate with the scoring engine. Sign up for free at anchor-app-one.vercel.app, generate a key in Settings, and inject it securely via your environment variables: export ANCHOR_API_KEY=your_key.

Q: Does Anchor require me to run a local backend or database? A: No! The open-source SDK communicates completely with our hosted cloud engine. There is zero local infrastructure required.

Q: Why was my action flagged with Drift detected? A: Anchor acts strictly based on the IntentContract you defined. If the agent's action deviates from the original instruction or violates constraints, it is flagged. You can view detailed scoring telemetry for every action in your Anchor Dashboard.


Benchmarks & Research

Anchor is based on research into real-time intent enforcement. Our latest benchmark on the CNN/DailyMail corpus with gemma4:31b-cloud shows a 9.2% net increase in high-fidelity grounding.

Read the full technical report: TECHNICAL_REPORT.md

Citation

If you use Anchor in your research or project, please cite:

@techreport{rahman2026anchor,
  title={Anchor: Real-Time Intent Preservation in LLM Agents},
  author={Rahman, Hasin},
  year={2026},
  url={https://github.com/anchor-engine/anchor-sdk}
}

License

MIT © anchor-engine

About

Real-time intent preservation layer for LLM agents. Stops hallucination drift before it executes.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors