olbrain-python-sdk 0.3.1__tar.gz → 0.3.2__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.
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/MANIFEST.in +1 -1
- {olbrain_python_sdk-0.3.1/olbrain_python_sdk.egg-info → olbrain_python_sdk-0.3.2}/PKG-INFO +13 -11
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/README.md +8 -6
- olbrain_python_sdk-0.3.2/olbrain/AGENTS.md +167 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain/__init__.py +3 -1
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2/olbrain_python_sdk.egg-info}/PKG-INFO +13 -11
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain_python_sdk.egg-info/SOURCES.txt +1 -1
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain_python_sdk.egg-info/top_level.txt +0 -1
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/pyproject.toml +6 -3
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/setup.py +6 -5
- olbrain_python_sdk-0.3.1/test_agent.py +0 -143
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/.gitignore +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/LICENSE +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/examples/advanced_features.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/examples/basic_usage.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/examples/error_handling.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/examples/session_management.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/examples/streaming_responses.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain/client.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain/exceptions.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain/session.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain/streaming.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain/utils.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain_python_sdk.egg-info/dependency_links.txt +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain_python_sdk.egg-info/not-zip-safe +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain_python_sdk.egg-info/requires.txt +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/requirements.txt +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/setup.cfg +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/tests/__init__.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/tests/test_client.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/tests/test_exceptions.py +0 -0
- {olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/tests/test_session.py +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: olbrain-python-sdk
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Official Python SDK for Olbrain AI agents
|
|
5
|
-
Home-page: https://github.com/Olbrain/olbrain-
|
|
5
|
+
Home-page: https://github.com/Olbrain/olbrain-sdk
|
|
6
6
|
Author: Olbrain Team
|
|
7
7
|
Author-email: Olbrain Team <support@olbrain.com>
|
|
8
8
|
License: MIT
|
|
9
|
-
Project-URL: Homepage, https://github.com/Olbrain/olbrain-python
|
|
10
|
-
Project-URL: Bug Reports, https://github.com/Olbrain/olbrain-
|
|
11
|
-
Project-URL: Source, https://github.com/Olbrain/olbrain-
|
|
9
|
+
Project-URL: Homepage, https://github.com/Olbrain/olbrain-sdk/tree/main/packages/python
|
|
10
|
+
Project-URL: Bug Reports, https://github.com/Olbrain/olbrain-sdk/issues
|
|
11
|
+
Project-URL: Source, https://github.com/Olbrain/olbrain-sdk
|
|
12
12
|
Project-URL: Documentation, https://docs.olbrain.com/python-sdk
|
|
13
13
|
Keywords: olbrain,ai,agents,chatbot,nlp,artificial intelligence,sdk,api,conversation,streaming
|
|
14
14
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -54,6 +54,8 @@ Dynamic: requires-python
|
|
|
54
54
|
|
|
55
55
|
Official Python SDK for integrating Olbrain AI agents into your applications.
|
|
56
56
|
|
|
57
|
+
> **Coding assistants:** the complete API reference ships in the package as [`olbrain/AGENTS.md`](olbrain/AGENTS.md) (`site-packages/olbrain/AGENTS.md`).
|
|
58
|
+
|
|
57
59
|
## Installation
|
|
58
60
|
|
|
59
61
|
```bash
|
|
@@ -66,8 +68,8 @@ For local development and testing:
|
|
|
66
68
|
|
|
67
69
|
```bash
|
|
68
70
|
# Clone the repository
|
|
69
|
-
git clone https://github.com/Olbrain/olbrain-
|
|
70
|
-
cd olbrain-python
|
|
71
|
+
git clone https://github.com/Olbrain/olbrain-sdk.git
|
|
72
|
+
cd olbrain-sdk/packages/python
|
|
71
73
|
|
|
72
74
|
# Create virtual environment
|
|
73
75
|
python3 -m venv venv
|
|
@@ -315,7 +317,7 @@ The SDK validates API keys. Valid prefixes are:
|
|
|
315
317
|
# Valid API key
|
|
316
318
|
client = AgentClient(
|
|
317
319
|
agent_id="your-agent-id",
|
|
318
|
-
api_key="
|
|
320
|
+
api_key="sk_live_your_api_key_here"
|
|
319
321
|
)
|
|
320
322
|
```
|
|
321
323
|
|
|
@@ -509,7 +511,7 @@ python examples/basic_usage.py
|
|
|
509
511
|
|
|
510
512
|
## Support
|
|
511
513
|
|
|
512
|
-
- **Issues**: [GitHub Issues](https://github.com/Olbrain/olbrain-
|
|
514
|
+
- **Issues**: [GitHub Issues](https://github.com/Olbrain/olbrain-sdk/issues)
|
|
513
515
|
- **Documentation**: See [examples/](examples/) directory
|
|
514
516
|
- **API Status**: Check [status page](https://olbrain.com/status)
|
|
515
517
|
|
|
@@ -524,6 +526,6 @@ Current version: **0.2.0**
|
|
|
524
526
|
## Links
|
|
525
527
|
|
|
526
528
|
- [PyPI Package](https://pypi.org/project/olbrain-python-sdk/)
|
|
527
|
-
- [GitHub Repository](https://github.com/Olbrain/olbrain-
|
|
528
|
-
- [Report Issues](https://github.com/Olbrain/olbrain-
|
|
529
|
+
- [GitHub Repository](https://github.com/Olbrain/olbrain-sdk)
|
|
530
|
+
- [Report Issues](https://github.com/Olbrain/olbrain-sdk/issues)
|
|
529
531
|
- [Olbrain Website](https://olbrain.com)
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
Official Python SDK for integrating Olbrain AI agents into your applications.
|
|
8
8
|
|
|
9
|
+
> **Coding assistants:** the complete API reference ships in the package as [`olbrain/AGENTS.md`](olbrain/AGENTS.md) (`site-packages/olbrain/AGENTS.md`).
|
|
10
|
+
|
|
9
11
|
## Installation
|
|
10
12
|
|
|
11
13
|
```bash
|
|
@@ -18,8 +20,8 @@ For local development and testing:
|
|
|
18
20
|
|
|
19
21
|
```bash
|
|
20
22
|
# Clone the repository
|
|
21
|
-
git clone https://github.com/Olbrain/olbrain-
|
|
22
|
-
cd olbrain-python
|
|
23
|
+
git clone https://github.com/Olbrain/olbrain-sdk.git
|
|
24
|
+
cd olbrain-sdk/packages/python
|
|
23
25
|
|
|
24
26
|
# Create virtual environment
|
|
25
27
|
python3 -m venv venv
|
|
@@ -267,7 +269,7 @@ The SDK validates API keys. Valid prefixes are:
|
|
|
267
269
|
# Valid API key
|
|
268
270
|
client = AgentClient(
|
|
269
271
|
agent_id="your-agent-id",
|
|
270
|
-
api_key="
|
|
272
|
+
api_key="sk_live_your_api_key_here"
|
|
271
273
|
)
|
|
272
274
|
```
|
|
273
275
|
|
|
@@ -461,7 +463,7 @@ python examples/basic_usage.py
|
|
|
461
463
|
|
|
462
464
|
## Support
|
|
463
465
|
|
|
464
|
-
- **Issues**: [GitHub Issues](https://github.com/Olbrain/olbrain-
|
|
466
|
+
- **Issues**: [GitHub Issues](https://github.com/Olbrain/olbrain-sdk/issues)
|
|
465
467
|
- **Documentation**: See [examples/](examples/) directory
|
|
466
468
|
- **API Status**: Check [status page](https://olbrain.com/status)
|
|
467
469
|
|
|
@@ -476,6 +478,6 @@ Current version: **0.2.0**
|
|
|
476
478
|
## Links
|
|
477
479
|
|
|
478
480
|
- [PyPI Package](https://pypi.org/project/olbrain-python-sdk/)
|
|
479
|
-
- [GitHub Repository](https://github.com/Olbrain/olbrain-
|
|
480
|
-
- [Report Issues](https://github.com/Olbrain/olbrain-
|
|
481
|
+
- [GitHub Repository](https://github.com/Olbrain/olbrain-sdk)
|
|
482
|
+
- [Report Issues](https://github.com/Olbrain/olbrain-sdk/issues)
|
|
481
483
|
- [Olbrain Website](https://olbrain.com)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# olbrain-python-sdk — reference for coding assistants
|
|
2
|
+
|
|
3
|
+
This file ships inside the installed package (`site-packages/olbrain/AGENTS.md`).
|
|
4
|
+
It is the complete, offline reference for the public API. Everything here is
|
|
5
|
+
taken from the source. If it disagrees with the web docs, this file is right.
|
|
6
|
+
|
|
7
|
+
Find it from Python with:
|
|
8
|
+
`python -c "import olbrain, os; print(os.path.join(os.path.dirname(olbrain.__file__), 'AGENTS.md'))"`
|
|
9
|
+
|
|
10
|
+
The Python SDK covers **conversational agents** only (`AgentClient`). Workflow
|
|
11
|
+
runs, approvals and research agents are available only in the JavaScript SDK
|
|
12
|
+
(`@olbrain/js-sdk`, class `Olbrain`).
|
|
13
|
+
|
|
14
|
+
## Install and import
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install olbrain-python-sdk # import name: olbrain. Requires Python 3.7+ and requests.
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from olbrain import AgentClient, ChatResponse, OlbrainError
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import os
|
|
28
|
+
from olbrain import AgentClient
|
|
29
|
+
|
|
30
|
+
with AgentClient(agent_id="your-agent-id", api_key=os.environ["OLBRAIN_API_KEY"]) as client:
|
|
31
|
+
session_id = client.create_session(title="Support chat", user_id="u_42")
|
|
32
|
+
reply = client.send_and_wait(session_id, "Hello!")
|
|
33
|
+
if reply.success:
|
|
34
|
+
print(reply.text)
|
|
35
|
+
else:
|
|
36
|
+
print("agent error:", reply.error)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The client is synchronous and uses `requests`.
|
|
40
|
+
|
|
41
|
+
## `AgentClient(agent_id, api_key, agent_url=None)`
|
|
42
|
+
|
|
43
|
+
- `agent_id`: required. An empty value raises `ValueError`.
|
|
44
|
+
- `api_key`: must start with `sk_live_`, `org_live_`, `sk_` or `org_`, or the
|
|
45
|
+
constructor raises `ValueError`. `ak_` keys are **not** accepted here.
|
|
46
|
+
- `agent_url`: optional. Defaults to `https://olbrain-agent-cloud-768934887465.us-central1.run.app`.
|
|
47
|
+
|
|
48
|
+
Every call is a `POST {agent_url}/api/agent/webhook` with headers
|
|
49
|
+
`Authorization: Bearer <api_key>` and `X-Agent-ID: <agent_id>`. The client is a
|
|
50
|
+
context manager, and `__exit__` calls `close()`.
|
|
51
|
+
|
|
52
|
+
### Methods
|
|
53
|
+
|
|
54
|
+
| Method | Returns | Notes |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `create_session(on_message=None, title=None, user_id=None, metadata=None, mode="production", description=None)` | `str` session id | Sends `title` (default `"New Session"`) to the agent **as the first message**. `mode` must be `"development"`, `"testing"` or `"production"`, otherwise `ValueError`. `description` is stored as `metadata["session_description"]`. If you pass `on_message`, it also calls `listen()`. Timeout 30 s. |
|
|
57
|
+
| `send_and_wait(session_id, message, user_id=None, metadata=None, model=None, timeout=120)` | `ChatResponse` | Waits for the reply. `timeout` is in **seconds**. `model` overrides the agent's model. Empty or whitespace-only messages raise `ValueError`. |
|
|
58
|
+
| `send(session_id, message, user_id=None, metadata=None, model=None, mode="production")` | `dict` (raw JSON) | Same request, but returns the raw response dict (`response`, `token_usage`, `success`, …). It still blocks, with a 120 s timeout. |
|
|
59
|
+
| `listen(session_id, on_message)` | `None` | Starts a background daemon thread that reads SSE from `GET {agent_url}/sessions/{id}/stream`. It reconnects with backoff from 5 s up to 60 s. Calling it again for the same session does nothing. |
|
|
60
|
+
| `run()` | `None` | Blocks until Ctrl+C, then calls `close()`. Use it to keep a script alive for `listen` callbacks. |
|
|
61
|
+
| `close()` | `None` | Stops all streams. |
|
|
62
|
+
| `get_session(session_id)` | `SessionInfo` | Needs backend support (webhook `action: get_session_info`). |
|
|
63
|
+
| `update_session(session_id, title=None, metadata=None, status=None)` | `SessionInfo` | `status` must be `"active"` or `"archived"`. |
|
|
64
|
+
| `delete_session(session_id)` | `dict` | Also stops that session's stream. |
|
|
65
|
+
| `get_session_stats(session_id)` | `dict` | |
|
|
66
|
+
| `get_messages(session_id, limit=20, offset=0)` | `dict` | The messages list and pagination info, as the backend returns them. |
|
|
67
|
+
|
|
68
|
+
The five session-management methods (`get_session` through `get_messages`)
|
|
69
|
+
depend on webhook `action`s that not every backend implements. They raise if
|
|
70
|
+
the backend refuses. Only `create_session`, `send_and_wait` and `send` are
|
|
71
|
+
guaranteed to work.
|
|
72
|
+
|
|
73
|
+
### Streaming callback
|
|
74
|
+
|
|
75
|
+
`on_message` gets the **raw dict** from each SSE frame that has a `content`
|
|
76
|
+
key. Frames whose `type` is `ping` or `connected` are skipped. The callback
|
|
77
|
+
runs on the stream thread, so keep it fast and don't raise from it.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
def on_message(msg: dict):
|
|
81
|
+
print(f"{msg.get('role')}: {msg['content']}")
|
|
82
|
+
|
|
83
|
+
client = AgentClient(agent_id="…", api_key="sk_live_…")
|
|
84
|
+
sid = client.create_session(on_message=on_message, title="Streaming chat")
|
|
85
|
+
client.send(sid, "Tell me a story")
|
|
86
|
+
client.run() # blocks; Ctrl+C to stop
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Data classes (`olbrain.session`, re-exported from `olbrain`)
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
@dataclass
|
|
93
|
+
class ChatResponse:
|
|
94
|
+
text: str
|
|
95
|
+
session_id: str
|
|
96
|
+
success: bool = True
|
|
97
|
+
token_usage: Optional[TokenUsage] = None # None if the server sent none
|
|
98
|
+
model_used: Optional[str] = None
|
|
99
|
+
response_time_ms: Optional[int] = None
|
|
100
|
+
metadata: Optional[dict] = None
|
|
101
|
+
error: Optional[str] = None
|
|
102
|
+
# ChatResponse.from_dict(data, session_id=""), .to_dict()
|
|
103
|
+
|
|
104
|
+
@dataclass
|
|
105
|
+
class TokenUsage:
|
|
106
|
+
prompt_tokens: int = 0
|
|
107
|
+
completion_tokens: int = 0
|
|
108
|
+
total_tokens: int = 0
|
|
109
|
+
cost: float = 0.0
|
|
110
|
+
|
|
111
|
+
@dataclass
|
|
112
|
+
class SessionInfo:
|
|
113
|
+
session_id: str
|
|
114
|
+
title: str = ""
|
|
115
|
+
status: str = "active" # "active" | "archived"
|
|
116
|
+
created_at: str = ""
|
|
117
|
+
updated_at: str = ""
|
|
118
|
+
message_count: int = 0
|
|
119
|
+
user_id: Optional[str] = None
|
|
120
|
+
channel: str = "api"
|
|
121
|
+
metadata: dict = {}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`token_usage` can be `None`, so guard before reading it:
|
|
125
|
+
`reply.token_usage.total_tokens if reply.token_usage else 0`. Always check
|
|
126
|
+
`reply.success` too. A 200 response can carry `success=False` and an `error`.
|
|
127
|
+
|
|
128
|
+
Avoid the exported `Message` and `Session` classes. Nothing in the client
|
|
129
|
+
returns them, and `Session.get_stats()` always falls back to local data.
|
|
130
|
+
|
|
131
|
+
## Errors (`olbrain.exceptions`)
|
|
132
|
+
|
|
133
|
+
All of them subclass `OlbrainError`, which has `.message`, `.error_code` and
|
|
134
|
+
`.details`.
|
|
135
|
+
|
|
136
|
+
| Condition | Raised |
|
|
137
|
+
|---|---|
|
|
138
|
+
| Bad constructor args, empty message, bad `mode`/`status` | `ValueError` (**not** `ValidationError`) |
|
|
139
|
+
| HTTP 401 | `AuthenticationError` |
|
|
140
|
+
| HTTP 404 whose detail mentions "session" | `SessionNotFoundError` (a subclass of `SessionError`) |
|
|
141
|
+
| Other HTTP 404 | `OlbrainError` ("Endpoint not found (404) …") |
|
|
142
|
+
| HTTP 429 | `RateLimitError` (`.retry_after` from `detail.retry_after`, may be `None`) |
|
|
143
|
+
| Any other non-200 (403, 5xx…) | `OlbrainError("Failed to <operation>: <status> - <detail>")` |
|
|
144
|
+
| Connection error or timeout | `NetworkError` |
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from olbrain import AgentClient, AuthenticationError, RateLimitError, NetworkError, OlbrainError
|
|
148
|
+
import time
|
|
149
|
+
|
|
150
|
+
def ask(client, sid, text, tries=3):
|
|
151
|
+
for i in range(tries):
|
|
152
|
+
try:
|
|
153
|
+
return client.send_and_wait(sid, text)
|
|
154
|
+
except RateLimitError as e:
|
|
155
|
+
time.sleep(e.retry_after or 2 ** i)
|
|
156
|
+
except NetworkError:
|
|
157
|
+
time.sleep(2 ** i)
|
|
158
|
+
raise OlbrainError("gave up")
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`ValidationError` and `StreamingError` are exported, but the client never
|
|
162
|
+
raises them.
|
|
163
|
+
|
|
164
|
+
## Logging
|
|
165
|
+
|
|
166
|
+
The SDK logs through `logging.getLogger("olbrain")`. Turn on
|
|
167
|
+
`logging.basicConfig(level=logging.DEBUG)` to see requests and stream events.
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Olbrain Python SDK
|
|
3
3
|
Simple client for Olbrain AI agents with real-time message streaming
|
|
4
4
|
|
|
5
|
+
Full offline API reference: AGENTS.md next to this file.
|
|
6
|
+
|
|
5
7
|
Example:
|
|
6
8
|
>>> from olbrain import AgentClient
|
|
7
9
|
>>>
|
|
@@ -33,7 +35,7 @@ from .exceptions import (
|
|
|
33
35
|
StreamingError
|
|
34
36
|
)
|
|
35
37
|
|
|
36
|
-
__version__ = "0.3.
|
|
38
|
+
__version__ = "0.3.2"
|
|
37
39
|
__author__ = "Olbrain Team"
|
|
38
40
|
__email__ = "support@olbrain.com"
|
|
39
41
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: olbrain-python-sdk
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Official Python SDK for Olbrain AI agents
|
|
5
|
-
Home-page: https://github.com/Olbrain/olbrain-
|
|
5
|
+
Home-page: https://github.com/Olbrain/olbrain-sdk
|
|
6
6
|
Author: Olbrain Team
|
|
7
7
|
Author-email: Olbrain Team <support@olbrain.com>
|
|
8
8
|
License: MIT
|
|
9
|
-
Project-URL: Homepage, https://github.com/Olbrain/olbrain-python
|
|
10
|
-
Project-URL: Bug Reports, https://github.com/Olbrain/olbrain-
|
|
11
|
-
Project-URL: Source, https://github.com/Olbrain/olbrain-
|
|
9
|
+
Project-URL: Homepage, https://github.com/Olbrain/olbrain-sdk/tree/main/packages/python
|
|
10
|
+
Project-URL: Bug Reports, https://github.com/Olbrain/olbrain-sdk/issues
|
|
11
|
+
Project-URL: Source, https://github.com/Olbrain/olbrain-sdk
|
|
12
12
|
Project-URL: Documentation, https://docs.olbrain.com/python-sdk
|
|
13
13
|
Keywords: olbrain,ai,agents,chatbot,nlp,artificial intelligence,sdk,api,conversation,streaming
|
|
14
14
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -54,6 +54,8 @@ Dynamic: requires-python
|
|
|
54
54
|
|
|
55
55
|
Official Python SDK for integrating Olbrain AI agents into your applications.
|
|
56
56
|
|
|
57
|
+
> **Coding assistants:** the complete API reference ships in the package as [`olbrain/AGENTS.md`](olbrain/AGENTS.md) (`site-packages/olbrain/AGENTS.md`).
|
|
58
|
+
|
|
57
59
|
## Installation
|
|
58
60
|
|
|
59
61
|
```bash
|
|
@@ -66,8 +68,8 @@ For local development and testing:
|
|
|
66
68
|
|
|
67
69
|
```bash
|
|
68
70
|
# Clone the repository
|
|
69
|
-
git clone https://github.com/Olbrain/olbrain-
|
|
70
|
-
cd olbrain-python
|
|
71
|
+
git clone https://github.com/Olbrain/olbrain-sdk.git
|
|
72
|
+
cd olbrain-sdk/packages/python
|
|
71
73
|
|
|
72
74
|
# Create virtual environment
|
|
73
75
|
python3 -m venv venv
|
|
@@ -315,7 +317,7 @@ The SDK validates API keys. Valid prefixes are:
|
|
|
315
317
|
# Valid API key
|
|
316
318
|
client = AgentClient(
|
|
317
319
|
agent_id="your-agent-id",
|
|
318
|
-
api_key="
|
|
320
|
+
api_key="sk_live_your_api_key_here"
|
|
319
321
|
)
|
|
320
322
|
```
|
|
321
323
|
|
|
@@ -509,7 +511,7 @@ python examples/basic_usage.py
|
|
|
509
511
|
|
|
510
512
|
## Support
|
|
511
513
|
|
|
512
|
-
- **Issues**: [GitHub Issues](https://github.com/Olbrain/olbrain-
|
|
514
|
+
- **Issues**: [GitHub Issues](https://github.com/Olbrain/olbrain-sdk/issues)
|
|
513
515
|
- **Documentation**: See [examples/](examples/) directory
|
|
514
516
|
- **API Status**: Check [status page](https://olbrain.com/status)
|
|
515
517
|
|
|
@@ -524,6 +526,6 @@ Current version: **0.2.0**
|
|
|
524
526
|
## Links
|
|
525
527
|
|
|
526
528
|
- [PyPI Package](https://pypi.org/project/olbrain-python-sdk/)
|
|
527
|
-
- [GitHub Repository](https://github.com/Olbrain/olbrain-
|
|
528
|
-
- [Report Issues](https://github.com/Olbrain/olbrain-
|
|
529
|
+
- [GitHub Repository](https://github.com/Olbrain/olbrain-sdk)
|
|
530
|
+
- [Report Issues](https://github.com/Olbrain/olbrain-sdk/issues)
|
|
529
531
|
- [Olbrain Website](https://olbrain.com)
|
{olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain_python_sdk.egg-info/SOURCES.txt
RENAMED
|
@@ -5,12 +5,12 @@ README.md
|
|
|
5
5
|
pyproject.toml
|
|
6
6
|
requirements.txt
|
|
7
7
|
setup.py
|
|
8
|
-
test_agent.py
|
|
9
8
|
examples/advanced_features.py
|
|
10
9
|
examples/basic_usage.py
|
|
11
10
|
examples/error_handling.py
|
|
12
11
|
examples/session_management.py
|
|
13
12
|
examples/streaming_responses.py
|
|
13
|
+
olbrain/AGENTS.md
|
|
14
14
|
olbrain/__init__.py
|
|
15
15
|
olbrain/client.py
|
|
16
16
|
olbrain/exceptions.py
|
|
@@ -61,11 +61,14 @@ async = [
|
|
|
61
61
|
]
|
|
62
62
|
|
|
63
63
|
[project.urls]
|
|
64
|
-
"Homepage" = "https://github.com/Olbrain/olbrain-python
|
|
65
|
-
"Bug Reports" = "https://github.com/Olbrain/olbrain-
|
|
66
|
-
"Source" = "https://github.com/Olbrain/olbrain-
|
|
64
|
+
"Homepage" = "https://github.com/Olbrain/olbrain-sdk/tree/main/packages/python"
|
|
65
|
+
"Bug Reports" = "https://github.com/Olbrain/olbrain-sdk/issues"
|
|
66
|
+
"Source" = "https://github.com/Olbrain/olbrain-sdk"
|
|
67
67
|
"Documentation" = "https://docs.olbrain.com/python-sdk"
|
|
68
68
|
|
|
69
|
+
[tool.setuptools.package-data]
|
|
70
|
+
olbrain = ["AGENTS.md"]
|
|
71
|
+
|
|
69
72
|
[tool.setuptools_scm]
|
|
70
73
|
write_to = "olbrain/_version.py"
|
|
71
74
|
|
|
@@ -15,7 +15,7 @@ if os.path.exists(readme_path):
|
|
|
15
15
|
long_description = f.read()
|
|
16
16
|
|
|
17
17
|
# Read version from the package
|
|
18
|
-
version = "0.3.
|
|
18
|
+
version = "0.3.2"
|
|
19
19
|
|
|
20
20
|
setup(
|
|
21
21
|
name="olbrain-python-sdk",
|
|
@@ -25,8 +25,9 @@ setup(
|
|
|
25
25
|
description="Official Python SDK for Olbrain AI agents",
|
|
26
26
|
long_description=long_description,
|
|
27
27
|
long_description_content_type="text/markdown",
|
|
28
|
-
url="https://github.com/Olbrain/olbrain-
|
|
29
|
-
packages=find_packages(),
|
|
28
|
+
url="https://github.com/Olbrain/olbrain-sdk",
|
|
29
|
+
packages=find_packages(exclude=["tests", "tests.*"]),
|
|
30
|
+
package_data={"olbrain": ["AGENTS.md"]},
|
|
30
31
|
classifiers=[
|
|
31
32
|
"Development Status :: 3 - Alpha",
|
|
32
33
|
"Intended Audience :: Developers",
|
|
@@ -76,8 +77,8 @@ setup(
|
|
|
76
77
|
"streaming"
|
|
77
78
|
],
|
|
78
79
|
project_urls={
|
|
79
|
-
"Bug Reports": "https://github.com/Olbrain/olbrain-
|
|
80
|
-
"Source": "https://github.com/Olbrain/olbrain-python
|
|
80
|
+
"Bug Reports": "https://github.com/Olbrain/olbrain-sdk/issues",
|
|
81
|
+
"Source": "https://github.com/Olbrain/olbrain-sdk/tree/main/packages/python",
|
|
81
82
|
"Documentation": "https://docs.olbrain.com/python-sdk",
|
|
82
83
|
},
|
|
83
84
|
include_package_data=True,
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
Test script for Olbrain Python SDK
|
|
4
|
-
Tests agent eQG36P3MaS3T6craxbET with real-time streaming
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import sys
|
|
8
|
-
import os
|
|
9
|
-
import logging
|
|
10
|
-
import time
|
|
11
|
-
import threading
|
|
12
|
-
|
|
13
|
-
# Add current directory to path to use local SDK
|
|
14
|
-
sys.path.insert(0, os.path.dirname(__file__))
|
|
15
|
-
|
|
16
|
-
from olbrain import AgentClient
|
|
17
|
-
|
|
18
|
-
# Setup logging
|
|
19
|
-
logging.basicConfig(
|
|
20
|
-
level=logging.INFO,
|
|
21
|
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
def main():
|
|
25
|
-
"""Main test function"""
|
|
26
|
-
|
|
27
|
-
# Agent configuration
|
|
28
|
-
AGENT_ID = "Ock2O6ZkG7bN1bPoAYSS"
|
|
29
|
-
|
|
30
|
-
print("\n" + "=" * 70)
|
|
31
|
-
print("🧪 OLBRAIN SDK TEST")
|
|
32
|
-
print("=" * 70)
|
|
33
|
-
print(f"\n🎯 Target Agent: {AGENT_ID}")
|
|
34
|
-
|
|
35
|
-
# Get API key
|
|
36
|
-
API_KEY = "sk_live_24c2859a0cf359b8aebbe3d8e9c60f0341d111b30004a56b428726edb354bec5"
|
|
37
|
-
|
|
38
|
-
print("\n" + "=" * 70)
|
|
39
|
-
print("🚀 STARTING TEST")
|
|
40
|
-
print("=" * 70)
|
|
41
|
-
|
|
42
|
-
# Message handler with nice formatting
|
|
43
|
-
def on_message(msg):
|
|
44
|
-
"""Handle incoming messages"""
|
|
45
|
-
role = msg.get('role', 'unknown')
|
|
46
|
-
content = msg.get('content', '')
|
|
47
|
-
tokens = msg.get('token_usage', {})
|
|
48
|
-
total_tokens = tokens.get('total', 0)
|
|
49
|
-
cost = tokens.get('cost', 0)
|
|
50
|
-
|
|
51
|
-
# Format output
|
|
52
|
-
if role == 'user':
|
|
53
|
-
emoji = "👤"
|
|
54
|
-
color_code = "\033[94m" # Blue
|
|
55
|
-
else:
|
|
56
|
-
emoji = "🤖"
|
|
57
|
-
color_code = "\033[92m" # Green
|
|
58
|
-
|
|
59
|
-
reset_code = "\033[0m"
|
|
60
|
-
|
|
61
|
-
print(f"\n{color_code}{emoji} [{role.upper()}]{reset_code}")
|
|
62
|
-
print(f" {content}")
|
|
63
|
-
|
|
64
|
-
if total_tokens > 0:
|
|
65
|
-
print(f" 💰 Tokens: {total_tokens} | Cost: ${cost:.6f}")
|
|
66
|
-
|
|
67
|
-
# Create client
|
|
68
|
-
try:
|
|
69
|
-
print("\n📦 Initializing SDK client...")
|
|
70
|
-
client = AgentClient(agent_id=AGENT_ID, api_key=API_KEY)
|
|
71
|
-
print(f"✅ Client initialized: {client}")
|
|
72
|
-
|
|
73
|
-
except Exception as e:
|
|
74
|
-
print(f"\n❌ Failed to initialize client: {e}")
|
|
75
|
-
return 1
|
|
76
|
-
|
|
77
|
-
try:
|
|
78
|
-
# Create session
|
|
79
|
-
print("\n📝 Creating session...")
|
|
80
|
-
session = client.create_session(on_message=on_message)
|
|
81
|
-
print(f"✅ Session created: {session}")
|
|
82
|
-
print(" 📡 Real-time message stream active")
|
|
83
|
-
|
|
84
|
-
print("\n" + "=" * 70)
|
|
85
|
-
print("💬 INTERACTIVE MODE")
|
|
86
|
-
print("=" * 70)
|
|
87
|
-
print("\n ✨ Type your messages below")
|
|
88
|
-
print(" 📨 All responses will appear in real-time")
|
|
89
|
-
print(" ⏰ Scheduled messages will arrive automatically")
|
|
90
|
-
print(" 🚪 Type 'exit' or 'quit' to stop")
|
|
91
|
-
print(" ⏹️ Press Ctrl+C to force exit\n")
|
|
92
|
-
|
|
93
|
-
# Main thread handles input (SSE stream runs in background)
|
|
94
|
-
while True:
|
|
95
|
-
try:
|
|
96
|
-
print("USER > ", end="", flush=True)
|
|
97
|
-
user_input = input()
|
|
98
|
-
|
|
99
|
-
if user_input.strip().lower() in ['exit', 'quit']:
|
|
100
|
-
print("\n👋 Exiting...")
|
|
101
|
-
break
|
|
102
|
-
|
|
103
|
-
if user_input.strip():
|
|
104
|
-
client.send(session, user_input)
|
|
105
|
-
|
|
106
|
-
except EOFError:
|
|
107
|
-
# Ctrl+D pressed
|
|
108
|
-
print("\n👋 Exiting...")
|
|
109
|
-
break
|
|
110
|
-
except Exception as e:
|
|
111
|
-
print(f"\n⚠️ Error: {e}")
|
|
112
|
-
break
|
|
113
|
-
|
|
114
|
-
except KeyboardInterrupt:
|
|
115
|
-
print("\n\n" + "=" * 70)
|
|
116
|
-
print("👋 GRACEFUL SHUTDOWN")
|
|
117
|
-
print("=" * 70)
|
|
118
|
-
print("\n✅ Test completed successfully!")
|
|
119
|
-
|
|
120
|
-
except Exception as e:
|
|
121
|
-
print("\n\n" + "=" * 70)
|
|
122
|
-
print("❌ ERROR OCCURRED")
|
|
123
|
-
print("=" * 70)
|
|
124
|
-
print(f"\n💥 Error: {e}")
|
|
125
|
-
print("\n📋 Traceback:")
|
|
126
|
-
import traceback
|
|
127
|
-
traceback.print_exc()
|
|
128
|
-
return 1
|
|
129
|
-
|
|
130
|
-
finally:
|
|
131
|
-
print("\n🧹 Cleaning up...")
|
|
132
|
-
client.close()
|
|
133
|
-
print("✅ Cleanup complete")
|
|
134
|
-
print("\n" + "=" * 70)
|
|
135
|
-
print("🏁 TEST FINISHED")
|
|
136
|
-
print("=" * 70 + "\n")
|
|
137
|
-
|
|
138
|
-
return 0
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if __name__ == "__main__":
|
|
142
|
-
exit_code = main()
|
|
143
|
-
sys.exit(exit_code)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain_python_sdk.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{olbrain_python_sdk-0.3.1 → olbrain_python_sdk-0.3.2}/olbrain_python_sdk.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|