Letta (MemGPT) Integration
THSP safety validation for Letta agents with persistent memory.
Letta (formerly MemGPT) is a platform for building stateful AI agents with self-editing memory. This integration adds safety validation at message input, tool execution, and memory operations.Installation
pip install letta-client sentinelseed
Quick Start
Method 1: Wrapped Client
from letta_client import Letta
from sentinelseed.integrations.letta import SentinelLettaClient
base = Letta(api_key="your-letta-key")
client = SentinelLettaClient(
base,
api_key="your-openai-key",
mode="block", # block, flag, log
)
agent = client.agents.create(
model="openai/gpt-4o-mini",
memory_blocks=[
{"label": "human", "value": "User info"},
{"label": "persona", "value": "AI assistant"},
],
)
response = client.agents.messages(agent.id).create(
input="Hello, how are you?"
)
Method 2: Safety Tool
from letta_client import Letta
from sentinelseed.integrations.letta import create_sentinel_tool
client = Letta(api_key="your-key")
tool = create_sentinel_tool(
client,
api_key="your-openai-key",
require_approval=True,
)
agent = client.agents.create(
model="openai/gpt-4o-mini",
tools=[tool.name],
memory_blocks=[...],
)
Method 3: Safe Agent Factory
from sentinelseed.integrations.letta import create_safe_agent
agent = create_safe_agent(
client,
validator_api_key="your-openai-key",
model="openai/gpt-4o-mini",
memory_blocks=[...],
include_safety_tool=True,
high_risk_tools=["web_search", "run_code"],
)
Features
Message Validation
- Input validation: Check user messages before processing
- Output validation: Check agent responses before returning
- Configurable modes: block, flag, or log
Memory Integrity
from sentinelseed.integrations.letta import create_memory_guard_tool
guard = create_memory_guard_tool(
client,
secret="your-hmac-secret",
)
Memory Content Validation (v2.0)
Validates content BEFORE HMAC signing, detecting injection attacks at the source.
Detected Patterns:| Category | Examples |
|---|---|
| Authority Claims | "ADMIN:", "SYSTEM NOTICE:" |
| Instruction Overrides | "Ignore previous instructions" |
| Address Redirection | Suspicious wallet changes |
| Urgency Manipulation | "URGENT: action required" |
Approval Handler
from sentinelseed.integrations.letta import sentinel_approval_handler
decision = sentinel_approval_handler(
approval_request={
"tool_name": "run_code",
"arguments": {"code": "print('hello')"},
},
api_key="your-openai-key",
auto_approve_safe=True,
auto_deny_unsafe=True,
)
THSP Gates
| Gate | Purpose |
|---|---|
| Truth | Factually accurate? |
| Harm | Could cause harm? |
| Scope | Within boundaries? |
| Purpose | Legitimate benefit? |