diff --git a/pyproject.toml b/pyproject.toml index 0fdff3d..0168830 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ dependencies = [ "atproto", "python-dotenv", "PyYAML", + "requests", ] [project.scripts] diff --git a/src/void_tools/cli.py b/src/void_tools/cli.py index 7f906d3..1373e05 100644 --- a/src/void_tools/cli.py +++ b/src/void_tools/cli.py @@ -7,9 +7,39 @@ import os import json import yaml import hashlib +import requests from atproto import models from void_tools.client import get_client +def mirror_to_letta(text, target_uri): + """Mirrors an annotation to Letta archival memory.""" + agent_id = os.getenv("AGENT_ID") + api_key = os.getenv("LETTA_API_KEY") + + if not agent_id or not api_key: + print(" Skipping Letta sync: AGENT_ID or LETTA_API_KEY missing from .env") + return + + try: + url = f"https://api.letta.com/v1/agents/{agent_id}/archival-memory" + headers = { + "Authorization": f"Bearer {api_key}", + "Content-Type": "application/json" + } + payload = { + "text": f"Margin Annotation attached to {target_uri}: {text}" + } + + # We need to handle Letta's expected JSON payload which might require a specific format. + # The standard endpoint takes {"text": "string"} + resp = requests.post(url, headers=headers, json=payload) + if resp.ok: + print(" Mirrored annotation to Letta archival memory.") + else: + print(f" Warning: Failed to mirror to Letta: {resp.status_code} - {resp.text}") + except Exception as e: + print(f" Warning: Failed to mirror to Letta: {e}") + def cmd_sync(args): client = get_client() agent_id = os.getenv("AGENT_ID", "agent-c52e371d-cb89-4f99-8634-b606bdc69cad") @@ -251,6 +281,8 @@ def cmd_dispatch(args): 'record': record }) print(f" Annotated: {resp.uri}") + # Mirror to internal memory + mirror_to_letta(text, target_uri) except Exception as e: print(f"Error annotating {target_uri}: {e}") @@ -432,6 +464,8 @@ def cmd_annotate(args): 'record': record }) print(f"Successfully annotated: {resp.uri}") + # Mirror to internal memory + mirror_to_letta(args.text, target_uri) except Exception as e: print(f"Error annotating {target_uri}: {e}", file=sys.stderr) sys.exit(1)