Retrieve relevant evidence, pack it within a token budget, and get a decision receipt
The core endpoint. Given a query and token budget, retrieve relevant evidence, pack it optimally, enforce policy, and return ready-to-inject prompt text plus a full audit receipt.
pack = client.context_pack( query="What is the current enterprise discount cap for Q2?", workspace_id="ws_acme", max_tokens=2048, actor_id="user_alice",)if pack["abstain_flag"]: print(f"Cannot answer: {pack['abstain_reason']}")else: # Inject into your LLM print(pack["context_text"]) print(f"Confidence: {pack['confidence']:.0%}") print(f"Tokens used: {pack['total_tokens']}")
Response
{ "context_text": "=== PINNED CONTEXT (Authoritative) ===\n[cite:1] The Q2 enterprise discount cap has been raised to 18%.\n\n=== TOP EVIDENCE (Most Relevant to Query) ===\n[cite:2] Enterprise pricing guidelines updated for Q2...\n\n=== END CONTEXT ===", "prefix_text": "=== PINNED CONTEXT (Authoritative) ===\n[cite:1] ...", "working_set_text": "=== TOP EVIDENCE ===\n[cite:2] ...", "citations": [ { "artifact_id": "a1b2c3d4-...", "span_id": "s1e2f3g4-...", "start_offset": 0, "end_offset": 56, "content_hash": "sha256:...", "source_type": "chat_turn", "relevance_score": 0.94, "content_preview": "The Q2 enterprise discount cap has been raised to 18%." } ], "confidence": 0.87, "abstain_flag": false, "abstain_reason": null, "receipt_id": "r1a2b3c4-...", "total_tokens": 347, "pack_hash": "sha256:..."}
Always check abstain_flag before using context_text. When the system determines it cannot provide reliable evidence, it sets abstain_flag: true. Your agent should decline to answer rather than use low-quality context.
Abstention triggers when evidence quality or quantity is too low to provide a reliable answer. See Confidence and Abstention for details.
Memory Runtime is fully deterministic. Given the same query against the same data, it produces byte-identical output — same evidence, same order, same token count, same pack_hash. You can verify this by comparing pack_hash values across runs.