Skip to content
This repository was archived by the owner on May 5, 2026. It is now read-only.
This repository was archived by the owner on May 5, 2026. It is now read-only.

Backend: Agent-scoped checkpoints via checkpoint_ns (agentId) + agentId-aware filters and socket init #9

Description

@noa-lucent

Context
Multiple agent instances write to the same collection and are only filtered by thread_id, causing collisions when agents share a thread.

Interface clarification

  • Socket (and CheckpointerService filters) use { agentId?, threadId? }.
  • Internally, agentId maps 1:1 to checkpoint_ns and should equal the runtime node id.

Correct approach (no saver namespace)

  • @langchain/langgraph-checkpoint-mongodb MongoDBSaver does not take a namespace option. The correct way to scope writes is to set configurable.checkpoint_ns in the RunnableConfig passed to LangGraph.

Tasks

  1. Pass checkpoint_ns (agentId) in RunnableConfig
  • apps/server/src/agents/simple.agent.ts
    • Update SimpleAgent to accept agentId in constructor.
    • In init(), set default _config to include configurable: { checkpoint_ns: agentId } while preserving recursionLimit.
    • BaseAgent.invoke already merges thread_id each call, so checkpoint_ns remains set.
  1. agentId-aware filtering in DB layer
  • apps/server/src/services/checkpointer.service.ts
    • Add checkpointNs?: string to CheckpointWriteNormalized; map from raw.checkpoint_ns.
    • fetchLatestWrites({ threadId?, agentId? }, limit): apply both fields (agentId -> checkpoint_ns) to Mongo filter.
    • watchInserts({ threadId?, agentId? }): add to $match as fullDocument.checkpoint_ns.
  1. Wire agentId from template registry
  • apps/server/src/templates.ts: simpleAgent factory uses ctx.nodeId as agentId and passes it to constructor.
  1. Socket init supports agentId
  • apps/server/src/services/socket.service.ts
    • Extend InitPayload with agentId?: string and threadId?: string; pass through to checkpointer with mapping agentId -> checkpoint_ns.

Acceptance Criteria

  • Two agents produce checkpoint_writes with distinct checkpoint_ns (matching agentId/nodeId) without modifying MongoDBSaver constructor.
  • fetch/watch with agentId filter returns only matching writes.
  • Socket init with agentId streams only that agent’s writes; no regression when agentId omitted.

Relationships

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions