entrove-sdk 0.2.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.
- entrove_sdk-0.2.0/LICENSE +201 -0
- entrove_sdk-0.2.0/PKG-INFO +339 -0
- entrove_sdk-0.2.0/README.md +317 -0
- entrove_sdk-0.2.0/pyproject.toml +91 -0
- entrove_sdk-0.2.0/pyproject.toml.orig +68 -0
- entrove_sdk-0.2.0/src/entrove/__init__.py +117 -0
- entrove_sdk-0.2.0/src/entrove/_async_client.py +152 -0
- entrove_sdk-0.2.0/src/entrove/_base_client.py +246 -0
- entrove_sdk-0.2.0/src/entrove/_client.py +151 -0
- entrove_sdk-0.2.0/src/entrove/_exceptions.py +125 -0
- entrove_sdk-0.2.0/src/entrove/_post_all.py +77 -0
- entrove_sdk-0.2.0/src/entrove/py.typed +0 -0
- entrove_sdk-0.2.0/src/entrove/testing.py +233 -0
- entrove_sdk-0.2.0/src/entrove/types.py +466 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: entrove-sdk
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python client for the Entrove Agent API
|
|
5
|
+
Author: Entrove
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Typing :: Typed
|
|
15
|
+
Requires-Dist: httpx2>=2,<3
|
|
16
|
+
Requires-Dist: pydantic>=2.11,<3
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Project-URL: Homepage, https://github.com/RhymeHQ/entrove-python-sdk
|
|
19
|
+
Project-URL: Issues, https://github.com/RhymeHQ/entrove-python-sdk/issues
|
|
20
|
+
Project-URL: Changelog, https://github.com/RhymeHQ/entrove-python-sdk/blob/main/CHANGELOG.md
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# Entrove Python SDK
|
|
24
|
+
|
|
25
|
+
Python client for the Entrove Agent API. An agent asks Entrove which workflow to follow for a ticket and reports what it did, one activity per ticket turn, which Entrove shows on the agent's Live Activity page.
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pip install entrove-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Requires Python 3.12+.
|
|
32
|
+
|
|
33
|
+
### Migrating from `rhyme-sdk`
|
|
34
|
+
|
|
35
|
+
This SDK was called `rhyme-sdk`, imported as `rhyme`. To move to `entrove-sdk`:
|
|
36
|
+
|
|
37
|
+
1. `pip uninstall rhyme-sdk && pip install entrove-sdk`. (`pip install -U rhyme-sdk` also works for now: its last release, 0.2.0, installs `entrove-sdk` and keeps only the alias below. `rhyme-sdk` gets no further releases.)
|
|
38
|
+
2. Import from `entrove`, and rename `Rhyme` → `Entrove`, `AsyncRhyme` → `AsyncEntrove`, `RhymeClient` → `EntroveClient`, `AsyncRhymeClient` → `AsyncEntroveClient`, `RhymeError` → `EntroveError`, and in tests `FakeRhyme` → `FakeEntrove`, `AsyncFakeRhyme` → `AsyncFakeEntrove`.
|
|
39
|
+
3. Rename the environment variables `RHYME_API_KEY` → `ENTROVE_API_KEY` and `RHYME_BASE_URL` → `ENTROVE_BASE_URL`.
|
|
40
|
+
4. If you configure the SDK's logger, it is now `entrove`, not `rhyme`.
|
|
41
|
+
|
|
42
|
+
Until you do, `import rhyme` (with `rhyme-sdk` installed) and the old names still work and are the same objects as the new ones, and `RHYME_*` variables are still read when the `ENTROVE_*` ones aren't set. Both raise a `DeprecationWarning`; the alias will be removed in a later release. API keys don't change: they keep their `rhyme_ak1_` prefix.
|
|
43
|
+
|
|
44
|
+
## Quickstart
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from entrove import Activity, ActivityRequest, Entrove
|
|
48
|
+
|
|
49
|
+
client = Entrove(api_key="rhyme_ak1_...", base_url="https://<entrove-host>/api/agent/v1")
|
|
50
|
+
|
|
51
|
+
client.me() # smoke-test the key: agent, scopes, limits, today's usage
|
|
52
|
+
|
|
53
|
+
result = client.post_activity(
|
|
54
|
+
Activity(
|
|
55
|
+
external_id="zendesk:4822:1",
|
|
56
|
+
status="done",
|
|
57
|
+
action="draft_reply",
|
|
58
|
+
request=ActivityRequest(source="zendesk", id="4822"),
|
|
59
|
+
summary="Drafted a reply about a delayed refund",
|
|
60
|
+
duration_ms=8400,
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
if not result.ok:
|
|
64
|
+
print(result.error)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`api_key` and `base_url` fall back to the `ENTROVE_API_KEY` and `ENTROVE_BASE_URL` environment variables. There is no default base URL: you choose which Entrove region your activity data goes to.
|
|
68
|
+
|
|
69
|
+
### Async
|
|
70
|
+
|
|
71
|
+
`AsyncEntrove` has the same methods, as coroutines:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from entrove import AsyncEntrove
|
|
75
|
+
|
|
76
|
+
async with AsyncEntrove() as client:
|
|
77
|
+
result = await client.post_activity(activity)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### HTTP client
|
|
81
|
+
|
|
82
|
+
Both clients use [HTTPX2](https://github.com/pydantic/httpx2). To configure proxies, TLS or connection limits, pass your own `httpx2.Client` (or `httpx2.AsyncClient` for `AsyncEntrove`) as `http_client=`. The SDK doesn't close a client you pass in. Redirects aren't followed: a 3xx raises `APIStatusError`.
|
|
83
|
+
|
|
84
|
+
## Activities
|
|
85
|
+
|
|
86
|
+
`POST /activities` upserts by `external_id`, so posting the same id again updates the activity (for example `pending` → `done`).
|
|
87
|
+
|
|
88
|
+
- A field you **don't set** keeps its stored value.
|
|
89
|
+
- Setting a field to **`None`** clears it. That works for the text fields (`requester`, `ask`, `summary`, `outcome`, `escalation_reason`, `output`, `input_text`), `duration_ms`, `usage`, `tools` and a reference's `url`. Every other field can't be null: `Activity(action=None)` raises `ValueError`, so leave the field unset instead.
|
|
90
|
+
- `request`, `occurred_at`, `workflow`, `step`, `intent` and `mode` are set once. A later, different value is ignored with an `immutable_field_ignored` warning. `metadata` is merged into the stored metadata.
|
|
91
|
+
- `done` and `handed_over` are final. A later `pending` or `failed` comes back with result `stale`, and nothing is written.
|
|
92
|
+
- A batch is 1–100 activities. Each item gets its own result, so a `200` can still contain rejected items:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
batch = client.post_activities(activities)
|
|
96
|
+
for item in batch.rejected:
|
|
97
|
+
print(item.index, item.error.code, item.error.field)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
You can also pass plain dicts in API field names (`{"externalId": ..., "status": ...}`). They are sent as given, without validation.
|
|
101
|
+
|
|
102
|
+
### Shadow mode
|
|
103
|
+
|
|
104
|
+
Set `mode="shadow"` when the agent runs on a ticket without acting on it, for example replaying last month's cases. Send the same activity it would send live, with `action` and `output` saying what it would have done. Shadow activities stay out of Live Activity and its totals; reviewers mark them correct or incorrect in the Evaluator. `mode` defaults to `live`.
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from entrove import Activity, ActivityMode, ActivityRequest, StepRef, WorkflowRef
|
|
108
|
+
|
|
109
|
+
client.post_activity(
|
|
110
|
+
Activity(
|
|
111
|
+
external_id="zendesk:4821:triage",
|
|
112
|
+
status="done",
|
|
113
|
+
mode=ActivityMode.SHADOW,
|
|
114
|
+
action="escalate",
|
|
115
|
+
output="Escalated to Tier 2: refund over the £200 limit",
|
|
116
|
+
request=ActivityRequest(source="zendesk", id="4821"),
|
|
117
|
+
workflow=WorkflowRef(key="triage"),
|
|
118
|
+
step=StepRef(key="escalate"),
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
A server older than this SDK ignores `mode` with an `unknown_field` warning and stores the activity as live.
|
|
124
|
+
|
|
125
|
+
### What the turn answered
|
|
126
|
+
|
|
127
|
+
Set `input_text` to the requester's message (or messages) the turn answered, so a reviewer in the Evaluator can judge the reply against what was asked without opening the ticket. `ask` is a short label for the request; `input_text` is the text itself.
|
|
128
|
+
|
|
129
|
+
Redact it before you send it: replace names, emails, phone numbers, addresses, order and card numbers with placeholders such as `[name]` or `[email]`. Entrove also redacts what it receives, but only as a fail-safe; a `pii_redacted` warning on the result means your own redaction missed something.
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from entrove import Activity, ActivityRequest
|
|
133
|
+
|
|
134
|
+
client.post_activity(
|
|
135
|
+
Activity(
|
|
136
|
+
external_id="zendesk:4821:2",
|
|
137
|
+
status="done",
|
|
138
|
+
mode="shadow",
|
|
139
|
+
request=ActivityRequest(source="zendesk", id="4821"),
|
|
140
|
+
ask="Gift card not received",
|
|
141
|
+
input_text="Hi, I'm [name]. I bought a gift card for [email] three days ago and it never arrived.",
|
|
142
|
+
output="Resent the gift card email and told the customer to check their spam folder.",
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
A server without `input_text` ignores it with an `unknown_field` warning.
|
|
148
|
+
|
|
149
|
+
### Batching
|
|
150
|
+
|
|
151
|
+
`post_activities` takes up to 100 activities per call. To send more, use `post_all`. It posts them in order, in batches of up to 100:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
result = client.post_all(activities) # or: await client.post_all(...) with AsyncEntrove
|
|
155
|
+
for batch in result.batch_results:
|
|
156
|
+
for item in batch.rejected:
|
|
157
|
+
print(item.external_id, item.error.code)
|
|
158
|
+
for d in result.dropped:
|
|
159
|
+
print("dropped", d.activity, d.error)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
- If the API refuses a batch as too large (413) or invalid (400), `post_all` splits it and posts the halves. An activity it still refuses on its own is skipped and returned in `result.dropped` with its error, so one bad item can't block the rest. A plain dict that can't be serialised to JSON is handled the same way.
|
|
163
|
+
- On any other error (network, 5xx, rate limits, auth), it stops and raises `entrove.PostAllError`. The underlying error is its `__cause__`. `.batch_results` and `.dropped` describe what happened before it stopped, and `.unsent` holds every activity not yet posted, in order, so you can retry exactly those. Activities upsert by `externalId`, so resending one is safe.
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
from entrove import PostAllError
|
|
167
|
+
|
|
168
|
+
try:
|
|
169
|
+
client.post_all(activities)
|
|
170
|
+
except PostAllError as e:
|
|
171
|
+
save_for_later(e.unsent)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
A key can have a lower per-request limit than 100 (see `GET /me`). Pass it as `max_items`:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
client.post_all(activities, max_items=client.me().limits.max_items)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`post_all` keeps nothing between calls. To collect activities as they happen and send them in batches, keep your own list (or queue) and pass it to `post_all` when it's full or on a timer.
|
|
181
|
+
|
|
182
|
+
## Intents and workflows
|
|
183
|
+
|
|
184
|
+
`search_intents` finds the intents that fit a request, and `get_workflow` returns an intent's published workflow as a prompt for your model. Both need a key with the `workflows:read` scope (`client.me().key.scopes` lists the key's scopes); without it they raise `PermissionDeniedError`.
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from pydantic import TypeAdapter
|
|
188
|
+
|
|
189
|
+
from entrove import Activity, ActivityRequest, StepRef, ToolDefinition
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def get_order(order_id: str) -> dict: ...
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
tools = [
|
|
196
|
+
ToolDefinition(
|
|
197
|
+
name="get_order",
|
|
198
|
+
description="Look up an order by its id",
|
|
199
|
+
parameters=TypeAdapter(get_order).json_schema(),
|
|
200
|
+
)
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
result = client.search_intents("The customer bought a gift card and it never arrived")
|
|
204
|
+
intent = classify(result.intents) # your model picks the intent that fits the ticket
|
|
205
|
+
|
|
206
|
+
wf = client.get_workflow(intent.id, tools=tools)
|
|
207
|
+
step = run_agent(wf.prompt, [t for t in tools if t.name in wf.tools]) # the key of the step the turn ended on
|
|
208
|
+
|
|
209
|
+
client.post_activity(
|
|
210
|
+
Activity(
|
|
211
|
+
external_id="zendesk:4822:1",
|
|
212
|
+
status="done",
|
|
213
|
+
request=ActivityRequest(source="zendesk", id="4822"),
|
|
214
|
+
intent=intent.id,
|
|
215
|
+
workflow=wf.workflow_ref(),
|
|
216
|
+
step=StepRef(key=step),
|
|
217
|
+
)
|
|
218
|
+
)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
- **The summary** is one or two sentences about the request. Leave out personal details such as names, emails and order ids. You get up to 20 of the best matches, or up to `limit=` (at most 100). An agent with 20 or fewer intents gets all of them whatever the summary (`result.strategy == "all"`, with no `score`), so a small agent always sees every intent.
|
|
222
|
+
- **The tools** are the ones the agent can call. `parameters` is the tool's JSON Schema from any source: the example uses Pydantic, so no agent framework is needed. A tool with no arguments can leave out `parameters`, but give every tool a `description`: Entrove maps tools onto steps by name and description. `wf.tools` names the tools some step uses, in the order you offered them. That may be fewer than you offered: expose only those to the model.
|
|
223
|
+
- **The graph** (`wf.graph`) is the same workflow as the prompt, for code that tracks where the agent is. Each step lists its `tools`, and `next` says where to go after it (empty means finish). `graph.slots` are the facts the branch conditions read, and `graph.rules` are the agent's rules for every step. A step with `handover` set (`wf.graph.handovers`) is where the agent must stop and escalate: `"human_step"` at a review step that needs a person (`mode == "review"`; `handover_roles` says who), or `"tool_missing"` when no offered tool fits (`missing_action` says what it can't do, and `wf.warnings` lists it). The steps before it still run. A step's `executor` is only who does it today: a step a person does now is still the agent's to run unless it's a review step.
|
|
224
|
+
- **The first `get_workflow`** for a new workflow version or tool list can take up to about a minute: the server maps the tools with an LLM, then caches the mapping. So it has its own `timeout=`, 90 seconds by default, instead of the client's. A mapping that takes longer than a minute answers 503 `tool_mapping_unavailable`, but keeps going and is saved, so the automatic [retry](#errors-and-retries) gets it from the cache.
|
|
225
|
+
- **The version** served is the published one. Pass `version=` to pin an earlier one, for example to go back after a bad publish: a superseded version is still served (`wf.workflow.status == "superseded"`). Drafts are never served.
|
|
226
|
+
- **The activity** names the exact workflow version that ran (`wf.workflow_ref()`) and, as `step`, the step the turn ended on, by a `key` from `wf.graph.steps`.
|
|
227
|
+
- **Caching** is up to you: the SDK keeps none. `wf.workflow.version_id` identifies the version, so you may cache the prompt by intent and version id while your tools stay the same. Each intent from `search_intents` carries the `version` of its published workflow (`intent.workflow.version`), to tell when it changes. An intent with no published workflow has `workflow=None`: you can still classify into it, then hand over.
|
|
228
|
+
|
|
229
|
+
### Summary language
|
|
230
|
+
|
|
231
|
+
Write the summary in the language of the agent's documents and workflows, which for now is always English. Entrove searches it as given and never translates it: your agent already reads the customer's language, so have it write the summary in English. For example, for a ticket in German:
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
summary = "The customer wants a refund for an order that arrived damaged." # not "Kunde möchte eine Rückerstattung"
|
|
235
|
+
result = client.search_intents(summary)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
A summary in another language still matches intents on meaning, but misses the full-text half of the search, so the results are worse. The prompt and graph from `get_workflow` are in the same language as the agent's workflows; tell your model which language to answer the customer in.
|
|
239
|
+
|
|
240
|
+
### Workflow errors
|
|
241
|
+
|
|
242
|
+
`get_workflow` raises these; branch on `.code`:
|
|
243
|
+
|
|
244
|
+
| `.code` | Exception | Meaning | What the agent should do |
|
|
245
|
+
|---|---|---|---|
|
|
246
|
+
| `intent_not_found` | `NotFoundError` (404) | The agent's intents changed | Search again |
|
|
247
|
+
| `workflow_not_found` | `NotFoundError` (404) | The intent has no workflow yet | Hand over |
|
|
248
|
+
| `workflow_not_published` | `ConflictError` (409) | The workflow isn't published | Hand over |
|
|
249
|
+
| `workflow_version_not_found` | `NotFoundError` (404) | The pinned `version=` is unknown, a draft or retired | Leave out `version=` to get the published version |
|
|
250
|
+
|
|
251
|
+
## Errors and retries
|
|
252
|
+
|
|
253
|
+
API, network and configuration errors raise a subclass of `entrove.EntroveError`. Invalid arguments, such as a malformed `Activity` or an empty batch, raise `ValueError` (pydantic's `ValidationError` is one).
|
|
254
|
+
|
|
255
|
+
| Exception | When |
|
|
256
|
+
|---|---|
|
|
257
|
+
| `BadRequestError` (400) | Invalid body, e.g. not 1 to 100 activities; see `.details` |
|
|
258
|
+
| `AuthenticationError` (401) | Missing, unknown or revoked key |
|
|
259
|
+
| `PermissionDeniedError` (403) | The key lacks the scope |
|
|
260
|
+
| `NotFoundError` (404) | Unknown intent, workflow or version; see [Workflow errors](#workflow-errors) |
|
|
261
|
+
| `ConflictError` (409) | `workflow_not_published` |
|
|
262
|
+
| `PayloadTooLargeError` (413) | Body over 1 MB |
|
|
263
|
+
| `RateLimitError` (429) | `.code` is `rate_limited` or `quota_exceeded`; `.retry_after` in seconds |
|
|
264
|
+
| `InternalServerError` (5xx) | Server error, including 503 `intent_search_unavailable` (search is down) and `tool_mapping_unavailable` (the tool mapping failed or took over a minute) |
|
|
265
|
+
| `APIConnectionError` / `APITimeoutError` | No response |
|
|
266
|
+
|
|
267
|
+
Every `APIStatusError` carries `.status_code`, `.code` and `.request_id`. Quote the request id when reporting a problem.
|
|
268
|
+
|
|
269
|
+
The client retries connection errors, timeouts, 5xx responses and `rate_limited` up to `max_retries` times (default 2). It honours `Retry-After` up to 60 seconds and backs off with jitter otherwise. It never retries `quota_exceeded` or other 4xx errors. Retrying is safe: activities upsert by `external_id`, and `search_intents` and `get_workflow` change nothing.
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
from entrove import Entrove
|
|
273
|
+
|
|
274
|
+
client = Entrove(max_retries=5, timeout=30)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Each retry is logged at `INFO` on the `entrove` logger, with the error and its request id.
|
|
278
|
+
|
|
279
|
+
## Testing
|
|
280
|
+
|
|
281
|
+
`entrove.testing.FakeEntrove` has the same methods as `Entrove`, but sends nothing. It builds each request body exactly as `Entrove` would and records it, then returns every item as `created`. It doesn't model the API: nothing is stored, merged or rejected.
|
|
282
|
+
|
|
283
|
+
```python
|
|
284
|
+
from entrove.testing import FakeEntrove
|
|
285
|
+
|
|
286
|
+
fake = FakeEntrove()
|
|
287
|
+
my_agent.run(entrove=fake)
|
|
288
|
+
assert fake.posted[-1]["status"] == "done" # activities in API (camelCase) field names
|
|
289
|
+
assert len(fake.batches) == 1 # one entry per post call
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Set `fake.error` to an exception to make the next call raise it, or `fake.result` to an `ActivityBatchResult` to make the next post return it (to test how your code handles rejected items, say). `fake.me_calls` counts `me()` calls. `entrove.testing.AsyncFakeEntrove` does the same for `AsyncEntrove`.
|
|
293
|
+
|
|
294
|
+
For an agent that runs workflows, pass `intents=` and `workflows=`. `search_intents` returns all the intents, as the API does for an agent with 20 or fewer (set `fake.intent_search_result` to make the next search return something else, such as a `hybrid` result). `get_workflow` returns the `WorkflowPrompt` scripted for that intent id, as given, without mapping tools, and raises `NotFoundError` (`intent_not_found`) for any other id. `fake.intent_searches` and `fake.workflow_requests` record each body sent:
|
|
295
|
+
|
|
296
|
+
```python
|
|
297
|
+
from entrove import Intent, WorkflowPrompt
|
|
298
|
+
from entrove.testing import FakeEntrove
|
|
299
|
+
|
|
300
|
+
gift_card = Intent(id="gift-card-not-received", name="Gift card not received")
|
|
301
|
+
fake = FakeEntrove(
|
|
302
|
+
intents=[gift_card],
|
|
303
|
+
workflows={gift_card.id: WorkflowPrompt.model_validate_json(saved_json)}, # saved with wf.model_dump_json()
|
|
304
|
+
)
|
|
305
|
+
my_agent.run(entrove=fake)
|
|
306
|
+
assert fake.workflow_requests[-1]["intentId"] == gift_card.id
|
|
307
|
+
assert [t["name"] for t in fake.workflow_requests[-1]["tools"]] == ["get_order"] # in API field names
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Type your own code against the `EntroveClient` protocol (or `AsyncEntroveClient`), so it accepts either the real client or the fake:
|
|
311
|
+
|
|
312
|
+
```python
|
|
313
|
+
from entrove import AsyncEntroveClient, EntroveClient
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def report_turn(entrove: EntroveClient, ticket_id: str) -> None: ...
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
async def report_turn_async(entrove: AsyncEntroveClient, ticket_id: str) -> None: ...
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Development
|
|
323
|
+
|
|
324
|
+
```sh
|
|
325
|
+
uv sync
|
|
326
|
+
uv run pytest
|
|
327
|
+
uv run ruff check && uv run ruff format --check
|
|
328
|
+
uv run pyright
|
|
329
|
+
pre-commit install --hook-type pre-commit --hook-type pre-push
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Releasing
|
|
333
|
+
|
|
334
|
+
1. Bump `version` in `pyproject.toml` and add a `CHANGELOG.md` entry.
|
|
335
|
+
2. Publish a GitHub release tagged `vX.Y.Z`. The release workflow tests the code, builds it and uploads it to PyPI using trusted publishing. For `v0.2.0` only, it also publishes the last release of `rhyme-sdk` (`packages/rhyme-sdk`), the pre-rename package that installs `entrove-sdk` and the `rhyme` alias; `rhyme-sdk` is archived after that.
|
|
336
|
+
|
|
337
|
+
## License
|
|
338
|
+
|
|
339
|
+
Apache-2.0. See [LICENSE](LICENSE).
|