Priostack
LangChain ยท shared memory & context

LangChain agents with persistent, shared memory.

Two tools give a LangChain agent memory that survives the run and can be shared with other agents: one to save a fact, one to recall by topic, both backed by a Priostack space through the Python SDK.

Install: pip install priostackTools: save_memory, recall_memoryWiring: any tool-calling agent
01

Define the two tools

The ACN calls are the load-bearing part: store persists a typed object, fetch reads back what matches a topic. Wrap them with @tool and hand them to any tool-calling agent.

python
from langchain_core.tools import tool
from priostack import ACNClient

acn = ACNClient(); acn.register(display_name="langchain-agent"); acn.connect()
SPACE_ID = acn.create_space("langchain-memory").space_id

@tool
def save_memory(fact: str) -> str:
    """Persist an important fact or user preference for future sessions."""
    acn.store(SPACE_ID, objects=[{"content": fact, "type": "declaration"}])
    return f"Stored in Priostack ACN: {fact!r}"

@tool
def recall_memory(topic: str) -> str:
    """Recall previously stored facts related to a topic (substring match)."""
    hits = acn.fetch(SPACE_ID, query=topic, limit=5)
    return "\n".join(f"- {c}" for c in hits.contents()) or "No matching memory found."
02

Wire them into an agent

Bind the tools to your model of choice with create_tool_calling_agent and an AgentExecutor; the runnable example in the SDK repository uses ChatAnthropic. The agent wiring tracks LangChain's current API; the memory calls do not change.

i

Persist the token and the space id (for example in your settings) and reconnect on the next run instead of registering again.

03

One memory for several agents

Because the memory is a space on the network, a second LangChain agent, a CrewAI crew or a Claude agent can read it under a grant, and the owner keeps the receipts.

python
# owner: share one space with another agent (its agent id from register)
grant = owner.grant_access(space.space_id, worker_agent_id, rights=["read", "quote"])

# the grantee reconnects to pick up the widened scope, then reads
worker.connect()
print(worker.fetch(space.space_id, query="refund").contents())

# immediate, forward-only
owner.revoke_access(grant.capability_ref)
04

Questions people ask

Is this a LangChain Memory class?
It is two tools over a durable, permissioned store, which works with tool-calling agents regardless of memory-class API changes in LangChain.

How is recall matched?
fetch filters stored objects with a case-insensitive substring; store what you want to find again as short, typed facts.

Where is the full example?
examples/langchain_memory.py in the SDK repository, runnable with an Anthropic key or in tool-only mode without one.