Wire CortexDB recall and capture into NVIDIA NeMo Guardrails as registered actions.
NeMo Guardrails Integration
NeMo Guardrails uses Colang flows to constrain LLM behavior. Register CortexDB as custom actions so flows can recall context and capture audit-relevant turns.
Install
pip install cortexdbai nemoguardrails
Register custom actions
# config/actions.py
import os
from datetime import datetime, timezone
from uuid import uuid4
from nemoguardrails.actions import action
from cortexdb.v1 import V1Client
client = V1Client(api_url="https://api-v1.cortexdb.ai", actor="user:alice",
bearer=os.environ["CORTEX_TOKEN"])
SCOPE = "org:acme/user:alice"
@action()
async def cortex_recall(query: str) -> str:
pack = client.recall(scope=SCOPE, view="holistic", query=query,
include=["beliefs", "facts", "episodes"],
budgets={"max_tokens": 3000})
return pack["context_block"] or ""
@action()
async def cortex_capture(text: str, role: str = "user") -> bool:
client.experience(scope=SCOPE, text=text, role=role,
observed_at=datetime.now(timezone.utc).isoformat(),
idempotency_key=f"nemo-{role}-{uuid4()}")
return True
# config/rails.co
define flow recall_and_answer
user said something
$context = execute cortex_recall(query=$user_message)
bot $context # prepend to system
execute cortex_capture(text=$user_message, role="user")
The forget surface (/v1/forget, /v1/erasures) is useful when guardrails detect a violation — call client.forget(...) from a block_message flow to drop the offending turn from derived layers.