Skip to main content

Agent context

POST /api/v2/containers/{container_tag}/agent/context

Agent context is the pre-turn path. It returns a compact, scoped memory packet for an agent before it answers. Use it when you are building an integration and want UnifiedMemory to decide which memories are safe and useful for the next prompt.

Auth

Send a scoped agent key:

Authorization: Bearer $UNIFIED_MEMORY_API_KEY

The key decides the effective agent identity. If the request body tries to pretend to be another agent, the server should ignore or downgrade that value and expose the diagnostic fields.

Path parameters

NameRequiredDescription
container_tagYesMemory container. The default first-party container is jeethendra.

Request fields

FieldRequiredTypeDefaultDescription
user_messageYesstringThe current user message or task.
agent_idNostringkey metadataCompatibility field. Key metadata remains authoritative.
app_idNostringkey metadataClient app identifier.
run_idNostringCurrent run/session identifier.
source_appNostringkey metadataCaller surface such as codex, claude, or hermes.
limitNointeger8Maximum memories to include before budget trimming.
max_context_tokensNointeger1200Target token budget for the context block.
trust_policyNostringbalancedRecall trust mode. Use stricter policies for prompt injection.
include_courtroom_linksNobooleantrueInclude Courtroom URLs where available.
metadataNoobject{}Integration-specific diagnostics.

Schema from OpenAPI

This section is generated from /openapi.public.json. Edit the OpenAPI source or generator, not this block.

POST /api/v2/containers/{container_tag}/agent/context

  • Operation ID: agent_memory_context_api_v2_containers__container_tag__agent_context_post
  • Declared response statuses: 200, 422

Request schema

Schema: AgentContextRequest

FieldRequiredTypeNullableDefaultConstraints
agent_idNostringYes--
app_idNostringYes--
context_tagsNoarray of stringYes--
context_typesNoarray of stringYes--
limitNointegerNo8minimum=1.0, maximum=50.0
max_context_tokensNointegerNo1200minimum=128.0, maximum=8000.0
memory_planeNostringYes--
memory_scopeNostringYes--
org_idNostringYes--
request_idNostringYes--
run_idNostringYes--
session_idNostringYes--
tagsNoarray of stringYes--
task_goalNostringYes-maxLength=8000
thresholdNonumberNo0.0minimum=0.0, maximum=1.0
trust_policyNostringNo"balanced"-
user_idNostringYes--
user_messageYesstringNo-minLength=1, maxLength=20000

200 response schema

Schema: AgentContextResponse

FieldRequiredTypeNullableDefaultConstraints
citationsNoarray of objectNo--
container_tagYesstringNo--
diagnosticsNoobjectNo--
needs_confirmationNoarray of objectNo--
prompt_memory_blockNostringNo""-
queryYesstringNo--
suppressedNoarray of objectNo--
trust_policyYesstringNo--
trusted_contextNoarray of objectNo--

Example

curl https://edge-api.jithendranara.dev/api/v2/containers/jeethendra/agent/context \
-H "Authorization: Bearer $UNIFIED_MEMORY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"user_message": "What should I remember before editing the docs?",
"source_app": "codex",
"run_id": "docs-depth-repair",
"limit": 6,
"max_context_tokens": 900
}'

Response shape

{
"container_tag": "jeethendra",
"context": "Relevant memory:\n- Docs are hosted at docs.jithendranara.dev...",
"memories": [
{
"id": "mem_docs_surface",
"content": "Hosted docs are a first-class product surface.",
"trust_bucket": "trusted",
"source": "codex",
"courtroom_url": "/memories?view=courtroom&case=mem_docs_surface"
}
],
"tokens_injected": 82,
"suppressed_count": 4,
"trust_policy": "balanced",
"effective_agent_id": "codex",
"effective_source_app": "codex",
"caller_agent_id_dropped": false
}

Fields may include additional diagnostics such as cross_agent_candidates_suppressed, scope_filter_stage_counts, algorithm_version, and why_recalled.

Common outcomes

StatusMeaning
200Context assembled. The memories array may be empty if no safe memory exists.
401Missing or invalid key.
403Key lacks agent.context or container access.
404Container not found or not visible to the key.
422Request validation failed, usually missing user_message.
200 degradedContext returned with a fallback path; inspect algorithm_fallback_reason if present.

Next steps

  • Save useful post-turn outcomes with Writeback.
  • Inspect why a memory appeared with Courtroom.