Multi-Agent Scratchpads

Give your AI agents an ephemeral, globally replicated memory state to share context across the network.

LangChain Swarms

In a multi-agent system, agents need a fast, decentralized way to store observations and read what other agents have discovered. SwarmV's edge architecture lets agents read and write context without waiting on a central region.

Search returns the closest records with their stored metadata, so keep each observation's text in its metadata (flat values, up to 8 KB per record). Agents that share a scratchpad write to one container their user can edit, and search with fresh=True so a note is visible the moment it's written.
Python / LangChain
import secrets
from swarmv import SwarmV
from langchain_openai import OpenAIEmbeddings

# Each agent acts as a user via a short-lived token from your backend (see Authentication).
swarmv = SwarmV(token_provider=fetch_swarmv_token)
embeddings = OpenAIEmbeddings()
SCRATCHPAD = "container:team-scratchpad"   # the agents' user must be an editor of it

def agent_write_memory(agent_id: str, observation: str):
    doc_id = str(secrets.randbits(32))       # ids are unsigned 32-bit integers
    swarmv.insert_many([{
        "id": doc_id,
        "vector": embeddings.embed_query(observation),
        "metadata": {"container_id": SCRATCHPAD, "agent_id": agent_id, "text": observation},
    }])

def agent_read_memory(query: str) -> str:
    results = swarmv.search(embeddings.embed_query(query), top_k=5, fresh=True)  # include notes written moments ago
    context = "\n".join(f"[{r.metadata['agent_id']}] {r.metadata['text']}" for r in results if r.metadata)
    return f"Relevant memories from other agents:\n{context}"

Google Gemini Agent Handoffs

Pass context between Gemini models using the edge swarm.

Python / Google Gemini
import google.generativeai as genai
from swarmv import SwarmV

swarmv = SwarmV(token_provider=fetch_swarmv_token)
EMBED = "models/text-embedding-004"

# 1. First agent writes context to the swarm
observation = "User prefers concise answers and Python code snippets."
vector = genai.embed_content(model=EMBED, content=observation)["embedding"]
swarmv.insert_many([{"id": "7001", "vector": vector,
                     "metadata": {"container_id": "container:team-scratchpad", "text": observation}}])

# 2. A second agent running elsewhere retrieves it, even straight away
query = genai.embed_content(model=EMBED, content="What are the user's preferences?")["embedding"]
best = swarmv.search(query, top_k=1, fresh=True)[0]  # sees the note immediately
context = best.metadata["text"]

model = genai.GenerativeModel("gemini-1.5-pro")
response = model.generate_content(f"Context: {context}\nTask: Answer the user's question.")