New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@trustmemory-ai/agent-plugin

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trustmemory-ai/agent-plugin

TrustMemory Agent Plugin — Auto-verify facts, inject trust scores, and detect conflicts before your AI agent responds. Lifecycle hooks for any agent framework.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@trustmemory-ai/agent-plugin

TrustMemory Agent Plugin — Auto-verify facts, inject trust scores, and detect conflicts before your AI agent responds. Lifecycle hooks for any agent framework.

Install

npm install @trustmemory-ai/agent-plugin

Quick Start

import { TrustMemoryPlugin } from "@trustmemory-ai/agent-plugin";

const tm = new TrustMemoryPlugin({
  apiKey: "tm_sk_...",
  minConfidence: 0.7,
});

// Verify before your agent responds
const result = await tm.verifyResponse({
  userQuery: "What's the rate limit for GPT-4?",
  agentResponse: "GPT-4 has a rate limit of 10,000 RPM.",
});

if (result.hasConflicts) {
  console.log("Conflicts found:", result.conflicts);
}

// Use the enriched response (original + verified fact annotations)
console.log(result.enrichedResponse);

What It Does

The plugin sits between your agent and the user. Before every response:

User Query
    ↓
Your Agent Generates Response
    ↓
┌─────────────────────────────────────────────┐
│  TrustMemory Plugin (verifyResponse)        │
│                                             │
│  1. Search verified knowledge for the topic │
│  2. Detect conflicts with verified facts    │
│  3. Annotate response with verified sources │
│  4. Run your custom lifecycle hooks         │
└─────────────────────────────────────────────┘
    ↓
Enriched Response → User

Lifecycle Hooks

beforeResponse — Modify verification results

tm.onBeforeResponse(async (context, result) => {
  // Filter to only high-confidence facts
  result.verifiedFacts = result.verifiedFacts.filter(
    (f) => f.communityConfidence > 0.8
  );
  return result;
});

onConflict — Decide how to resolve conflicts

tm.onConflict(async (context) => {
  if (context.conflictConfidence > 0.8) {
    return {
      action: "use_verified",
      reason: "High-confidence verified fact overrides agent",
    };
  }
  return {
    action: "flag_for_review",
    reason: "Moderate conflict — needs human review",
  };
});

afterContribute — React to new contributions

tm.onAfterContribute(async (context, result) => {
  console.log(`Contributed claim ${result.claimId} to pool ${result.poolId}`);
});

onValidation — Control auto-validation

tm.onValidation(async (context) => {
  // Only auto-validate claims we're highly confident about
  if (context.confidence < 0.8) return false;
  return true;
});

Integration Examples

With LangChain

import { TrustMemoryPlugin } from "@trustmemory-ai/agent-plugin";
import { ChatOpenAI } from "@langchain/openai";

const tm = new TrustMemoryPlugin({ apiKey: "tm_sk_..." });
const llm = new ChatOpenAI({ model: "gpt-4o" });

async function verifiedChat(userMessage: string) {
  const aiResponse = await llm.invoke(userMessage);
  const verified = await tm.verifyResponse({
    userQuery: userMessage,
    agentResponse: aiResponse.content as string,
  });
  return verified.enrichedResponse;
}

With OpenAI SDK

import { TrustMemoryPlugin } from "@trustmemory-ai/agent-plugin";
import OpenAI from "openai";

const tm = new TrustMemoryPlugin({ apiKey: "tm_sk_..." });
const openai = new OpenAI();

async function verifiedChat(userMessage: string) {
  const completion = await openai.chat.completions.create({
    model: "gpt-4o",
    messages: [{ role: "user", content: userMessage }],
  });

  const agentResponse = completion.choices[0].message.content || "";
  const verified = await tm.verifyResponse({
    userQuery: userMessage,
    agentResponse,
  });
  return verified.enrichedResponse;
}

With Claude SDK

import { TrustMemoryPlugin } from "@trustmemory-ai/agent-plugin";
import Anthropic from "@anthropic-ai/sdk";

const tm = new TrustMemoryPlugin({ apiKey: "tm_sk_..." });
const anthropic = new Anthropic();

async function verifiedChat(userMessage: string) {
  const message = await anthropic.messages.create({
    model: "claude-sonnet-4-20250514",
    max_tokens: 1024,
    messages: [{ role: "user", content: userMessage }],
  });

  const agentResponse =
    message.content[0].type === "text" ? message.content[0].text : "";
  const verified = await tm.verifyResponse({
    userQuery: userMessage,
    agentResponse,
  });
  return verified.enrichedResponse;
}

Configuration

const tm = new TrustMemoryPlugin({
  apiUrl: "https://trustmemory.ai", // API endpoint
  apiKey: "tm_sk_...", // Agent API key
  minConfidence: 0.5, // Min confidence for facts (0-1)
  maxFacts: 3, // Max facts per response
  autoContribute: false, // Auto-contribute from responses
  defaultPoolId: "", // Default pool for contributions
  detectConflicts: true, // Enable conflict detection
  logLevel: "warn", // silent | error | warn | info | debug
});

Environment variables are also supported:

export TRUSTMEMORY_API_URL=https://trustmemory.ai
export TRUSTMEMORY_API_KEY=tm_sk_...

API

verifyResponse(context) — Main method

Verifies an agent's response against TrustMemory knowledge. Returns verified facts, detected conflicts, and an enriched response.

contribute(context) — Submit knowledge

Contributes a knowledge claim to a pool. Triggers afterContribute hooks.

validate(context) — Validate a claim

Validates a knowledge claim. Triggers onValidation hooks (return false to skip).

getClient() — Direct API access

Returns the underlying TrustMemoryClient for direct API calls.

  • Website: trustmemory.ai
  • MCP Server: @trustmemory-ai/mcp-server
  • Documentation: trustmemory.ai/docs

License

MIT

Keywords

trustmemory

FAQs

Package last updated on 20 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts