Anthropic Integration
Wire Synapse into a Claude agent loop. Load relevant memories before each call. Save the exchange after. Your agent remembers across sessions with zero extra LLM calls.
Install
pip install anthropic requestsAgent loop with persistent memory
This pattern: load context → build system prompt → call Claude → save exchange. Synapse handles storage and retrieval; Claude handles reasoning.
import anthropic
import requests
SYNAPSE_KEY = "sk_syn_your_key_here"
SYNAPSE_URL = "https://synapse.by-kit.com/api/v1"
AGENT_ID = "claude-assistant"
client = anthropic.Anthropic(api_key="sk-ant-...")
def synapse_write(title: str, body: str, memory_type: str = "exchange"):
"""Write a memory to Synapse."""
requests.post(
f"{SYNAPSE_URL}/record",
headers={"Authorization": f"Bearer {SYNAPSE_KEY}"},
json={
"agent_id": AGENT_ID,
"type": memory_type,
"title": title,
"body": body
}
)
def synapse_query(query: str, limit: int = 5) -> str:
"""Retrieve relevant memories from Synapse."""
resp = requests.get(
f"{SYNAPSE_URL}/query",
headers={"Authorization": f"Bearer {SYNAPSE_KEY}"},
params={"q": query, "agent_id": AGENT_ID, "limit": limit}
)
memories = resp.json() if resp.ok else []
if not memories:
return "No relevant context found."
return "\n".join(
f"[{m['type']}] {m['title']}: {m['body']}"
for m in memories
)
def chat(user_message: str) -> str:
# Load relevant memories before calling Claude
context = synapse_query(user_message)
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
system=f"""You are a helpful assistant with persistent memory.
Relevant context from previous sessions:
{context}
Use this context to give informed, consistent answers.""",
messages=[{"role": "user", "content": user_message}]
)
reply = response.content[0].text
# Save the exchange after getting Claude's response
synapse_write(
title=f"Q: {user_message[:80]}",
body=f"User: {user_message}\nAssistant: {reply}",
memory_type="exchange"
)
return reply
# Usage
if __name__ == "__main__":
print(chat("What did we decide about the database architecture?"))
print(chat("Remind me — which pricing tier is most popular?"))Tips
- Keep context injection under 2,000 tokens — pull the 5 most relevant records, not everything.
- Use
type="decision"writes for anything Claude decides — critical for long-running agents. - Use
type="open_item"for unresolved tasks so they surface in future sessions. - Query with
type=open_itemat the start of every session to resume open work.