evokai-client 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.
- evokai_client-0.1.0/LICENSE +202 -0
- evokai_client-0.1.0/NOTICE +7 -0
- evokai_client-0.1.0/PKG-INFO +370 -0
- evokai_client-0.1.0/README.md +334 -0
- evokai_client-0.1.0/pyproject.toml +141 -0
- evokai_client-0.1.0/pyproject.toml.orig +119 -0
- evokai_client-0.1.0/src/evokai/__init__.py +175 -0
- evokai_client-0.1.0/src/evokai/_calls.py +614 -0
- evokai_client-0.1.0/src/evokai/_http.py +276 -0
- evokai_client-0.1.0/src/evokai/_version.py +1 -0
- evokai_client-0.1.0/src/evokai/errors.py +186 -0
- evokai_client-0.1.0/src/evokai/events.py +394 -0
- evokai_client-0.1.0/src/evokai/models.py +1444 -0
- evokai_client-0.1.0/src/evokai/py.typed +0 -0
- evokai_client-0.1.0/src/evokai/server.py +1344 -0
- evokai_client-0.1.0/src/evokai/session.py +1011 -0
- evokai_client-0.1.0/src/evokai/sse.py +162 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Evokai™
|
|
2
|
+
Copyright 2026 Giordano Pescetelli
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
5
|
+
The name "Evokai™", its logo and its mascot are (unregistered) trademarks of Giordano Pescetelli and are not licensed under the
|
|
6
|
+
Apache License (see its section 6): forks and derived works must use a different name and branding, and must keep
|
|
7
|
+
this NOTICE and the copyright notices.
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: evokai-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for Evokai: session tokens, server runs, admin API and streamed session chats
|
|
5
|
+
Keywords: evokai,agents,llm,mcp,sse,client,sdk
|
|
6
|
+
Author: Giordano Pescetelli
|
|
7
|
+
Author-email: Giordano Pescetelli <giordano.pescetelli@gmail.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: NOTICE
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
23
|
+
Classifier: Framework :: AsyncIO
|
|
24
|
+
Classifier: Framework :: Pydantic :: 2
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Dist: httpx>=0.27
|
|
28
|
+
Requires-Dist: pydantic>=2.11
|
|
29
|
+
Requires-Dist: typing-extensions>=4.12
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
|
+
Project-URL: Homepage, https://github.com/Giordyfish/evokai
|
|
32
|
+
Project-URL: Repository, https://github.com/Giordyfish/evokai
|
|
33
|
+
Project-URL: Documentation, https://github.com/Giordyfish/evokai/tree/main/clients/python#readme
|
|
34
|
+
Project-URL: Issues, https://github.com/Giordyfish/evokai/issues
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# evokai-client
|
|
38
|
+
|
|
39
|
+
Python client for [Evokai](https://github.com/Giordyfish/evokai), the agents runtime. One package, `import evokai`:
|
|
40
|
+
|
|
41
|
+
| Class | Credential | What it is |
|
|
42
|
+
| --- | --- | --- |
|
|
43
|
+
| `EvokaiServer` / `AsyncEvokaiServer` | server key (and admin key for `.admin`) | Your backend: session tokens, server runs, conversations, memories, usage, privacy requests, the admin API. |
|
|
44
|
+
| `EvokaiSession` / `AsyncEvokaiSession` | session token | One subject, one agent, one conversation: chats streamed as typed events, confirmations, questions, replay, cancel, thumbs. |
|
|
45
|
+
|
|
46
|
+
It is the Python sibling of the TypeScript client (`@evokai/evokai-client`): same routes, same names in snake_case.
|
|
47
|
+
Built on `httpx` and `pydantic` v2, sync and async, fully typed (`py.typed`), Python 3.10 or newer.
|
|
48
|
+
|
|
49
|
+
`base_url` is where the service is mounted, base path included, e.g. `https://agents.example.com/agent`. Keys
|
|
50
|
+
never belong in a browser.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
uv add evokai-client
|
|
56
|
+
# or
|
|
57
|
+
pip install evokai-client
|
|
58
|
+
# or, unreleased changes, from the repository:
|
|
59
|
+
uv add "evokai-client @ git+https://github.com/Giordyfish/evokai#subdirectory=clients/python"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Backend: minting a session token
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import os
|
|
66
|
+
|
|
67
|
+
from evokai import EvokaiServer
|
|
68
|
+
|
|
69
|
+
evokai = EvokaiServer(
|
|
70
|
+
os.environ["EVOKAI_URL"], # https://agents.example.com/agent
|
|
71
|
+
os.environ["EVOKAI_SERVER_KEY"], # evk_srv_...
|
|
72
|
+
admin_key=os.environ.get("EVOKAI_ADMIN_KEY"), # evk_adm_..., only for evokai.admin
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
token = evokai.mint_session_token(
|
|
76
|
+
"user-42", # your own opaque id of the end user
|
|
77
|
+
"assistant",
|
|
78
|
+
tags=["team:ops"],
|
|
79
|
+
forward_credential=request_jwt, # forward_user MCP servers call your API as this user
|
|
80
|
+
limits={"caps": [{"period": "week", "amount": 5}]}, # or subject_daily_usd (USD)
|
|
81
|
+
voice_engine="browser",
|
|
82
|
+
)
|
|
83
|
+
# Hand the browser what it needs: token.token, token.expires_at, token.conversation_id,
|
|
84
|
+
# token.usage (shares of the caps, never amounts) and token.suggestions.
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Every field of `POST /v1/session-tokens` is a keyword argument: `conversation_id` (continue a conversation),
|
|
88
|
+
`ttl_seconds`, `model`, `voice`, `voice_engine`, `storage_mode`, `consent`, `exit_code` (kiosks), `memory_consent`
|
|
89
|
+
(the person's answer to long-term memory, asked in your own interface; `token.memory` is their memory state).
|
|
90
|
+
|
|
91
|
+
With FastAPI, a token route is a few lines:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from fastapi import Depends, FastAPI
|
|
95
|
+
|
|
96
|
+
from evokai import AsyncEvokaiServer
|
|
97
|
+
|
|
98
|
+
app = FastAPI()
|
|
99
|
+
evokai = AsyncEvokaiServer(EVOKAI_URL, EVOKAI_SERVER_KEY)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@app.post("/api/evokai/token")
|
|
103
|
+
async def evokai_token(user=Depends(current_user)):
|
|
104
|
+
t = await evokai.mint_session_token(user.id, "assistant")
|
|
105
|
+
return {"token": t.token, "expiresAt": t.expires_at, "conversationId": t.conversation_id}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Running an agent from the server
|
|
109
|
+
|
|
110
|
+
An agent whose `channels` include `server` runs with no browser and no user:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
result = evokai.run(
|
|
114
|
+
"mail-triage",
|
|
115
|
+
"Classify this message",
|
|
116
|
+
subject="customer-9137",
|
|
117
|
+
attachments=[{"name": "mail.txt", "text": body}],
|
|
118
|
+
)
|
|
119
|
+
result.output # the schema-valid JSON when the agent has an output_schema, else the answer text
|
|
120
|
+
result.model # the model that answered
|
|
121
|
+
result.usage.cost_usd # server to server: amounts are fine here
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`input` can also be a conversation: `[{"role": "user", "text": "..."}, {"role": "assistant", "text": "..."}]`.
|
|
125
|
+
`store=True` keeps the run as a conversation of the subject.
|
|
126
|
+
|
|
127
|
+
## Streaming a session chat
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from evokai import AskEvent, ConfirmEvent, EvokaiSession, TextEvent
|
|
131
|
+
|
|
132
|
+
with EvokaiSession(EVOKAI_URL, token) as session: # a token string or the minted SessionToken
|
|
133
|
+
with session.chat("How many orders are waiting to ship?", page={"path": "/orders"}) as stream:
|
|
134
|
+
for event in stream:
|
|
135
|
+
match event:
|
|
136
|
+
case TextEvent(delta=delta):
|
|
137
|
+
print(delta, end="", flush=True)
|
|
138
|
+
case AskEvent(question=q, options=options):
|
|
139
|
+
print(f"\n{q} {options}")
|
|
140
|
+
case ConfirmEvent(action_id=action_id, items=items):
|
|
141
|
+
pending = action_id
|
|
142
|
+
print(stream.done.reason) # end_turn, confirm, ask, limit, ...
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- Iterating yields typed events (pydantic models): `conversation`, `text`, `say`, `tool`, `chart`, `diagram`, `ask`,
|
|
146
|
+
`navigate`, `confirm`, `rewritten`, `usage`, `speech`, `error` and `done`. Each carries `turn_id` and `seq`. A type this client
|
|
147
|
+
does not know yet arrives as `UnknownEvent` with every field in `event.data`, so a newer service never breaks you.
|
|
148
|
+
- `stream.turn_id` (from the `X-Turn-Id` header), `stream.text` (the deltas so far), `stream.done` and
|
|
149
|
+
`stream.until_done()` help when you do not need every event.
|
|
150
|
+
- Leaving the `with` block (or `break`, or `stream.close()`) closes the connection, and the service cancels that
|
|
151
|
+
turn. `session.cancel(turn_id)` cancels it explicitly and the stream still ends with `done`.
|
|
152
|
+
- If the connection drops before `done`, the stream completes itself from the replay endpoint
|
|
153
|
+
(`GET /v1/session/events?after=seq`); after `replay_attempts` polls without `done` it raises
|
|
154
|
+
`EvokaiConnectionError` with code `incomplete_turn`.
|
|
155
|
+
- Server-sent events are parsed by the client itself: comments (`: ping` every 10 seconds), multi-line `data:`,
|
|
156
|
+
CR/LF/CRLF line ends and chunks that split anything, multi-byte characters included.
|
|
157
|
+
|
|
158
|
+
### Confirmations and questions
|
|
159
|
+
|
|
160
|
+
A tool that changes data never runs directly: the turn ends with a `confirm` event and `done` reason `confirm`.
|
|
161
|
+
Send the user's decision and stream the turn that resumes:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
for event in session.confirm(pending, approve=True):
|
|
165
|
+
...
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`confirm.why[i]` says why `items[i]` waits: `key` is `confirm.why.writes` (a change), `confirm.why.policy` or
|
|
169
|
+
`confirm.why.rule` (an ask rule, with its `label` in the application's language).
|
|
170
|
+
|
|
171
|
+
The person may edit their last question and send it again while it is `rewritable` (on the stored user message, and on
|
|
172
|
+
every `done`): the last turn is replaced, and the stream starts with `conversation` and `rewritten`. A turn that
|
|
173
|
+
changed data cannot be rewritten (`EvokaiConflictError`, code `rewrite_after_write`):
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
for event in session.rewrite("Show September instead"):
|
|
177
|
+
...
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
An `ask` event is answered by sending the chosen option as the next message:
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
session.answer("The second one").until_done()
|
|
184
|
+
session.answer(["Rome", "Milan"]) # several options of a multiple-choice question: "Rome, Milan"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Without streaming
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
result = session.chat_json("Summarise my week") # Accept: application/json, waits for the end
|
|
191
|
+
result.text, result.reason, result.events
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
External storage (the application keeps the conversation): pass `history=[...]` (`HistoryMessage` or plain dicts)
|
|
195
|
+
to `chat`, `confirm`, `answer` or `chat_json`, and append `done.messages` (or `result.messages`) to your copy. A
|
|
196
|
+
rewrite (`session.rewrite(text, history=...)`, `chat_json(text, history=..., rewrite=True)`) says where its messages go:
|
|
197
|
+
drop your copy from `replaced_from` first.
|
|
198
|
+
|
|
199
|
+
### The rest of the session API
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
session.info() # conversation, agent, usage shares, memories, starter questions
|
|
203
|
+
session.conversation() # stored messages (events typed), open confirmation, last seq, running turn
|
|
204
|
+
session.events(after=0) # replay
|
|
205
|
+
session.feedback(message_id, 1) # thumbs up (1), down (-1) or none (None)
|
|
206
|
+
session.cancel(turn_id)
|
|
207
|
+
session.report_bug("The chart is empty", {"page": "/reports"})
|
|
208
|
+
session.exit("1234") # kiosk sessions
|
|
209
|
+
session.use_token(new_token) # a refreshed token for the same conversation
|
|
210
|
+
|
|
211
|
+
# Long-term memory, as the person sees it
|
|
212
|
+
listed = session.memories() # listed.memory (mode, consent, active, ask), listed.items (Memory)
|
|
213
|
+
session.memory_consent(True) # a no deletes what was remembered; 409 memory_off when the mode is off
|
|
214
|
+
session.edit_memory(memory_id, "Prefers short answers") # 400 memory_refused: instructions, secrets, personal data
|
|
215
|
+
session.forget_memory(memory_id) # one; forget_memory() deletes everything. Returns how many.
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`EvokaiServer.session(token)` gives a session that shares the server client's HTTP connection pool.
|
|
219
|
+
|
|
220
|
+
### Async
|
|
221
|
+
|
|
222
|
+
Every class has an async twin with the same methods:
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
import asyncio
|
|
226
|
+
|
|
227
|
+
from evokai import AsyncEvokaiServer, TextEvent
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
async def main() -> None:
|
|
231
|
+
async with AsyncEvokaiServer(EVOKAI_URL, EVOKAI_SERVER_KEY) as evokai:
|
|
232
|
+
token = await evokai.mint_session_token("user-42", "assistant")
|
|
233
|
+
async with evokai.session(token) as session, session.chat("Hi") as stream:
|
|
234
|
+
async for event in stream:
|
|
235
|
+
if isinstance(event, TextEvent):
|
|
236
|
+
print(event.delta, end="")
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
asyncio.run(main())
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Conversations, memories, usage, catalogue
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
evokai.conversations.list("user-42", limit=10)
|
|
246
|
+
evokai.conversations.get(conversation_id, "user-42")
|
|
247
|
+
evokai.conversations.delete(conversation_id, "user-42")
|
|
248
|
+
evokai.memories.list("user-42")
|
|
249
|
+
evokai.memories.forget("user-42") # everything, or memory_id="..." for one fact
|
|
250
|
+
evokai.memories.consent("user-42", False) # the person's answer; False deletes what was remembered
|
|
251
|
+
evokai.agents()
|
|
252
|
+
evokai.voices(language="it-IT")
|
|
253
|
+
report = evokai.usage(group_by=["subject", "day"], from_="2026-11-01")
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
`usage()` returns amounts (server key only). People never see amounts: before usage reaches a browser, turn it into
|
|
257
|
+
shares of the caps with `to_usage_shares(report)`, which drops every amount.
|
|
258
|
+
|
|
259
|
+
## Privacy requests
|
|
260
|
+
|
|
261
|
+
The subject travels in the body, never in the address:
|
|
262
|
+
|
|
263
|
+
```python
|
|
264
|
+
data = evokai.privacy.export("user-42") # everything Evokai keeps about them
|
|
265
|
+
erased = evokai.privacy.erase("user-42") # right to be forgotten; idempotent
|
|
266
|
+
erased.conversations, erased.usage_deidentified
|
|
267
|
+
evokai.privacy.revoke_sessions("user-42") # sign-out everywhere
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Admin API
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
from evokai import AgentDef, AppPatch
|
|
274
|
+
|
|
275
|
+
admin = evokai.admin # needs admin_key
|
|
276
|
+
|
|
277
|
+
admin.application.get()
|
|
278
|
+
admin.application.patch(daily_cap_usd=20, allowed_origins=["https://app.example.com"])
|
|
279
|
+
admin.application.patch(AppPatch(daily_cap_usd=None)) # None clears; unset fields are not sent
|
|
280
|
+
|
|
281
|
+
admin.agents.put(
|
|
282
|
+
AgentDef(
|
|
283
|
+
name="assistant",
|
|
284
|
+
model="bedrock:eu.anthropic.claude-sonnet-4-5",
|
|
285
|
+
instructions="You help the bookshop staff with orders and returns.",
|
|
286
|
+
mcp_servers=["crm"],
|
|
287
|
+
channels=["browser"],
|
|
288
|
+
)
|
|
289
|
+
)
|
|
290
|
+
admin.agents.list()
|
|
291
|
+
admin.agents.versions("assistant")
|
|
292
|
+
admin.agents.delete("assistant")
|
|
293
|
+
|
|
294
|
+
admin.mcp_servers.put("crm", {"url": "https://crm.example.com/mcp", "auth": "forward_user"})
|
|
295
|
+
admin.mcp_servers.test("crm", credential=user_jwt)
|
|
296
|
+
admin.mcp_servers.connectors()
|
|
297
|
+
|
|
298
|
+
admin.skills.put("refunds", {"description": "How refunds work", "body": "..."})
|
|
299
|
+
admin.prompts.put("assistant", "You are ...") # returns the version
|
|
300
|
+
|
|
301
|
+
admin.security.put({"mode": "enforce", "tools": {"deny": ["crm_delete_client"]}})
|
|
302
|
+
admin.security.events(control="input.", limit=50)
|
|
303
|
+
|
|
304
|
+
admin.grants.get()
|
|
305
|
+
admin.grants.change([{"kind": "model", "name": "openai:gpt-5", "value": "off"}])
|
|
306
|
+
admin.grants.change([{"kind": "code", "name": "*", "value": True}]) # code_run, off until granted
|
|
307
|
+
|
|
308
|
+
admin.compliance.put_profile({"controller": "Acme S.p.A.", "ai_act": {"annex_iii": []}})
|
|
309
|
+
admin.compliance.pack("gdpr", lang="it") # JSON, every statement with its sources
|
|
310
|
+
admin.compliance.pack("ai-act", format="html", lang="en") # printable HTML (or "md")
|
|
311
|
+
snap = admin.compliance.snapshot("before the November release")
|
|
312
|
+
admin.compliance.diff(snap.id, admin.compliance.snapshot().id, lang="en")
|
|
313
|
+
|
|
314
|
+
admin.keys.rotate(key_id) # the new key is shown only now
|
|
315
|
+
admin.usage_summary(from_="2026-11-01")
|
|
316
|
+
admin.activity(limit=20)
|
|
317
|
+
admin.export() # the application as a config file
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Errors
|
|
321
|
+
|
|
322
|
+
Every failure raises an `EvokaiError` with `status`, the service's stable `code` and a `message` that is safe to show
|
|
323
|
+
(plus `fields` for invalid requests and `body` for the rest, e.g. `problems` of `not_granted`):
|
|
324
|
+
|
|
325
|
+
| Class | When |
|
|
326
|
+
| --- | --- |
|
|
327
|
+
| `EvokaiAuthError` | 401, 403 (`unauthorized`, `origin`, `channel`, `model_not_granted`, ...) |
|
|
328
|
+
| `EvokaiNotFoundError` | 404 |
|
|
329
|
+
| `EvokaiConflictError` | 409 (`closed`, `storage_mode`, `expired_conversation`, ...) |
|
|
330
|
+
| `EvokaiValidationError` | 400, 422 (`bad_request` with `fields`, `not_granted`, ...) |
|
|
331
|
+
| `EvokaiRateLimitError` | 429 (`limit`, `rate_limited`), with `retry_after` |
|
|
332
|
+
| `EvokaiServerError` | 5xx (`internal`, `invalid_output`) |
|
|
333
|
+
| `EvokaiConnectionError` | no answer (`network`, `timeout`) or a turn that ended without `done` (`incomplete_turn`) |
|
|
334
|
+
|
|
335
|
+
```python
|
|
336
|
+
from evokai import EvokaiError, is_expired_conversation
|
|
337
|
+
|
|
338
|
+
try:
|
|
339
|
+
token = evokai.mint_session_token("user-42", "assistant", conversation_id=cid)
|
|
340
|
+
except EvokaiError as e:
|
|
341
|
+
if is_expired_conversation(e):
|
|
342
|
+
token = evokai.mint_session_token("user-42", "assistant")
|
|
343
|
+
else:
|
|
344
|
+
raise
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## Models
|
|
348
|
+
|
|
349
|
+
Requests and answers are pydantic models with snake_case attributes; on the wire they keep the service's names.
|
|
350
|
+
Every model keeps fields it does not know yet in `model_extra`. Methods that take a body accept the model or a plain
|
|
351
|
+
mapping (attribute or wire names). A test checks the request models against the service's OpenAPI schema
|
|
352
|
+
(`clients/typescript/openapi.json`), so a renamed or newly required field fails CI.
|
|
353
|
+
|
|
354
|
+
## Development
|
|
355
|
+
|
|
356
|
+
```sh
|
|
357
|
+
cd clients/python
|
|
358
|
+
uv sync
|
|
359
|
+
uv run ruff check src tests && uv run ruff format --check src tests
|
|
360
|
+
uv run ty check
|
|
361
|
+
uv run pytest -q
|
|
362
|
+
uv build
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
`scripts/ci.sh python` runs the same gates from the repository root.
|
|
366
|
+
|
|
367
|
+
## License
|
|
368
|
+
|
|
369
|
+
Apache-2.0, see [LICENSE](LICENSE) and [NOTICE](NOTICE). "Evokai" and its logo are trademarks of Giordano
|
|
370
|
+
Pescetelli and are not licensed under the Apache License.
|