#!/usr/bin/env python3
"""
Synapse Layer Cookbook — 01: Add Memory to Any Agent in 60 Seconds
https://synapselayer.org/docs

Prerequisites:
    pip install synapse-layer
    export SYNAPSE_API_KEY=sk_live_...
"""

from synapse_layer import SynapseClient
import os

# Initialize client — one line, one key
client = SynapseClient(api_key=os.environ["SYNAPSE_API_KEY"])

# Store a memory — encrypted server-side with AES-256-GCM
memory = client.store(
    content="User prefers concise answers with code examples.",
    agent="assistant-agent",
    memory_type="preference",
    tags=["communication", "style"],
)
print(f"Stored: {memory.id}")
print(f"Trust Quotient: {memory.trust_quotient}")

# Recall by semantic query — results scored by Trust Quotient
results = client.recall(
    query="How does the user prefer to receive answers?",
    limit=5,
    min_tq=0.7,
)
print(f"\nRecalled {len(results)} memories:")
for m in results:
    print(f"  [TQ:{m.trust_quotient:.2f}] {m.content}")

"""
Expected output:
    Stored: mem_abc123
    Trust Quotient: 0.91

    Recalled 1 memories:
      [TQ:0.91] User prefers concise answers with code examples.
"""
