The agent orchestration layer for Index Network. Implements LangGraph-based workflows for intent processing, opportunity discovery, and chat — decoupled from any specific infrastructure via adapter injection.
npm install @indexnetwork/protocolCall configureProtocol once at startup before creating any tools or graphs:
import { configureProtocol } from "@indexnetwork/protocol";
configureProtocol({
apiKey: process.env.OPENROUTER_API_KEY,
chatModel: "google/gemini-2.5-flash", // optional — has a default
chatReasoningEffort: "low", // optional: minimal | low | medium | high | xhigh
});The package defines interfaces — your application provides the concrete implementations:
| Interface | Responsibility |
|---|---|
ChatGraphCompositeDatabase |
Core data access (users, intents, indexes, opportunities) |
Embedder |
Vector embeddings for semantic search |
Scraper |
Web content extraction |
Cache / HydeCache |
Result caching |
IntegrationAdapter |
OAuth and external tool actions |
ContactServiceAdapter |
Contact management |
IntentGraphQueue |
Background intent processing queue |
ChatSessionReader |
Load conversation history |
ProfileEnricher |
Enrich profiles from external sources |
NegotiationDatabase |
Negotiation state persistence |
AgentDatabase |
Agent registry CRUD (agents, transports, permissions) |
AgentDispatcher |
Resolves and invokes agents during negotiation turns |
McpAuthResolver |
Resolves { userId, agentId } from an incoming MCP HTTP request |
All interfaces are exported from the package root — import them with import type { ... } from "@indexnetwork/protocol".
Pass your adapter implementations to createChatTools to get a set of LangChain-compatible tools bound to a user session:
import { createChatTools } from "@indexnetwork/protocol";
const tools = await createChatTools({
userId: "user-uuid",
sessionId: "chat-session-id",
indexId: "optional-index-uuid", // scope tools to a specific index
database,
embedder,
scraper,
cache,
hydeCache,
integration,
intentQueue,
contactService,
chatSession,
enricher,
negotiationDatabase,
integrationImporter,
createUserDatabase,
createSystemDatabase,
});
// tools is an array of LangChain Tool objects ready to bind to an agentFor direct graph invocation (bypassing the tool layer), factory classes are exported for each workflow:
import { ChatGraphFactory, IntentGraphFactory, OpportunityGraphFactory } from "@indexnetwork/protocol";Each factory exposes a .createGraph() method that returns a compiled LangGraph ready for .invoke().
The package exports a factory that registers every chat tool over the Model Context Protocol and attaches a canonical instructions block (MCP_INSTRUCTIONS) that every connecting runtime follows. The factory takes three arguments:
import { createMcpServer, type McpAuthResolver } from "@indexnetwork/protocol";
const authResolver: McpAuthResolver = {
async resolveIdentity(req) {
// Look up the API key in `x-api-key` and return { userId, agentId? }.
// `agentId` should come from Better Auth token metadata so downstream
// tool handlers can attribute every call to a concrete agent identity.
return resolveFromApiKey(req);
},
};
const server = createMcpServer(
deps,
authResolver,
{
// Per-request factory for scoped user/system databases.
create: (userId, indexScope) => createScopedDeps(userId, indexScope),
},
);On every tool call the server:
- Extracts the HTTP request from the MCP
ServerContext. - Calls
authResolver.resolveIdentity(req)to get{ userId, agentId }. - Gates access: MCP callers without a resolved
agentIdare blocked from every tool exceptregister_agent,read_docs, andscrape_urluntil they register. - Builds per-request scoped databases via
scopedDepsFactoryand invokes the tool handler.
The instructions string is the single canonical behavioral contract for every runtime that connects to Index Network — voice, entity model, discovery-first rule, output rules, and the Negotiation turn mode block that tells a silent subagent how to handle a live negotiation turn when its session key is prefixed index:negotiation:. Plugin skills and bootstrap scripts do not redefine this guidance; they defer to whatever ships in MCP_INSTRUCTIONS.
Personal agents participate in bilateral negotiation via a small set of MCP tools:
| Tool | Purpose |
|---|---|
get_negotiation |
Fetch the full turn history and assessment seed for a negotiation |
list_negotiations |
List negotiations awaiting a response from this agent's user |
respond_to_negotiation |
Submit a turn (propose / counter / accept / reject / question) |
Publishing is handled via CI:
# dev pushes publish an rc prerelease
git push <remote> dev
# main pushes publish the stable release if the package version is new
git push <remote> maindev publishes prerelease versions derived from package.json using npm's rc tag, for example 0.4.0-rc.123.1. main publishes the base version from package.json to latest.
Or publish manually from packages/protocol/:
npm publish --access public