observe-and-enrich, how to put its result into your prompt, and how to store your model’s reply.
The loop for each user message is:
- Send the message to
observe-and-enrich. - Put the returned memory text into your prompt.
- Ask your model.
- Show the reply.
Before you start
Create an agent and a thread, as in walkthrough 1. Use one agent per customer: memory is shared across an agent, so two people on one agent can be answered from each other’s facts.Step 1: send the message and receive the memory text
200.
response_contextis memory text, not an answer. It is written for a model to read.used_memory_idstells you which memories were used. Write them to your logs if you audit answers.preferenceis empty today. It is reserved for learned user preferences.
detail chooses how much memory text you receive. Send brief when your model needs only the key facts, and detailed when it writes a long answer, such as a report or a full history. max_context_chars is different: it is a hard cut that trims the text, so set it only to protect a small context window. See Answer length.
If it fails:
429 rate_limit_exceeded: more than 20 calls in one minute, or 2 answers already running. WaitRetry-Afterseconds.503 answer_model_unavailable: wait, then send the request again. Or answer without memory this one time.
Step 2: build your prompt
Step 3: decide whether to store the reply
Priors learned the user’s message in step 1. It did not see your model’s reply. If future answers must know what your model said, send the reply withobserve:
speaker, so that the agent knows who said it.
When the agent knows nothing yet
response_context is empty. Your model answers from the message alone. This is normal for a new user. Nothing failed.
How often you can call
Eachobserve-and-enrich call searches the memory and writes the memory text. For one account, two calls can run at the same time, and 20 calls can start per minute. If your product sends one user message to several model calls, call Priors once and use the same memory text for all of them.