lorebo-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.
- lorebo_sdk-0.1.0/.gitignore +14 -0
- lorebo_sdk-0.1.0/LICENSE +21 -0
- lorebo_sdk-0.1.0/PKG-INFO +297 -0
- lorebo_sdk-0.1.0/README.md +258 -0
- lorebo_sdk-0.1.0/pyproject.toml +74 -0
- lorebo_sdk-0.1.0/src/lorebo_sdk/__init__.py +0 -0
- lorebo_sdk-0.1.0/src/lorebo_sdk/client.py +119 -0
- lorebo_sdk-0.1.0/src/lorebo_sdk/errors.py +29 -0
- lorebo_sdk-0.1.0/src/lorebo_sdk/pages.py +92 -0
- lorebo_sdk-0.1.0/src/lorebo_sdk/py.typed +0 -0
- lorebo_sdk-0.1.0/src/lorebo_sdk/records.py +32 -0
- lorebo_sdk-0.1.0/src/lorebo_sdk/runs.py +164 -0
- lorebo_sdk-0.1.0/src/lorebo_sdk/skills.py +101 -0
- lorebo_sdk-0.1.0/src/lorebo_sdk/tools.py +87 -0
- lorebo_sdk-0.1.0/tests/__init__.py +0 -0
- lorebo_sdk-0.1.0/tests/lorebo_fakes.py +137 -0
- lorebo_sdk-0.1.0/tests/test_lorebo.py +186 -0
- lorebo_sdk-0.1.0/tests/test_skills.py +57 -0
lorebo_sdk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LexRAG
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: lorebo-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Save and retrieve Lorebo knowledge from your application with any LLM
|
|
5
|
+
Project-URL: Homepage, https://github.com/lexrag/lorebo-sdk
|
|
6
|
+
Project-URL: Documentation, https://github.com/lexrag/lorebo-sdk#quick-start
|
|
7
|
+
Project-URL: Repository, https://github.com/lexrag/lorebo-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/lexrag/lorebo-sdk/issues
|
|
9
|
+
Author: LexRAG
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,knowledge-base,llm,lorebo,mcp,pydantic-ai
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Framework :: AsyncIO
|
|
15
|
+
Classifier: Framework :: Pydantic
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Requires-Dist: fastmcp-slim[client]>=4.1
|
|
23
|
+
Requires-Dist: httpx>=0.28
|
|
24
|
+
Requires-Dist: pydantic-ai-slim[mcp]>=2.59
|
|
25
|
+
Requires-Dist: pydantic>=2.11
|
|
26
|
+
Provides-Extra: anthropic
|
|
27
|
+
Requires-Dist: pydantic-ai-slim[anthropic]>=2.59; extra == 'anthropic'
|
|
28
|
+
Provides-Extra: bedrock
|
|
29
|
+
Requires-Dist: pydantic-ai-slim[bedrock]>=2.59; extra == 'bedrock'
|
|
30
|
+
Provides-Extra: google
|
|
31
|
+
Requires-Dist: pydantic-ai-slim[google]>=2.59; extra == 'google'
|
|
32
|
+
Provides-Extra: groq
|
|
33
|
+
Requires-Dist: pydantic-ai-slim[groq]>=2.59; extra == 'groq'
|
|
34
|
+
Provides-Extra: mistral
|
|
35
|
+
Requires-Dist: pydantic-ai-slim[mistral]>=2.59; extra == 'mistral'
|
|
36
|
+
Provides-Extra: openai
|
|
37
|
+
Requires-Dist: pydantic-ai-slim[openai]>=2.59; extra == 'openai'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<a href="https://github.com/lexrag/lorebo-sdk">
|
|
42
|
+
<picture>
|
|
43
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/lexrag/lorebo-sdk/main/assets/lorebo-logo-on-dark.svg">
|
|
44
|
+
<img src="https://raw.githubusercontent.com/lexrag/lorebo-sdk/main/assets/lorebo-logo-primary.svg" width="264" alt="Lorebo">
|
|
45
|
+
</picture>
|
|
46
|
+
</a>
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
<h1 align="center">Lorebo SDK</h1>
|
|
50
|
+
|
|
51
|
+
<p align="center"><strong>Give your application a knowledge base that people and AI share.</strong></p>
|
|
52
|
+
|
|
53
|
+
<p align="center">
|
|
54
|
+
<a href="https://github.com/lexrag/lorebo-sdk/actions/workflows/check.yml"><img src="https://github.com/lexrag/lorebo-sdk/actions/workflows/check.yml/badge.svg" alt="Checks"></a>
|
|
55
|
+
<a href="https://github.com/lexrag/lorebo-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-593EDC" alt="MIT license"></a>
|
|
56
|
+
<a href="https://pypi.org/project/lorebo-sdk/"><img src="https://img.shields.io/badge/Python-3.12+-3776AB" alt="Python 3.12+"></a>
|
|
57
|
+
<a href="https://www.npmjs.com/package/lorebo-sdk"><img src="https://img.shields.io/badge/TypeScript-Node_22+-3178C6" alt="TypeScript, Node 22+"></a>
|
|
58
|
+
</p>
|
|
59
|
+
|
|
60
|
+
<p align="center">
|
|
61
|
+
<a href="#quick-start">Quick start</a> ·
|
|
62
|
+
<a href="#results">Results</a> ·
|
|
63
|
+
<a href="#choosing-a-base">Choosing a base</a> ·
|
|
64
|
+
<a href="#errors">Errors</a> ·
|
|
65
|
+
<a href="#connecting-to-lorebo">Connecting to Lorebo</a>
|
|
66
|
+
</p>
|
|
67
|
+
|
|
68
|
+
Lorebo turns useful AI work into knowledge you own:
|
|
69
|
+
readable, connected pages that people and AI agents can find, correct and reuse.
|
|
70
|
+
|
|
71
|
+
The Lorebo SDK lets your application use that knowledge with two calls:
|
|
72
|
+
|
|
73
|
+
- **`capture`** saves the durable part of a text as Lorebo pages. It searches
|
|
74
|
+
first, updates pages that already cover the topic and creates the rest.
|
|
75
|
+
- **`explore`** answers a question from the pages in Lorebo and returns the
|
|
76
|
+
pages the answer relies on.
|
|
77
|
+
|
|
78
|
+
Both calls run the official Lorebo skills with the language model you choose.
|
|
79
|
+
The SDK is available for Python and TypeScript with the same behavior.
|
|
80
|
+
|
|
81
|
+
## Requirements
|
|
82
|
+
|
|
83
|
+
- A Lorebo MCP endpoint:
|
|
84
|
+
- Lorebo Desktop serves `http://127.0.0.1:8757/mcp` on your machine.
|
|
85
|
+
- [Lorebo Headless](https://github.com/orgs/lexrag/packages/container/package/lorebo-headless) serves `http://127.0.0.1:8758/mcp` when run locally with the example below.
|
|
86
|
+
- A language model that supports tool calls and structured output.
|
|
87
|
+
- Python 3.12+ or Node.js 22+.
|
|
88
|
+
|
|
89
|
+
## Connecting to Lorebo
|
|
90
|
+
|
|
91
|
+
With Desktop already running, use its local MCP URL in the quick start.
|
|
92
|
+
To run Headless with Docker instead:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
docker run --detach --name lorebo \
|
|
96
|
+
--publish 127.0.0.1:8758:8758 \
|
|
97
|
+
--volume lorebo-data:/data \
|
|
98
|
+
ghcr.io/lexrag/lorebo-headless:stable
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Use `http://127.0.0.1:8758/mcp` as the SDK URL and `None` (`null` in
|
|
102
|
+
TypeScript) as the token. The volume preserves your bases when the container
|
|
103
|
+
is recreated. Back up the complete volume before upgrading and stop the old
|
|
104
|
+
container before starting another writer on it. The official image is Linux
|
|
105
|
+
amd64; ARM hosts need amd64 emulation.
|
|
106
|
+
|
|
107
|
+
For a remote deployment, use the HTTPS URL and authentication configured by
|
|
108
|
+
your deployment operator. The SDK's `token` argument sends an optional HTTP
|
|
109
|
+
Bearer token; it does not configure the server's authentication or perform
|
|
110
|
+
Lorebo broker OAuth sign-in. Keep the native server behind the authenticated
|
|
111
|
+
deployment perimeter. No provider API key or Lorebo credential belongs in source
|
|
112
|
+
code; configure model-provider credentials through the provider's environment
|
|
113
|
+
settings.
|
|
114
|
+
|
|
115
|
+
## Quick start
|
|
116
|
+
|
|
117
|
+
### Python
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pip install "lorebo-sdk[openai]"
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The extra installs the model provider. `anthropic`, `google`, `groq`,
|
|
124
|
+
`mistral` and `bedrock` are available too.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
import asyncio
|
|
128
|
+
|
|
129
|
+
from lorebo_sdk.client import Lorebo
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
async def main() -> None:
|
|
133
|
+
lorebo = Lorebo.from_url(
|
|
134
|
+
url="http://127.0.0.1:8757/mcp",
|
|
135
|
+
token=None,
|
|
136
|
+
model="openai:gpt-5-mini",
|
|
137
|
+
base_ref="local:your-entry-id",
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
captured = await lorebo.capture("Our API listens on port 8757, on loopback only.")
|
|
141
|
+
print(captured.summary)
|
|
142
|
+
|
|
143
|
+
explored = await lorebo.explore("Which port does our API use?")
|
|
144
|
+
print(explored.answer)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
asyncio.run(main())
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`model` accepts any [Pydantic AI](https://ai.pydantic.dev/models/) model or model name.
|
|
151
|
+
|
|
152
|
+
### TypeScript
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
npm install lorebo-sdk ai @ai-sdk/openai
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
import { openai } from "@ai-sdk/openai";
|
|
160
|
+
import { createLorebo } from "lorebo-sdk";
|
|
161
|
+
|
|
162
|
+
const lorebo = createLorebo({
|
|
163
|
+
url: "http://127.0.0.1:8757/mcp",
|
|
164
|
+
token: null,
|
|
165
|
+
model: openai("gpt-5-mini"),
|
|
166
|
+
baseRef: "local:your-entry-id",
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const captured = await lorebo.capture("Our API listens on port 8757, on loopback only.");
|
|
170
|
+
console.log(captured.summary);
|
|
171
|
+
|
|
172
|
+
const explored = await lorebo.explore("Which port does our API use?");
|
|
173
|
+
console.log(explored.answer);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
`model` accepts any [AI SDK](https://ai-sdk.dev/providers) language model.
|
|
177
|
+
|
|
178
|
+
## Results
|
|
179
|
+
|
|
180
|
+
`capture` returns what changed in Lorebo:
|
|
181
|
+
|
|
182
|
+
| Field | Meaning |
|
|
183
|
+
| --------- | ----------------------------------- |
|
|
184
|
+
| `summary` | One or two sentences for your user. |
|
|
185
|
+
| `created` | Pages this call created. |
|
|
186
|
+
| `updated` | Existing pages this call changed. |
|
|
187
|
+
|
|
188
|
+
`explore` returns the answer and its sources:
|
|
189
|
+
|
|
190
|
+
| Field | Meaning |
|
|
191
|
+
| --------- | --------------------------------------------------- |
|
|
192
|
+
| `answer` | Plain-text answer for your user. |
|
|
193
|
+
| `sources` | Pages the answer relies on, each read in this call. |
|
|
194
|
+
|
|
195
|
+
Each page has an `id`, a `title` and the `base_ref` (`baseRef` in TypeScript)
|
|
196
|
+
of the base that holds it. The SDK builds these lists from Lorebo's responses,
|
|
197
|
+
not from the model's text, so they only contain pages that exist.
|
|
198
|
+
|
|
199
|
+
Summaries and answers are plain text written for your user, without the model's
|
|
200
|
+
reasoning, tool names or page IDs. Nothing is printed to your console.
|
|
201
|
+
|
|
202
|
+
## Choosing a base
|
|
203
|
+
|
|
204
|
+
A Lorebo installation can hold several knowledge bases. Pass `base_ref` to
|
|
205
|
+
lock every call to one of them:
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
lorebo = Lorebo.from_url(..., base_ref="local:your-entry-id")
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
When the model tries to use another base, the call stops with
|
|
212
|
+
`LockedBaseError` before anything is written there.
|
|
213
|
+
|
|
214
|
+
With multi-base permissions, pass `None` (`null` in TypeScript) to let the skill choose. `capture` then
|
|
215
|
+
picks the base the knowledge belongs to, or creates one when none fits.
|
|
216
|
+
`explore` picks the base that holds the answer.
|
|
217
|
+
|
|
218
|
+
For a local Headless container, run `docker exec lorebo lorebo-headless --json
|
|
219
|
+
base list` and use `local:<entry_id>` for the active base. Desktop also displays
|
|
220
|
+
the base reference on Base Home. Use the registry entry ID, not the database's
|
|
221
|
+
logical base ID.
|
|
222
|
+
|
|
223
|
+
When the server exposes multi-base MCP tools, list bases with an unlocked client:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
for base in await lorebo.list_bases():
|
|
227
|
+
print(base.base_ref, base.label)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
for (const base of await lorebo.listBases()) {
|
|
232
|
+
console.log(base.baseRef, base.label);
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
`create_base` (`createBase` in TypeScript) creates a base from your code.
|
|
237
|
+
Actions remain subject to the connected runtime's account entitlements and
|
|
238
|
+
agent permissions for each base.
|
|
239
|
+
On Free, lock the client to the active base; multi-base discovery and base
|
|
240
|
+
creation through MCP require the corresponding Pro permissions.
|
|
241
|
+
|
|
242
|
+
## What the model can do
|
|
243
|
+
|
|
244
|
+
The model only sees the Lorebo tools its skill needs:
|
|
245
|
+
|
|
246
|
+
- `explore` can read and search pages.
|
|
247
|
+
- `capture` can also create, update and link pages.
|
|
248
|
+
- Without a locked base, both can list bases and `capture` can create one when
|
|
249
|
+
the connected runtime exposes and permits those tools.
|
|
250
|
+
|
|
251
|
+
Tools that delete pages, delete bases, restore backups or change sharing are
|
|
252
|
+
never offered.
|
|
253
|
+
|
|
254
|
+
## Errors
|
|
255
|
+
|
|
256
|
+
Every SDK error extends `LoreboError`:
|
|
257
|
+
|
|
258
|
+
| Error | Raised when |
|
|
259
|
+
| ------------------- | -------------------------------------------------------------- |
|
|
260
|
+
| `LockedBaseError` | The model tried to use a base other than the locked one. |
|
|
261
|
+
| `LoreboToolError` | Lorebo rejected a call or returned an unexpected response. |
|
|
262
|
+
| `RunLimitError` | The skill did not finish within the step limit of 24. |
|
|
263
|
+
| `SkillPackageError` | A Lorebo skill could not be downloaded or failed verification. |
|
|
264
|
+
|
|
265
|
+
Python imports them from `lorebo_sdk.errors`, TypeScript from `lorebo-sdk/errors`.
|
|
266
|
+
Errors from the model provider are passed through unchanged.
|
|
267
|
+
|
|
268
|
+
## Lorebo skills
|
|
269
|
+
|
|
270
|
+
Each SDK release is pinned to one version of the official `lorebo-capture`
|
|
271
|
+
and `lorebo-explore` skills. They are downloaded from `downloads.lorebo.com`
|
|
272
|
+
on first use, checked against a SHA-256 digest built into the SDK and kept in
|
|
273
|
+
memory for the life of the client.
|
|
274
|
+
|
|
275
|
+
## Development
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
uv sync
|
|
279
|
+
uv run mypy
|
|
280
|
+
uv run ruff check .
|
|
281
|
+
uv run pytest
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
cd typescript
|
|
286
|
+
npm ci
|
|
287
|
+
npm run check
|
|
288
|
+
npm run build
|
|
289
|
+
npm pack --dry-run
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Package publication is described in
|
|
293
|
+
[Releasing](https://github.com/lexrag/lorebo-sdk/blob/main/docs/releasing.md).
|
|
294
|
+
|
|
295
|
+
## License
|
|
296
|
+
|
|
297
|
+
[MIT](https://github.com/lexrag/lorebo-sdk/blob/main/LICENSE)
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/lexrag/lorebo-sdk">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/lexrag/lorebo-sdk/main/assets/lorebo-logo-on-dark.svg">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/lexrag/lorebo-sdk/main/assets/lorebo-logo-primary.svg" width="264" alt="Lorebo">
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<h1 align="center">Lorebo SDK</h1>
|
|
11
|
+
|
|
12
|
+
<p align="center"><strong>Give your application a knowledge base that people and AI share.</strong></p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://github.com/lexrag/lorebo-sdk/actions/workflows/check.yml"><img src="https://github.com/lexrag/lorebo-sdk/actions/workflows/check.yml/badge.svg" alt="Checks"></a>
|
|
16
|
+
<a href="https://github.com/lexrag/lorebo-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-593EDC" alt="MIT license"></a>
|
|
17
|
+
<a href="https://pypi.org/project/lorebo-sdk/"><img src="https://img.shields.io/badge/Python-3.12+-3776AB" alt="Python 3.12+"></a>
|
|
18
|
+
<a href="https://www.npmjs.com/package/lorebo-sdk"><img src="https://img.shields.io/badge/TypeScript-Node_22+-3178C6" alt="TypeScript, Node 22+"></a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#quick-start">Quick start</a> ·
|
|
23
|
+
<a href="#results">Results</a> ·
|
|
24
|
+
<a href="#choosing-a-base">Choosing a base</a> ·
|
|
25
|
+
<a href="#errors">Errors</a> ·
|
|
26
|
+
<a href="#connecting-to-lorebo">Connecting to Lorebo</a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
Lorebo turns useful AI work into knowledge you own:
|
|
30
|
+
readable, connected pages that people and AI agents can find, correct and reuse.
|
|
31
|
+
|
|
32
|
+
The Lorebo SDK lets your application use that knowledge with two calls:
|
|
33
|
+
|
|
34
|
+
- **`capture`** saves the durable part of a text as Lorebo pages. It searches
|
|
35
|
+
first, updates pages that already cover the topic and creates the rest.
|
|
36
|
+
- **`explore`** answers a question from the pages in Lorebo and returns the
|
|
37
|
+
pages the answer relies on.
|
|
38
|
+
|
|
39
|
+
Both calls run the official Lorebo skills with the language model you choose.
|
|
40
|
+
The SDK is available for Python and TypeScript with the same behavior.
|
|
41
|
+
|
|
42
|
+
## Requirements
|
|
43
|
+
|
|
44
|
+
- A Lorebo MCP endpoint:
|
|
45
|
+
- Lorebo Desktop serves `http://127.0.0.1:8757/mcp` on your machine.
|
|
46
|
+
- [Lorebo Headless](https://github.com/orgs/lexrag/packages/container/package/lorebo-headless) serves `http://127.0.0.1:8758/mcp` when run locally with the example below.
|
|
47
|
+
- A language model that supports tool calls and structured output.
|
|
48
|
+
- Python 3.12+ or Node.js 22+.
|
|
49
|
+
|
|
50
|
+
## Connecting to Lorebo
|
|
51
|
+
|
|
52
|
+
With Desktop already running, use its local MCP URL in the quick start.
|
|
53
|
+
To run Headless with Docker instead:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
docker run --detach --name lorebo \
|
|
57
|
+
--publish 127.0.0.1:8758:8758 \
|
|
58
|
+
--volume lorebo-data:/data \
|
|
59
|
+
ghcr.io/lexrag/lorebo-headless:stable
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Use `http://127.0.0.1:8758/mcp` as the SDK URL and `None` (`null` in
|
|
63
|
+
TypeScript) as the token. The volume preserves your bases when the container
|
|
64
|
+
is recreated. Back up the complete volume before upgrading and stop the old
|
|
65
|
+
container before starting another writer on it. The official image is Linux
|
|
66
|
+
amd64; ARM hosts need amd64 emulation.
|
|
67
|
+
|
|
68
|
+
For a remote deployment, use the HTTPS URL and authentication configured by
|
|
69
|
+
your deployment operator. The SDK's `token` argument sends an optional HTTP
|
|
70
|
+
Bearer token; it does not configure the server's authentication or perform
|
|
71
|
+
Lorebo broker OAuth sign-in. Keep the native server behind the authenticated
|
|
72
|
+
deployment perimeter. No provider API key or Lorebo credential belongs in source
|
|
73
|
+
code; configure model-provider credentials through the provider's environment
|
|
74
|
+
settings.
|
|
75
|
+
|
|
76
|
+
## Quick start
|
|
77
|
+
|
|
78
|
+
### Python
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install "lorebo-sdk[openai]"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The extra installs the model provider. `anthropic`, `google`, `groq`,
|
|
85
|
+
`mistral` and `bedrock` are available too.
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import asyncio
|
|
89
|
+
|
|
90
|
+
from lorebo_sdk.client import Lorebo
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
async def main() -> None:
|
|
94
|
+
lorebo = Lorebo.from_url(
|
|
95
|
+
url="http://127.0.0.1:8757/mcp",
|
|
96
|
+
token=None,
|
|
97
|
+
model="openai:gpt-5-mini",
|
|
98
|
+
base_ref="local:your-entry-id",
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
captured = await lorebo.capture("Our API listens on port 8757, on loopback only.")
|
|
102
|
+
print(captured.summary)
|
|
103
|
+
|
|
104
|
+
explored = await lorebo.explore("Which port does our API use?")
|
|
105
|
+
print(explored.answer)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
asyncio.run(main())
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`model` accepts any [Pydantic AI](https://ai.pydantic.dev/models/) model or model name.
|
|
112
|
+
|
|
113
|
+
### TypeScript
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
npm install lorebo-sdk ai @ai-sdk/openai
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { openai } from "@ai-sdk/openai";
|
|
121
|
+
import { createLorebo } from "lorebo-sdk";
|
|
122
|
+
|
|
123
|
+
const lorebo = createLorebo({
|
|
124
|
+
url: "http://127.0.0.1:8757/mcp",
|
|
125
|
+
token: null,
|
|
126
|
+
model: openai("gpt-5-mini"),
|
|
127
|
+
baseRef: "local:your-entry-id",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const captured = await lorebo.capture("Our API listens on port 8757, on loopback only.");
|
|
131
|
+
console.log(captured.summary);
|
|
132
|
+
|
|
133
|
+
const explored = await lorebo.explore("Which port does our API use?");
|
|
134
|
+
console.log(explored.answer);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`model` accepts any [AI SDK](https://ai-sdk.dev/providers) language model.
|
|
138
|
+
|
|
139
|
+
## Results
|
|
140
|
+
|
|
141
|
+
`capture` returns what changed in Lorebo:
|
|
142
|
+
|
|
143
|
+
| Field | Meaning |
|
|
144
|
+
| --------- | ----------------------------------- |
|
|
145
|
+
| `summary` | One or two sentences for your user. |
|
|
146
|
+
| `created` | Pages this call created. |
|
|
147
|
+
| `updated` | Existing pages this call changed. |
|
|
148
|
+
|
|
149
|
+
`explore` returns the answer and its sources:
|
|
150
|
+
|
|
151
|
+
| Field | Meaning |
|
|
152
|
+
| --------- | --------------------------------------------------- |
|
|
153
|
+
| `answer` | Plain-text answer for your user. |
|
|
154
|
+
| `sources` | Pages the answer relies on, each read in this call. |
|
|
155
|
+
|
|
156
|
+
Each page has an `id`, a `title` and the `base_ref` (`baseRef` in TypeScript)
|
|
157
|
+
of the base that holds it. The SDK builds these lists from Lorebo's responses,
|
|
158
|
+
not from the model's text, so they only contain pages that exist.
|
|
159
|
+
|
|
160
|
+
Summaries and answers are plain text written for your user, without the model's
|
|
161
|
+
reasoning, tool names or page IDs. Nothing is printed to your console.
|
|
162
|
+
|
|
163
|
+
## Choosing a base
|
|
164
|
+
|
|
165
|
+
A Lorebo installation can hold several knowledge bases. Pass `base_ref` to
|
|
166
|
+
lock every call to one of them:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
lorebo = Lorebo.from_url(..., base_ref="local:your-entry-id")
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
When the model tries to use another base, the call stops with
|
|
173
|
+
`LockedBaseError` before anything is written there.
|
|
174
|
+
|
|
175
|
+
With multi-base permissions, pass `None` (`null` in TypeScript) to let the skill choose. `capture` then
|
|
176
|
+
picks the base the knowledge belongs to, or creates one when none fits.
|
|
177
|
+
`explore` picks the base that holds the answer.
|
|
178
|
+
|
|
179
|
+
For a local Headless container, run `docker exec lorebo lorebo-headless --json
|
|
180
|
+
base list` and use `local:<entry_id>` for the active base. Desktop also displays
|
|
181
|
+
the base reference on Base Home. Use the registry entry ID, not the database's
|
|
182
|
+
logical base ID.
|
|
183
|
+
|
|
184
|
+
When the server exposes multi-base MCP tools, list bases with an unlocked client:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
for base in await lorebo.list_bases():
|
|
188
|
+
print(base.base_ref, base.label)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
for (const base of await lorebo.listBases()) {
|
|
193
|
+
console.log(base.baseRef, base.label);
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
`create_base` (`createBase` in TypeScript) creates a base from your code.
|
|
198
|
+
Actions remain subject to the connected runtime's account entitlements and
|
|
199
|
+
agent permissions for each base.
|
|
200
|
+
On Free, lock the client to the active base; multi-base discovery and base
|
|
201
|
+
creation through MCP require the corresponding Pro permissions.
|
|
202
|
+
|
|
203
|
+
## What the model can do
|
|
204
|
+
|
|
205
|
+
The model only sees the Lorebo tools its skill needs:
|
|
206
|
+
|
|
207
|
+
- `explore` can read and search pages.
|
|
208
|
+
- `capture` can also create, update and link pages.
|
|
209
|
+
- Without a locked base, both can list bases and `capture` can create one when
|
|
210
|
+
the connected runtime exposes and permits those tools.
|
|
211
|
+
|
|
212
|
+
Tools that delete pages, delete bases, restore backups or change sharing are
|
|
213
|
+
never offered.
|
|
214
|
+
|
|
215
|
+
## Errors
|
|
216
|
+
|
|
217
|
+
Every SDK error extends `LoreboError`:
|
|
218
|
+
|
|
219
|
+
| Error | Raised when |
|
|
220
|
+
| ------------------- | -------------------------------------------------------------- |
|
|
221
|
+
| `LockedBaseError` | The model tried to use a base other than the locked one. |
|
|
222
|
+
| `LoreboToolError` | Lorebo rejected a call or returned an unexpected response. |
|
|
223
|
+
| `RunLimitError` | The skill did not finish within the step limit of 24. |
|
|
224
|
+
| `SkillPackageError` | A Lorebo skill could not be downloaded or failed verification. |
|
|
225
|
+
|
|
226
|
+
Python imports them from `lorebo_sdk.errors`, TypeScript from `lorebo-sdk/errors`.
|
|
227
|
+
Errors from the model provider are passed through unchanged.
|
|
228
|
+
|
|
229
|
+
## Lorebo skills
|
|
230
|
+
|
|
231
|
+
Each SDK release is pinned to one version of the official `lorebo-capture`
|
|
232
|
+
and `lorebo-explore` skills. They are downloaded from `downloads.lorebo.com`
|
|
233
|
+
on first use, checked against a SHA-256 digest built into the SDK and kept in
|
|
234
|
+
memory for the life of the client.
|
|
235
|
+
|
|
236
|
+
## Development
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
uv sync
|
|
240
|
+
uv run mypy
|
|
241
|
+
uv run ruff check .
|
|
242
|
+
uv run pytest
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
cd typescript
|
|
247
|
+
npm ci
|
|
248
|
+
npm run check
|
|
249
|
+
npm run build
|
|
250
|
+
npm pack --dry-run
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Package publication is described in
|
|
254
|
+
[Releasing](https://github.com/lexrag/lorebo-sdk/blob/main/docs/releasing.md).
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
[MIT](https://github.com/lexrag/lorebo-sdk/blob/main/LICENSE)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "lorebo-sdk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Save and retrieve Lorebo knowledge from your application with any LLM"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{ name = "LexRAG" }]
|
|
13
|
+
requires-python = ">=3.12"
|
|
14
|
+
keywords = ["lorebo", "knowledge-base", "mcp", "llm", "agents", "pydantic-ai"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Framework :: AsyncIO",
|
|
22
|
+
"Framework :: Pydantic",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"fastmcp-slim[client]>=4.1",
|
|
27
|
+
"httpx>=0.28",
|
|
28
|
+
"pydantic>=2.11",
|
|
29
|
+
"pydantic-ai-slim[mcp]>=2.59",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
openai = ["pydantic-ai-slim[openai]>=2.59"]
|
|
34
|
+
anthropic = ["pydantic-ai-slim[anthropic]>=2.59"]
|
|
35
|
+
google = ["pydantic-ai-slim[google]>=2.59"]
|
|
36
|
+
groq = ["pydantic-ai-slim[groq]>=2.59"]
|
|
37
|
+
mistral = ["pydantic-ai-slim[mistral]>=2.59"]
|
|
38
|
+
bedrock = ["pydantic-ai-slim[bedrock]>=2.59"]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/lexrag/lorebo-sdk"
|
|
42
|
+
Documentation = "https://github.com/lexrag/lorebo-sdk#quick-start"
|
|
43
|
+
Repository = "https://github.com/lexrag/lorebo-sdk"
|
|
44
|
+
Issues = "https://github.com/lexrag/lorebo-sdk/issues"
|
|
45
|
+
|
|
46
|
+
[dependency-groups]
|
|
47
|
+
dev = [
|
|
48
|
+
"fastmcp-slim[server]>=4.1",
|
|
49
|
+
"mypy>=1.17",
|
|
50
|
+
"pytest>=8.4",
|
|
51
|
+
"pytest-asyncio>=1.0",
|
|
52
|
+
"ruff>=0.12",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.wheel]
|
|
56
|
+
packages = ["src/lorebo_sdk"]
|
|
57
|
+
|
|
58
|
+
[tool.hatch.build.targets.sdist]
|
|
59
|
+
include = ["src/lorebo_sdk", "tests", "README.md", "LICENSE"]
|
|
60
|
+
|
|
61
|
+
[tool.pytest.ini_options]
|
|
62
|
+
asyncio_mode = "auto"
|
|
63
|
+
testpaths = ["tests"]
|
|
64
|
+
|
|
65
|
+
[tool.mypy]
|
|
66
|
+
strict = true
|
|
67
|
+
files = ["src", "tests"]
|
|
68
|
+
|
|
69
|
+
[tool.ruff]
|
|
70
|
+
line-length = 100
|
|
71
|
+
target-version = "py312"
|
|
72
|
+
|
|
73
|
+
[tool.ruff.lint]
|
|
74
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
File without changes
|