This commit renames the terminology across the entire codebase: - "mental models" (fact_type='mental_model' in memory_units) → "observations" - "reflections" table (stored reflect responses) → "mental_models" Changes include: - Database migration to rename tables, indexes, and constraints - API endpoints: /reflections → /mental-models, /mental-models → /observations - Config: ENABLE_MENTAL_MODELS → ENABLE_OBSERVATIONS - Response models and Pydantic classes - Reflect agent tools and prompts - Control plane UI and routes - Documentation and examples - Regenerated OpenAPI spec and client SDKs (Python, TypeScript) - Rust CLI: reflection commands → mental-model commands - LiteLLM: updated fact_types documentation
214 lines
5.8 KiB
Text
214 lines
5.8 KiB
Text
---
|
|
sidebar_position: 4
|
|
---
|
|
|
|
# Mental Models
|
|
|
|
User-curated summaries that provide high-quality, pre-computed answers for common queries.
|
|
|
|
import Tabs from '@theme/Tabs';
|
|
import TabItem from '@theme/TabItem';
|
|
import CodeSnippet from '@site/src/components/CodeSnippet';
|
|
|
|
{/* Import raw source files */}
|
|
import mentalModelsPy from '!!raw-loader!@site/examples/api/mental-models.py';
|
|
|
|
## What Are Mental Models?
|
|
|
|
Mental models are **saved reflect responses** that you curate for your memory bank. When you create a mental model, Hindsight runs a reflect operation with your source query and stores the result. During future reflect calls, these pre-computed summaries are checked first — providing faster, more consistent answers.
|
|
|
|
```mermaid
|
|
graph LR
|
|
A[Create Mental Model] --> B[Run Reflect]
|
|
B --> C[Store Result]
|
|
C --> D[Future Queries]
|
|
D --> E{Match Found?}
|
|
E -->|Yes| F[Return Mental Model]
|
|
E -->|No| G[Run Full Reflect]
|
|
```
|
|
|
|
### Why Use Mental Models?
|
|
|
|
| Benefit | Description |
|
|
|---------|-------------|
|
|
| **Consistency** | Same answer every time for common questions |
|
|
| **Speed** | Pre-computed responses are returned instantly |
|
|
| **Quality** | Manually curated summaries you've reviewed |
|
|
| **Control** | Define exactly how key topics should be answered |
|
|
|
|
### Hierarchical Retrieval
|
|
|
|
During reflect, the agent checks sources in priority order:
|
|
|
|
1. **Mental Models** — User-curated summaries (highest priority)
|
|
2. **Observations** — Consolidated knowledge
|
|
3. **Raw Facts** — Ground truth memories
|
|
|
|
Mental models are checked first because they represent your explicitly curated knowledge.
|
|
|
|
---
|
|
|
|
## Create a Mental Model
|
|
|
|
Creating a mental model runs a reflect operation in the background and saves the result:
|
|
|
|
<Tabs>
|
|
<TabItem value="python" label="Python">
|
|
<CodeSnippet code={mentalModelsPy} section="create-mental-model" language="python" />
|
|
</TabItem>
|
|
<TabItem value="cli" label="CLI">
|
|
|
|
```bash
|
|
# Create a mental model (async operation)
|
|
curl -X POST "http://localhost:8888/v1/default/banks/my-bank/mental-models" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"name": "Team Communication Preferences",
|
|
"source_query": "How does the team prefer to communicate?",
|
|
"tags": ["team"]
|
|
}'
|
|
|
|
# Response: {"operation_id": "op-123"}
|
|
# Use the operations endpoint to check completion
|
|
```
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
### Parameters
|
|
|
|
| Parameter | Type | Required | Description |
|
|
|-----------|------|----------|-------------|
|
|
| `name` | string | Yes | Human-readable name for the mental model |
|
|
| `source_query` | string | Yes | The query to run to generate content |
|
|
| `tags` | list | No | Tags for filtering during retrieval |
|
|
| `max_tokens` | int | No | Maximum tokens for the mental model content |
|
|
|
|
---
|
|
|
|
## List Mental Models
|
|
|
|
<Tabs>
|
|
<TabItem value="python" label="Python">
|
|
<CodeSnippet code={mentalModelsPy} section="list-mental-models" language="python" />
|
|
</TabItem>
|
|
<TabItem value="cli" label="CLI">
|
|
|
|
```bash
|
|
curl "http://localhost:8888/v1/default/banks/my-bank/mental-models"
|
|
```
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
---
|
|
|
|
## Get a Mental Model
|
|
|
|
<Tabs>
|
|
<TabItem value="python" label="Python">
|
|
<CodeSnippet code={mentalModelsPy} section="get-mental-model" language="python" />
|
|
</TabItem>
|
|
<TabItem value="cli" label="CLI">
|
|
|
|
```bash
|
|
curl "http://localhost:8888/v1/default/banks/my-bank/mental-models/{mental_model_id}"
|
|
```
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
### Response Fields
|
|
|
|
| Field | Type | Description |
|
|
|-------|------|-------------|
|
|
| `id` | string | Unique mental model ID |
|
|
| `bank_id` | string | Memory bank ID |
|
|
| `name` | string | Human-readable name |
|
|
| `source_query` | string | The query used to generate content |
|
|
| `content` | string | The generated mental model text |
|
|
| `tags` | list | Tags for filtering |
|
|
| `last_refreshed_at` | string | When the mental model was last updated |
|
|
| `created_at` | string | When the mental model was created |
|
|
| `reflect_response` | object | Full reflect response including `based_on` facts |
|
|
|
|
---
|
|
|
|
## Refresh a Mental Model
|
|
|
|
Re-run the source query to update the mental model with current knowledge:
|
|
|
|
<Tabs>
|
|
<TabItem value="python" label="Python">
|
|
<CodeSnippet code={mentalModelsPy} section="refresh-mental-model" language="python" />
|
|
</TabItem>
|
|
<TabItem value="cli" label="CLI">
|
|
|
|
```bash
|
|
curl -X POST "http://localhost:8888/v1/default/banks/my-bank/mental-models/{mental_model_id}/refresh"
|
|
```
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
Refreshing is useful when:
|
|
- New memories have been retained that affect the topic
|
|
- Observations have been updated
|
|
- You want to ensure the mental model reflects current knowledge
|
|
|
|
---
|
|
|
|
## Update a Mental Model
|
|
|
|
Update the mental model's name:
|
|
|
|
<Tabs>
|
|
<TabItem value="python" label="Python">
|
|
<CodeSnippet code={mentalModelsPy} section="update-mental-model" language="python" />
|
|
</TabItem>
|
|
<TabItem value="cli" label="CLI">
|
|
|
|
```bash
|
|
curl -X PATCH "http://localhost:8888/v1/default/banks/my-bank/mental-models/{mental_model_id}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"name": "Updated Team Communication Preferences"}'
|
|
```
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
---
|
|
|
|
## Delete a Mental Model
|
|
|
|
<Tabs>
|
|
<TabItem value="python" label="Python">
|
|
<CodeSnippet code={mentalModelsPy} section="delete-mental-model" language="python" />
|
|
</TabItem>
|
|
<TabItem value="cli" label="CLI">
|
|
|
|
```bash
|
|
curl -X DELETE "http://localhost:8888/v1/default/banks/my-bank/mental-models/{mental_model_id}"
|
|
```
|
|
|
|
</TabItem>
|
|
</Tabs>
|
|
|
|
---
|
|
|
|
## Use Cases
|
|
|
|
| Use Case | Example |
|
|
|----------|---------|
|
|
| **FAQ Answers** | Pre-compute answers to common customer questions |
|
|
| **Onboarding Summaries** | "What should new team members know?" |
|
|
| **Status Reports** | "What's the current project status?" refreshed weekly |
|
|
| **Policy Summaries** | "What are our security policies?" |
|
|
|
|
---
|
|
|
|
## Next Steps
|
|
|
|
- [**Reflect**](./reflect) — How the agentic loop uses mental models
|
|
- [**Observations**](/developer/observations) — How knowledge is consolidated
|
|
- [**Operations**](./operations) — Track async mental model creation
|