> ## Documentation Index
> Fetch the complete documentation index at: https://www.sapientpriors.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 2. Bring your own model

> Use observe-and-enrich to give a language model that you already run a memory of your users.

This walkthrough is for a product that already has a language model. Priors supplies the memory. Your model writes the answer. After you read it, you know how to call `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:

1. Send the message to `observe-and-enrich`.
2. Put the returned memory text into your prompt.
3. Ask your model.
4. Show the reply.

Every user message is also learned in step 1.

## Before you start

Create an agent and a thread, as in [walkthrough 1](/docs/walkthroughs/first-conversation). 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

```bash theme={null}
curl -X POST https://app.sapientpriors.com/api/v1/agents/agent_01J.../threads/thread_01J.../observe-and-enrich \
  -H "Authorization: Bearer $SP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "observations": [{"content": [{"type": "text", "text": "Can you book the same hotel as last time?"}], "speaker": "Ada"}],
    "detail": "standard",
    "max_context_chars": 2000
  }'
```

**Success:** status `200`.

```json theme={null}
{
  "response_context": "Last trip the user stayed at the Grand Marina in Lisbon and asked for a quiet room on a high floor.",
  "preference": "",
  "in_context_memory_ids": ["mem_01J...", "mem_01J...", "mem_01J..."],
  "used_memory_ids": ["mem_01J...", "mem_01J..."],
  "in_context_source_ids": [],
  "used_source_ids": []
}
```

* `response_context` is memory text, not an answer. It is written for a model to read.
* `used_memory_ids` tells you which memories were used. Write them to your logs if you audit answers.
* `preference` is 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](/docs/concepts/answering#answer-length-detail).

**If it fails:**

* `429 rate_limit_exceeded`: more than 20 calls in one minute, or 2 answers already running. Wait `Retry-After` seconds.
* `503 answer_model_unavailable`: wait, then send the request again. Or answer without memory this one time.

## Step 2: build your prompt

```python theme={null}
system = (
    "You are a travel assistant. Use the memory below when it relates to the question. "
    "If the memory does not answer the question, say so.\n\n"
    f"Memory:\n{context['response_context']}"
)
reply = your_model.complete(system=system, user=user_message)
```

Put the memory text into the system prompt, not into the user message. Tell your model what the memory is and what to do when the memory is empty.

## 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 with `observe`:

```bash theme={null}
curl -X POST .../observe \
  -H "Authorization: Bearer $SP_API_KEY" \
  -d '{
    "observations": [
      {
        "content": [{"type": "text", "text": "I booked the Grand Marina, high floor, for 12 to 15 October."}],
        "speaker": "Travel assistant"
      }
    ]
  }'
```

Set `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

Each `observe-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.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.