Skip to main content
Add persistent, cross-session memory to a Vercel eve agent. eve is a filesystem-first framework for durable backend agents: you author an agent as files under agent/. This integration adds four of those: memory tools the model can call, stream hooks that report each run to Synap, an instructions resolver that injects Synap’s short-term context into every turn, and a compaction model that makes Synap’s compaction eve’s checkpoint.
eve’s own durability (Vercel Workflows) persists a single session’s turn state so it survives crashes and redeploys; that is short-term session state, not cross-session memory. Synap is the durable, cross-session layer on top. Tested against [email protected] (AI SDK v7); eve is in beta, so pin your version.
@maximem/synap-eve uses the JavaScript SDK and needs Node.js 20+. Use 0.1.4 or later. eve deploys to Vercel Functions, which satisfies that. The gRPC stream opens only on Node.js; where it cannot open, turns go over REST. See Installation → JavaScript and TypeScript SDK.

Overview

This guide shows how to add Synap to an eve agent so it can:
  • Recall long-term memory and store facts on demand, via tools the model chooses to call
  • Report each run (the user’s message, the reply, tool calls and results, reasoning) so Synap can anticipate the next turn and compact the conversation
  • Automatically inject Synap’s compacted short-term context into the system prompt every turn
  • Hand eve’s own compaction call to Synap’s compaction
  • Scope memory per user without the model ever seeing the identity
The integration ships four factories. Three are the default export of a file under agent/; the fourth is used inside agent.ts: The filename under agent/tools/ becomes the model-facing tool name. The instructions resolver augments instructions.md: it adds a system message, it never replaces your prompt.

Setup

Install the package alongside eve:
Import the integration from its package name directly: import { createSynapSearchTool } from "@maximem/synap-eve". The core SDK (SynapClient) comes from the separate @maximem/synap-js-sdk package.
Configure your API key. Generate one from the Synap Dashboard.
.env
Initialize the SDK once and export it so your agent/ files can share it:
agent/lib/synap.ts
See SDK Initialization for the full lifecycle and configuration options.

Basic integration

The smallest useful integration is a single search tool. Drop this file in and the model can pull long-term context whenever it decides it needs it:
agent/tools/synap_search.ts
Identity is resolved automatically from the eve session: the Synap user_id comes from ctx.session.auth.current.principalId and the conversation_id from ctx.session.id. On an authenticated channel that is all you need; the model never sees the user identity, and reads degrade gracefully (empty result on failure, so a recall miss never aborts the turn). Add the stream hooks below so Synap sees the conversation itself: without them nothing is recorded and no stream opens, because the tools only read and write on the model’s request. To also inject short-term context on every turn without the model asking, add the instructions resolver.

Core concepts

Memory tools

Both tool factories return branded eve ToolDefinitions. Search reads; store writes:
agent/tools/synap_store.ts
synap_search input: { query: string, maxResults?: number }. synap_store input: { content: string, metadata?: Record<string, unknown> }. Error policy follows the Synap-wide contract:
  • synap_search degrades gracefully: returns { available: false } and logs on failure.
  • synap_store surfaces failures: raises SynapIntegrationError, so the model sees that an ingestion outage happened rather than assuming the write succeeded.

Stream hooks

createSynapStreamHooks returns an eve hook that subscribes to the run’s own events and reports them to Synap:
agent/hooks/synap.ts
The first event opens the gRPC stream for you; you do not call listen(). The user and assistant turns always get to Synap: on the stream when it is open, and over REST through sdk.conversation.record_message when it cannot carry them, never both. Tool calls, tool results, reasoning and the session end exist only on the stream. The open waits up to 10 seconds; after a failure it tries once more a few seconds later, then no more than once a minute. The hook never throws into eve’s run. A stream your own code opened with sdk.instance.listen() is used as is. To keep the integration on REST, set SYNAP_AUTO_LISTEN=false, or turn it off for one SDK:
agent/lib/synap.ts
An open stream does not keep a Node.js process alive: a script exits when its work is done. This applies only to the connection to Synap, at the address in SYNAP_GRPC_HOST and SYNAP_GRPC_PORT or the default; other HTTP/2 connections in your process behave as before. Options, besides sdk: If a turn has no resolvable user or conversation id (an unauthenticated channel with no userId option), the hook reports nothing for it.

Short-term context resolver

createSynapInstructions returns a defineDynamic resolver that runs at the start of every turn, fetches Synap’s compacted short-term summary for the conversation, and lowers it to one extra system message:
agent/instructions/synap.ts
It augments your agent/instructions.md; it never replaces it. The message holds Synap’s compaction block only, not the recent turns, which eve already sends. When Synap has not compacted the conversation yet (or on an SDK failure with the default onError: "fallback") the resolver returns null, which eve treats as “contribute nothing,” and the turn proceeds unchanged.

Compaction model

eve compacts its own history when it grows past compaction.thresholdPercent of the model’s context window, by calling a model to summarize the older turns and storing the result as a checkpoint. createSynapCompactionModel wraps the model you give it so that this one call is answered with Synap’s compaction instead. Every other call goes to your model unchanged.
agent/agent.ts
Set the wrapper as the agent’s model, and leave compaction.model unset. eve compacts with the agent’s own model, so a model placed in compaction.model is never called. Three things to know:
  • eve decides when to compact. Until it does, the model sees eve’s own history; lower thresholdPercent to hand over to Synap sooner.
  • The compaction call carries no eve session id, so name the Synap conversation here. Pass the same conversationId you give the hooks and the resolver, or a function that returns it.
  • When Synap has no compaction for the conversation, or cannot be reached, the call goes to your model and eve’s own summary is used.

Identity and scoping

The tools, the hooks and the resolver accept the standard scoping options, which override the session-derived defaults (the resolver and the compaction model take only conversationId): The integration deliberately does not fall back to the session initiator: on a delegated or system-initiated session that is whoever started it (an admin or service), not the end user the turn acts for; using it would scope memory to the wrong principal.

Complete example: memory-augmented agent

A complete agent that reports every run, has always-on short-term recall, AND lets the model search/store explicitly is a few files:
agent/agent.ts
agent/instructions.md
agent/instructions/synap.ts
agent/hooks/synap.ts
Run it locally and start a session with your usual eve client:
Three things to notice:
  1. The hooks, the resolver and the tools are complementary. The hooks report the run, createSynapInstructions sets the always-on baseline; the tools handle the explicit “I should look this up / bookmark this” path.
  2. Scope is derived per turn from the eve session: no per-request agent construction needed on authenticated channels.
  3. The instructions are the policy. Telling the model when to call synap_search / synap_store is what produces the explicit-memory behavior.

Advanced patterns

Unauthenticated channels

If a channel does not authenticate the caller (ctx.session.auth.current is null), the session-derived user_id is unavailable. Pass an explicit userId (and customerId for B2B) into the factories, including the hooks, which report nothing without one:
agent/tools/synap_search.ts

Latency vs. comprehensiveness

synap_search accepts mode:

Failure semantics

  • Reads (synap_search, the instructions resolver) degrade gracefully: empty result / null, logged.
  • The stream hooks and the compaction model never throw: a failed write is dropped and the run goes on; the compaction model falls back to your model.
  • synap_store surfaces failures: raises SynapIntegrationError, so the model sees the write failed.
Read failures shouldn’t break a user-facing turn. An explicit store is different: the model asked for it, so a failure is reported back to it.

Going further


Next steps

Vercel AI SDK

Model middleware for the Vercel AI SDK: the layer below eve.

Mastra

SynapMemory class and tools for Mastra.

Context Fetch

The retrieval API behind synap_search.

Memory Scopes

How userId, customerId, and conversationId interact across reads.