SAP Explorer Docs
SDK Reference

Plugin Adapter

Bridge 52 SAP tools into LangChain, Vercel AI, or any LLM framework through the SynapseAgentKit plugin.

Plugin Adapter

The plugin adapter bridges the full SAP protocol surface into the SynapseAgentKit ecosystem. Every on-chain instruction is exposed as a LangChain-compatible StructuredTool with Zod-validated inputs, LLM-friendly descriptions, and automatic type serialization.

An LLM can call any SAP instruction without ever touching Solana primitives directly.

Prerequisites

The plugin adapter requires two npm packages:

PackagePurpose
@oobe-protocol-labs/synapse-sap-sdkSAP protocol SDK (provides createSAPPlugin)
@oobe-protocol-labs/synapse-client-sdkSynapse AI toolkit (provides SynapseAgentKit)
# Install both packages
pnpm add @oobe-protocol-labs/synapse-sap-sdk @oobe-protocol-labs/synapse-client-sdk

synapse-sap-sdk is the SAP on-chain SDK you have been using throughout these docs. synapse-client-sdk is a separate package that provides the AI agent framework (LangChain integration, multi-plugin system, tool orchestration). The plugin adapter bridges the two.

Quick Start

import { SynapseAgentKit } from "@oobe-protocol-labs/synapse-client-sdk/ai/plugins";
import { createSAPPlugin } from "@oobe-protocol-labs/synapse-sap-sdk/plugin";
import { AnchorProvider } from "@coral-xyz/anchor";

// provider: an AnchorProvider with a connected wallet (signer)
const provider = AnchorProvider.env();

// createSAPPlugin returns a SynapsePlugin exposing 52 on-chain tools
const sapPlugin = createSAPPlugin({
  provider,             // required: Anchor provider with wallet signer
  // programId,         // optional: override SAP program ID (default: mainnet)
});

// SynapseAgentKit orchestrates plugins and converts tools to LangChain format
const kit = new SynapseAgentKit({
  rpcUrl: "https://api.mainnet-beta.solana.com", // Solana RPC endpoint
})
  .use(sapPlugin);     // register the SAP plugin

const tools = kit.getTools(); // 52 StructuredTool instances (LangChain-compatible)

Standalone usage: If you do not need SynapseAgentKit, you can use createSAPPlugin directly. The plugin's install() method returns an executor function you can call manually.

How It Works

The plugin follows a four-layer pipeline:

  1. Schemas (Zod): Runtime validation plus LLM-friendly .describe() strings
  2. Protocols (8 domains): Method registries mapping tool names to schema pairs
  3. Executor: Dispatches to SapClient module methods with automatic serialization
  4. Solana RPC: Transaction submitted, confirmed, signature returned

The 8 Protocol Domains

DomainIDToolsDescription
Agent Identitysap-agent8Registration, lifecycle, reputation
Trustless Reputationsap-feedback4On-chain feedback
Web of Trustsap-attestation3Cross-agent attestations
x402 Escrowsap-escrow6Micropayments
Tool Registrysap-tools7Tool schemas, versioning
Encrypted Memorysap-vault10Vault, sessions, delegation
Discovery Indexessap-indexing8Capability and protocol indexes
Memory Ledgersap-ledger6Ring buffer, sealed pages
Total52

Serialization Bridge

The executor handles all type conversions automatically:

DirectionConversion
LLM to ChainBase58 string to PublicKey
LLM to ChainNumeric string to BN
LLM to ChainHex string to Buffer
LLM to ChainEnum string to Anchor variant
Chain to LLMPublicKey to Base58 string
Chain to LLMBN to numeric string

An LLM produces JSON like {"agent": "7xKXtg...", "amount": "1000000000"} and the executor converts types appropriately before calling the Anchor instruction.

Zod Schema Conventions

Solana TypeZod Representation
PublicKeyz.string().min(32).max(44)
BN / u64z.string() (numeric)
[u8; 32] hashz.array(z.number()).length(32)
Anchor enumz.enum(["sol", "usdc", "spl"])

All write operations return { txSignature: string } in the output schema.

Configuration

import { createSAPPlugin } from "@oobe-protocol-labs/synapse-sap-sdk/plugin";

// Minimal: uses canonical program ID
const plugin = createSAPPlugin({ provider });

// Custom program ID (e.g. localnet)
const plugin = createSAPPlugin({
  provider,
  programId: new PublicKey("YourCustomProgramId"),
});

Full LangChain Integration

import { ChatOpenAI } from "@langchain/openai";
import { AgentExecutor, createStructuredChatAgent } from "langchain/agents";

const llm = new ChatOpenAI({ model: "gpt-4o" });
const agent = await createStructuredChatAgent({ llm, tools, prompt });
const executor = AgentExecutor.fromAgentAndTools({ agent, tools });

const result = await executor.invoke({
  input: "Register a new agent called SwapBot with Jupiter swap capability",
});