reflect-sdk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reflect_sdk-0.1.0/.gitignore +55 -0
- reflect_sdk-0.1.0/PKG-INFO +15 -0
- reflect_sdk-0.1.0/docs/.mintignore +7 -0
- reflect_sdk-0.1.0/docs/ai-tools/claude-code.mdx +37 -0
- reflect_sdk-0.1.0/docs/ai-tools/cursor.mdx +33 -0
- reflect_sdk-0.1.0/docs/ai-tools/windsurf.mdx +33 -0
- reflect_sdk-0.1.0/docs/api-reference/introduction.mdx +14 -0
- reflect_sdk-0.1.0/docs/api-reference/reflect-client.mdx +84 -0
- reflect_sdk-0.1.0/docs/development.mdx +50 -0
- reflect_sdk-0.1.0/docs/docs.json +90 -0
- reflect_sdk-0.1.0/docs/essentials/navigation.mdx +7 -0
- reflect_sdk-0.1.0/docs/essentials/settings.mdx +7 -0
- reflect_sdk-0.1.0/docs/favicon.svg +5 -0
- reflect_sdk-0.1.0/docs/guides/memories.mdx +51 -0
- reflect_sdk-0.1.0/docs/guides/traces-and-reviews.mdx +67 -0
- reflect_sdk-0.1.0/docs/index.mdx +71 -0
- reflect_sdk-0.1.0/docs/installation.mdx +24 -0
- reflect_sdk-0.1.0/docs/logo/dark.svg +13 -0
- reflect_sdk-0.1.0/docs/logo/light.svg +13 -0
- reflect_sdk-0.1.0/docs/package-lock.json +14495 -0
- reflect_sdk-0.1.0/docs/package.json +18 -0
- reflect_sdk-0.1.0/docs/quickstart.mdx +60 -0
- reflect_sdk-0.1.0/docs/snippets/snippet-intro.mdx +1 -0
- reflect_sdk-0.1.0/examples/augment_with_memories.py +182 -0
- reflect_sdk-0.1.0/examples/deepagents_exa_quickstart.py +192 -0
- reflect_sdk-0.1.0/examples/interactive_feedback_cli.py +192 -0
- reflect_sdk-0.1.0/examples/openai_agents_reflect_simple.py +79 -0
- reflect_sdk-0.1.0/pyproject.toml +27 -0
- reflect_sdk-0.1.0/scripts/generate_sdk_reference.py +205 -0
- reflect_sdk-0.1.0/src/reflect_sdk/__init__.py +26 -0
- reflect_sdk-0.1.0/src/reflect_sdk/client.py +664 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
env/
|
|
10
|
+
*.egg-info/
|
|
11
|
+
.eggs/
|
|
12
|
+
dist/
|
|
13
|
+
build/
|
|
14
|
+
|
|
15
|
+
# Node / TypeScript / JavaScript
|
|
16
|
+
node_modules/
|
|
17
|
+
*.tsbuildinfo
|
|
18
|
+
.cache/
|
|
19
|
+
.parcel-cache/
|
|
20
|
+
.vite/
|
|
21
|
+
.turbo/
|
|
22
|
+
.next/
|
|
23
|
+
.nuxt/
|
|
24
|
+
.output/
|
|
25
|
+
.vercel/
|
|
26
|
+
.netlify/
|
|
27
|
+
*.log
|
|
28
|
+
npm-debug.log*
|
|
29
|
+
yarn-debug.log*
|
|
30
|
+
yarn-error.log*
|
|
31
|
+
.pnpm-debug.log*
|
|
32
|
+
.eslintcache
|
|
33
|
+
coverage/
|
|
34
|
+
.nyc_output/
|
|
35
|
+
|
|
36
|
+
# IDE
|
|
37
|
+
.vscode/
|
|
38
|
+
.idea/
|
|
39
|
+
*.swp
|
|
40
|
+
*.swo
|
|
41
|
+
|
|
42
|
+
# Testing
|
|
43
|
+
.pytest_cache/
|
|
44
|
+
.coverage
|
|
45
|
+
htmlcov/
|
|
46
|
+
|
|
47
|
+
# Environment
|
|
48
|
+
.env
|
|
49
|
+
.env.local
|
|
50
|
+
*.local
|
|
51
|
+
|
|
52
|
+
# OS
|
|
53
|
+
.DS_Store
|
|
54
|
+
Thumbs.db
|
|
55
|
+
benchmark/results
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: reflect-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reflect SDK - Python client for Reflect API
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Requires-Dist: httpx>=0.28.0
|
|
7
|
+
Requires-Dist: ollama>=0.6.1
|
|
8
|
+
Requires-Dist: openai-agents>=0.2.0
|
|
9
|
+
Requires-Dist: openai>=2.28.0
|
|
10
|
+
Provides-Extra: examples
|
|
11
|
+
Requires-Dist: deepagents; extra == 'examples'
|
|
12
|
+
Requires-Dist: exa-py; extra == 'examples'
|
|
13
|
+
Requires-Dist: langchain-openai; extra == 'examples'
|
|
14
|
+
Provides-Extra: langsmith
|
|
15
|
+
Requires-Dist: langsmith>=0.7.0; extra == 'langsmith'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Claude Code setup"
|
|
3
|
+
description: "Configure Claude Code for Reflect SDK documentation"
|
|
4
|
+
icon: "asterisk"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Set up Claude Code to help you write and maintain the Reflect SDK documentation.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
- Active Claude subscription (Pro, Max, or API access)
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
<Steps>
|
|
16
|
+
<Step title="Install Claude Code">
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g @anthropic-ai/claude-code
|
|
19
|
+
```
|
|
20
|
+
</Step>
|
|
21
|
+
|
|
22
|
+
<Step title="Install the Mintlify skill">
|
|
23
|
+
In the docs directory (`packages/sdk/docs`), run:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx skills add https://mintlify.com/docs
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This adds Mintlify's component reference, writing standards, and workflow guidance.
|
|
30
|
+
</Step>
|
|
31
|
+
|
|
32
|
+
<Step title="Start writing with Claude Code">
|
|
33
|
+
```bash
|
|
34
|
+
claude
|
|
35
|
+
```
|
|
36
|
+
</Step>
|
|
37
|
+
</Steps>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Cursor setup"
|
|
3
|
+
description: "Configure Cursor for Reflect SDK documentation"
|
|
4
|
+
icon: "arrow-pointer"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Set up Cursor to help you write and maintain the Reflect SDK documentation.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
- Cursor editor installed
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
<Steps>
|
|
16
|
+
<Step title="Open the docs directory in Cursor">
|
|
17
|
+
Open `packages/sdk/docs` where `docs.json` is located.
|
|
18
|
+
</Step>
|
|
19
|
+
|
|
20
|
+
<Step title="Install the Mintlify skill">
|
|
21
|
+
In the integrated terminal, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx skills add https://mintlify.com/docs
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This adds Mintlify's component reference, writing standards, and workflow guidance.
|
|
28
|
+
</Step>
|
|
29
|
+
|
|
30
|
+
<Step title="Start writing with Cursor">
|
|
31
|
+
Open a file and use Cursor's AI features to draft and edit documentation.
|
|
32
|
+
</Step>
|
|
33
|
+
</Steps>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Windsurf setup"
|
|
3
|
+
description: "Configure Windsurf for Reflect SDK documentation"
|
|
4
|
+
icon: "water"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Set up Windsurf's Cascade AI assistant to help you write and maintain the Reflect SDK documentation.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
|
|
11
|
+
- Windsurf editor installed
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
<Steps>
|
|
16
|
+
<Step title="Open the docs directory in Windsurf">
|
|
17
|
+
Open `packages/sdk/docs` where `docs.json` is located.
|
|
18
|
+
</Step>
|
|
19
|
+
|
|
20
|
+
<Step title="Install the Mintlify skill">
|
|
21
|
+
In the integrated terminal, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx skills add https://mintlify.com/docs
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This adds Mintlify's component reference, writing standards, and workflow guidance.
|
|
28
|
+
</Step>
|
|
29
|
+
|
|
30
|
+
<Step title="Start writing with Cascade">
|
|
31
|
+
Open a file and use Cascade to draft and edit documentation.
|
|
32
|
+
</Step>
|
|
33
|
+
</Steps>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Introduction"
|
|
3
|
+
description: "ReflectClient API reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The Reflect SDK reference is generated from docstrings in `reflect_sdk.client`. Each method and data type is documented with signatures and descriptions.
|
|
7
|
+
|
|
8
|
+
<Card
|
|
9
|
+
title="ReflectClient"
|
|
10
|
+
icon="code"
|
|
11
|
+
href="/api-reference/reflect-client"
|
|
12
|
+
>
|
|
13
|
+
Full API reference for the Reflect Python client
|
|
14
|
+
</Card>
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "ReflectClient"
|
|
3
|
+
description: "API reference for the Reflect Python client."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Constructor
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
ReflectClient(*, base_url: str = 'http://localhost:8000', api_key: str, project_id: str, timeout: float | httpx.Timeout = 60.0) -> None
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
| Parameter | Type | Default | Description |
|
|
13
|
+
|-----------|------|---------|-------------|
|
|
14
|
+
| `base_url` | `str` | `"http://localhost:8000"` | Reflect API base URL (e.g. http://localhost:8000). |
|
|
15
|
+
| `api_key` | `str` | `required` | Plaintext API key (e.g. rf_live_...). |
|
|
16
|
+
| `project_id` | `str` | `required` | Project ID from the Reflect console. |
|
|
17
|
+
| `timeout` | `float | httpx.Timeout` | `60.0` | Request timeout in seconds. |
|
|
18
|
+
|
|
19
|
+
## Instance methods
|
|
20
|
+
|
|
21
|
+
### health
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
def health() -> dict[str, str]
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Return the API health status. No authentication required.
|
|
28
|
+
|
|
29
|
+
### query_memories
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
def query_memories(task: str, *, limit: int = 10, lambda_: float = 0.5) -> list[Memory]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Retrieve memories by semantic similarity and Q-value ranking.
|
|
36
|
+
|
|
37
|
+
### augment_with_memories
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
def augment_with_memories(task: str, *, limit: int = 10, lambda_: float = 0.5) -> AugmentedTask
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Query memories and format them into the task text for prompt augmentation.
|
|
44
|
+
|
|
45
|
+
### create_trace
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
def create_trace(*, task: str, trajectory: TrajectoryInput, final_response: str, retrieved_memory_ids: Sequence[str] = (), model: str | None = None, metadata: dict[str, Any] | None = None, review_result: str | None = None, feedback_text: str | None = None) -> Trace
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Store a trace. Optionally include an inline review.
|
|
52
|
+
|
|
53
|
+
### list_traces
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
def list_traces(*, review_status: str | None = None) -> list[Trace]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
List traces for the project.
|
|
60
|
+
|
|
61
|
+
### get_trace
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
def get_trace(trace_id: str) -> Trace
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Fetch a single trace by ID.
|
|
68
|
+
|
|
69
|
+
### review_trace
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
def review_trace(trace_id: str, *, result: str, feedback_text: str | None = None) -> Trace
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Submit a deferred review for a trace.
|
|
76
|
+
|
|
77
|
+
## Data types
|
|
78
|
+
|
|
79
|
+
| Type | Description |
|
|
80
|
+
|------|-------------|
|
|
81
|
+
| `AugmentedTask` | augmented_task, memories |
|
|
82
|
+
| `Memory` | id, task, reflection, q_value, similarity, score, success |
|
|
83
|
+
| `Review` | id, trace_id, result, feedback_text, mode |
|
|
84
|
+
| `Trace` | id, task, trajectory, final_response, retrieved_memory_ids, review_status, model, metadata, created_memory_id, review |
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Development"
|
|
3
|
+
description: "Preview and contribute to the Reflect SDK documentation."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
<Info>
|
|
7
|
+
**Prerequisites**: Node.js 19+ and a docs directory with `docs.json`.
|
|
8
|
+
</Info>
|
|
9
|
+
|
|
10
|
+
## Preview locally
|
|
11
|
+
|
|
12
|
+
<Steps>
|
|
13
|
+
<Step title="Install dependencies">
|
|
14
|
+
From the `packages/sdk/docs` directory:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install
|
|
18
|
+
```
|
|
19
|
+
</Step>
|
|
20
|
+
|
|
21
|
+
<Step title="Generate API reference">
|
|
22
|
+
The reference is generated from SDK docstrings. Run:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm run generate
|
|
26
|
+
```
|
|
27
|
+
</Step>
|
|
28
|
+
|
|
29
|
+
<Step title="Start the preview server">
|
|
30
|
+
```bash
|
|
31
|
+
npm run dev
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Open `http://localhost:3000` to view the docs.
|
|
35
|
+
</Step>
|
|
36
|
+
</Steps>
|
|
37
|
+
|
|
38
|
+
<Tip>
|
|
39
|
+
Use `npm run validate` to check links and build. Use `npm run broken-links` to find broken internal links.
|
|
40
|
+
</Tip>
|
|
41
|
+
|
|
42
|
+
## Regenerating the reference
|
|
43
|
+
|
|
44
|
+
When you change docstrings in `packages/sdk/src/reflect_sdk/client.py`, regenerate the reference:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm run generate
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The script writes `api-reference/reflect-client.mdx` from the SDK source.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://mintlify.com/schema.json",
|
|
3
|
+
"theme": "mint",
|
|
4
|
+
"name": "Reflect SDK",
|
|
5
|
+
"colors": {
|
|
6
|
+
"primary": "#2563eb",
|
|
7
|
+
"light": "#3b82f6",
|
|
8
|
+
"dark": "#1d4ed8"
|
|
9
|
+
},
|
|
10
|
+
"favicon": "/favicon.svg",
|
|
11
|
+
"logo": {
|
|
12
|
+
"light": "/logo/light.svg",
|
|
13
|
+
"dark": "/logo/dark.svg"
|
|
14
|
+
},
|
|
15
|
+
"navigation": {
|
|
16
|
+
"tabs": [
|
|
17
|
+
{
|
|
18
|
+
"tab": "Guides",
|
|
19
|
+
"groups": [
|
|
20
|
+
{
|
|
21
|
+
"group": "Getting started",
|
|
22
|
+
"pages": [
|
|
23
|
+
"index",
|
|
24
|
+
"quickstart",
|
|
25
|
+
"installation",
|
|
26
|
+
"development"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"group": "Core concepts",
|
|
31
|
+
"pages": [
|
|
32
|
+
"guides/memories",
|
|
33
|
+
"guides/traces-and-reviews"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"group": "AI tools",
|
|
38
|
+
"pages": [
|
|
39
|
+
"ai-tools/cursor",
|
|
40
|
+
"ai-tools/claude-code",
|
|
41
|
+
"ai-tools/windsurf"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"group": "Customization",
|
|
46
|
+
"pages": [
|
|
47
|
+
"essentials/settings",
|
|
48
|
+
"essentials/navigation"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"tab": "API reference",
|
|
55
|
+
"groups": [
|
|
56
|
+
{
|
|
57
|
+
"group": "SDK reference",
|
|
58
|
+
"pages": [
|
|
59
|
+
"api-reference/introduction",
|
|
60
|
+
"api-reference/reflect-client"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"global": {
|
|
67
|
+
"anchors": [
|
|
68
|
+
{
|
|
69
|
+
"anchor": "Console",
|
|
70
|
+
"href": "https://reflect.starlight-search.com",
|
|
71
|
+
"icon": "square-terminal"
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"contextual": {
|
|
77
|
+
"options": [
|
|
78
|
+
"copy",
|
|
79
|
+
"view",
|
|
80
|
+
"chatgpt",
|
|
81
|
+
"claude",
|
|
82
|
+
"perplexity",
|
|
83
|
+
"cursor",
|
|
84
|
+
"vscode"
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
"footer": {
|
|
88
|
+
"socials": {}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Navigation"
|
|
3
|
+
description: "How navigation is organized in the Reflect SDK docs"
|
|
4
|
+
icon: "map"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The navigation uses tabs: **Guides** and **API reference**. Add new pages in `docs.json` under the appropriate tab and group. Pages not listed in `docs.json` are hidden but still accessible by direct link or search.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Settings"
|
|
3
|
+
description: "Customize the Reflect SDK documentation site"
|
|
4
|
+
icon: "gear"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The `docs.json` file controls the look and feel of the Reflect SDK documentation. Key settings include `name`, `colors`, `logo`, `favicon`, and `navigation`. See the [Mintlify docs](https://mintlify.com/docs) for the full configuration schema.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg width="502" height="502" viewBox="0 0 502 502" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M501.402 185.33V29.9622C501.402 13.2897 487.876 0 471.453 0H316.156C291.763 0 267.611 4.83243 245.15 14.0144C222.689 23.438 202.16 36.9695 185.012 54.3668L183.804 55.575C161.101 78.5299 144.92 107.042 136.708 138.454C151.441 134.588 166.656 132.655 181.871 132.413C222.447 131.93 262.298 144.978 294.661 169.383C323.885 191.13 346.104 221.092 358.18 255.645C370.739 290.681 372.188 328.859 362.769 364.862C393.925 356.647 422.666 340.457 445.611 317.744L446.818 316.536C463.966 299.38 477.732 278.841 487.151 256.37C496.571 233.898 501.16 209.735 501.16 185.33H501.402Z" fill="#18E299"/>
|
|
3
|
+
<path d="M132.071 182.706C132.312 135.044 151.32 89.3068 184.764 55.1246L55.5569 184.391C55.0756 184.873 54.5942 185.113 54.113 185.595C22.5932 216.888 3.58552 258.774 0.457596 303.066C-2.42971 344.47 8.39746 385.392 31.4959 419.575C33.6992 422.835 39.6774 423.907 43.0459 420.778L122.206 341.822C146.989 317.028 154.689 280.198 142.899 247.219C135.44 226.758 131.831 204.852 132.071 182.706Z" fill="#0C8C5E"/>
|
|
4
|
+
<path d="M446.067 316.547C421.284 340.86 390.245 357.71 356.56 365.172C322.634 372.635 287.506 370.468 254.783 358.914C254.783 358.914 254.542 358.914 254.301 358.914C221.338 347.118 184.525 354.821 159.742 379.375L80.5808 458.331C77.2123 461.701 77.6935 467.238 81.7838 469.885C115.95 492.754 156.855 503.827 198.24 500.938C242.512 497.809 284.137 478.792 315.656 447.258L316.859 446.054L446.067 316.788V316.547Z" fill="#0C8C5E"/>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Memories"
|
|
3
|
+
description: "Query and augment tasks with Reflect memories."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Memories are stored reflections from past tasks and reviews. The Reflect API retrieves them by semantic similarity and Q-value ranking, so you can reuse successful patterns and avoid known failures.
|
|
7
|
+
|
|
8
|
+
## Query memories
|
|
9
|
+
|
|
10
|
+
Use `query_memories` to fetch relevant memories for a task:
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
memories = client.query_memories(
|
|
14
|
+
task="How do I handle rate limits in an API client?",
|
|
15
|
+
limit=10,
|
|
16
|
+
lambda_=0.5,
|
|
17
|
+
)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Default | Description |
|
|
21
|
+
|-----------|------|---------|-------------|
|
|
22
|
+
| `task` | `str` | required | The task description to search against. Embeddings are computed from this text. |
|
|
23
|
+
| `limit` | `int` | `10` | Maximum number of memories to return. |
|
|
24
|
+
| `lambda_` | `float` | `0.5` | Blend weight between semantic similarity (1.0 = pure similarity) and Q-value ranking (0.0 = pure Q-value). |
|
|
25
|
+
|
|
26
|
+
Each returned `Memory` has:
|
|
27
|
+
|
|
28
|
+
- `id`, `task`, `reflection` – the stored content
|
|
29
|
+
- `q_value` – learned Q-value from reviews
|
|
30
|
+
- `similarity` – embedding similarity to the query
|
|
31
|
+
- `score` – blended ranking score
|
|
32
|
+
- `success` – `True`/`False`/`None` from past reviews
|
|
33
|
+
|
|
34
|
+
## Augment with memories
|
|
35
|
+
|
|
36
|
+
`augment_with_memories` retrieves memories and formats them into a text block you can append to your prompt:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from reflect_sdk import ReflectClient
|
|
40
|
+
|
|
41
|
+
client = ReflectClient(api_key="...", project_id="...")
|
|
42
|
+
augmented = client.augment_with_memories(
|
|
43
|
+
task="Implement exponential backoff for retries",
|
|
44
|
+
limit=5,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# augmented.augmented_task = task + "\n\nRelevant memories:\n\n" + formatted blocks
|
|
48
|
+
# augmented.memories = list of Memory objects
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Memories are grouped by `success`: successful, failed, and other. Each block includes the past task and reflection.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Traces and reviews"
|
|
3
|
+
description: "Record trajectories and submit reviews for learning."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Traces capture the full trajectory of an AI run (task, steps, final response, retrieved memories). Reviews mark the outcome (success or failure) and optionally include feedback. Reviews update Q-values and create new reflection memories.
|
|
7
|
+
|
|
8
|
+
## Create a trace
|
|
9
|
+
|
|
10
|
+
Use `create_trace` to store a trajectory:
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from reflect_sdk import ReflectClient
|
|
14
|
+
|
|
15
|
+
client = ReflectClient(api_key="...", project_id="...")
|
|
16
|
+
trace = client.create_trace(
|
|
17
|
+
task="Parse the CSV and return the top 5 rows",
|
|
18
|
+
trajectory=[
|
|
19
|
+
{"role": "user", "content": "Parse the CSV..."},
|
|
20
|
+
{"role": "assistant", "content": "I'll use pandas..."},
|
|
21
|
+
],
|
|
22
|
+
final_response="Here are the top 5 rows: ...",
|
|
23
|
+
retrieved_memory_ids=["mem_abc", "mem_def"],
|
|
24
|
+
model="gpt-4",
|
|
25
|
+
metadata={"source": "cli"},
|
|
26
|
+
)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
You can pass `trajectory` as a list of message dicts or a JSON string.
|
|
30
|
+
|
|
31
|
+
## Inline review
|
|
32
|
+
|
|
33
|
+
Include a review when creating the trace:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
trace = client.create_trace(
|
|
37
|
+
task="...",
|
|
38
|
+
trajectory=[...],
|
|
39
|
+
final_response="...",
|
|
40
|
+
retrieved_memory_ids=["mem_abc"],
|
|
41
|
+
review_result="success",
|
|
42
|
+
feedback_text="Correct output format.",
|
|
43
|
+
)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`review_result` must be `"success"` or `"failure"`. The review is applied immediately; no separate `review_trace` call is needed.
|
|
47
|
+
|
|
48
|
+
## Deferred review
|
|
49
|
+
|
|
50
|
+
Create the trace first, then submit a review later:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
trace = client.create_trace(task="...", trajectory=[...], final_response="...")
|
|
54
|
+
# ... later, after human feedback ...
|
|
55
|
+
updated = client.review_trace(
|
|
56
|
+
trace_id=trace.id,
|
|
57
|
+
result="failure",
|
|
58
|
+
feedback_text="Wrong column order.",
|
|
59
|
+
)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## List and fetch traces
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
traces = client.list_traces(review_status="pending") # or "reviewed" or None for all
|
|
66
|
+
trace = client.get_trace(trace_id="tr_xyz")
|
|
67
|
+
```
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Introduction"
|
|
3
|
+
description: "Overview of the Reflect SDK for Python."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The Reflect SDK is a Python client for the Reflect API. It lets you query memories, augment tasks with learned reflections, and record traces with reviews so your AI improves from feedback.
|
|
7
|
+
|
|
8
|
+
## What Reflect does
|
|
9
|
+
|
|
10
|
+
Reflect combines semantic search with Q-learning to surface relevant past experiences. When you query memories for a task, the API blends embedding similarity with learned Q-values so high-scoring reflections rank higher over time.
|
|
11
|
+
|
|
12
|
+
The workflow:
|
|
13
|
+
|
|
14
|
+
1. **Query memories** – Retrieve similar past reflections for a task.
|
|
15
|
+
2. **Augment your prompt** – Append successful and failed memories to the task text.
|
|
16
|
+
3. **Generate a response** – Your LLM uses the augmented context.
|
|
17
|
+
4. **Record a trace** – Store the trajectory and final response.
|
|
18
|
+
5. **Submit a review** – Mark success or failure with optional feedback.
|
|
19
|
+
|
|
20
|
+
Reviews update Q-values in the vector store and create new reflection memories. Future queries automatically favor reflections that led to success.
|
|
21
|
+
|
|
22
|
+
## Get started
|
|
23
|
+
|
|
24
|
+
<Card
|
|
25
|
+
title="Quickstart"
|
|
26
|
+
icon="rocket"
|
|
27
|
+
href="/quickstart"
|
|
28
|
+
horizontal
|
|
29
|
+
>
|
|
30
|
+
Sign in to Reflect, create a project and API key, then use the SDK.
|
|
31
|
+
</Card>
|
|
32
|
+
|
|
33
|
+
## Requirements
|
|
34
|
+
|
|
35
|
+
- Python 3.12+
|
|
36
|
+
- An account on the [Reflect console](https://reflect.starlight-search.com)
|
|
37
|
+
- A project and API key created in the console (see [Quickstart](/quickstart))
|
|
38
|
+
- The Reflect API `base_url` for your environment
|
|
39
|
+
|
|
40
|
+
## Next steps
|
|
41
|
+
|
|
42
|
+
<Columns cols={2}>
|
|
43
|
+
<Card
|
|
44
|
+
title="Memories"
|
|
45
|
+
icon="brain"
|
|
46
|
+
href="/guides/memories"
|
|
47
|
+
>
|
|
48
|
+
Query and augment tasks with past reflections.
|
|
49
|
+
</Card>
|
|
50
|
+
<Card
|
|
51
|
+
title="Traces and reviews"
|
|
52
|
+
icon="clipboard-list"
|
|
53
|
+
href="/guides/traces-and-reviews"
|
|
54
|
+
>
|
|
55
|
+
Record trajectories and submit reviews for learning.
|
|
56
|
+
</Card>
|
|
57
|
+
<Card
|
|
58
|
+
title="API reference"
|
|
59
|
+
icon="code"
|
|
60
|
+
href="/api-reference/reflect-client"
|
|
61
|
+
>
|
|
62
|
+
Full ReflectClient reference from docstrings.
|
|
63
|
+
</Card>
|
|
64
|
+
<Card
|
|
65
|
+
title="Installation"
|
|
66
|
+
icon="download"
|
|
67
|
+
href="/installation"
|
|
68
|
+
>
|
|
69
|
+
Install the Reflect SDK with pip.
|
|
70
|
+
</Card>
|
|
71
|
+
</Columns>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Installation"
|
|
3
|
+
description: "Install the Reflect SDK for Python."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Install the Reflect SDK with pip:
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install reflect-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Optional dependencies
|
|
13
|
+
|
|
14
|
+
For LangSmith tracing:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install reflect-sdk[langsmith]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
For example scripts (DeepAgents, Exa, LangChain):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install reflect-sdk[examples]
|
|
24
|
+
```
|