from mubit import Client
import os
run_id = "support:acme:ticket-42"
client = Client(
endpoint=os.getenv("MUBIT_ENDPOINT", "https://api.mubit.ai"),
api_key=os.environ["MUBIT_API_KEY"],
run_id=run_id,
transport="http",
)
client.register_agent(
session_id=run_id,
agent_id="support-agent",
role="support",
read_scopes=["fact", "lesson", "rule", "handoff", "feedback"],
write_scopes=["fact", "trace", "lesson", "handoff", "feedback"],
)
client.remember(
session_id=run_id,
agent_id="support-agent",
content="Customer Taylor prefers concise Friday updates and wants billing fixes summarized in one paragraph.",
intent="fact",
metadata={"customer": "taylor", "source": "ticket"},
)
context = client.get_context(
session_id=run_id,
query="Draft the next customer-safe update for Taylor.",
mode="full",
max_token_budget=700,
)
checkpoint = client.checkpoint(
session_id=run_id,
agent_id="support-agent",
label="pre-response-compaction",
context_snapshot=context.get("context_block", ""),
metadata={"stage": "drafting"},
)
archived = client.archive(
session_id=run_id,
agent_id="support-agent",
content="Original billing diff and exact remediation note for ticket-42",
artifact_kind="billing_postmortem",
labels=["billing", "exact"],
)
exact = client.dereference(
session_id=run_id,
reference_id=archived["reference_id"],
)
reflection = client.reflect(session_id=run_id)
lessons = client.control.lessons({"run_id": run_id, "limit": 20})
lesson_id = (lessons.get("lessons") or [{}])[0].get("id")
if lesson_id:
client.record_outcome(
session_id=run_id,
agent_id="support-agent",
reference_id=lesson_id,
outcome="success",
signal=0.8,
rationale="The customer update matched the stored preference and resolved the billing question cleanly.",
)
strategies = client.surface_strategies(
session_id=run_id,
lesson_types=["success", "failure"],
max_strategies=3,
)
print({
"checkpoint_id": checkpoint.get("checkpoint_id"),
"lessons_stored": reflection.get("lessons_stored"),
"strategies": len(strategies.get("strategies", [])),
"exact_reference_found": exact.get("found"),
})