Using CoreTex In An Agent

The normal agent lifecycle is:

before model call:  prefetch(query) -> inject rendered cited context
after model call:   sync_turn(user turn, assistant reply, tools, documents)
session boundary:   flush_session() -> M3 boundary + durable checkpoint
periodically:       synchronize and atomically activate newer canonical state

A minimal Python integration is:

from coretex_memory.envelope import Scope
from coretex_memory_agent import AgentMemory, CompositionRouter
from coretex_memory_agent.adapters.openai import OpenAIMemoryAdapter

scope = Scope(
    tenant="example",
    user="alice",
    agent="assistant",
    profile="conv.pref.v1",
)

# The production activator supplies verified profile release directories.
# This local example uses the bundled reference path for one profile.
router = CompositionRouter(
    {"conv.pref.v1": None},
    composition={"conv.pref.v1": None},
)

memory = AgentMemory.open(
    "./coretex-memory.db",
    scope=scope,
    profile="conv.pref.v1",
    router=router,
)

adapter = OpenAIMemoryAdapter(memory, model="your-model")
request = adapter.build_request(
    "What deployment window did we agree on?",
    budget=300,
)

# response_text = your_openai_client.chat.completions.create(**request)
response_text = "We agreed on Friday."

adapter.sync_response(
    "What deployment window did we agree on?",
    response_text,
)
memory.flush_session("./session.checkpoint")
memory.close()

Equivalent Anthropic request construction is available through AnthropicMemoryAdapter. Applications may instead call AgentMemory directly:

  • prefetch(query, budget, as_of=None) returns cited, budget-bounded context;
  • sync_turn(...) ingests messages, tool calls, tool results, and documents;
  • flush_session() runs the session-end M3 boundary and checkpoints;
  • health() reports store and active-release health; and
  • capabilities() reports the active hooks and consolidation policy.

Always inject the authoritative rendered context returned by prefetch. Preserve citations through accounting, send only raw events into sync_turn, and assign separate scopes to unrelated users.

Non-Python applications can use the packaged localhost sidecar or wrap the same five operations in their own process boundary. The sidecar remains bound to localhost as a private integration seam.