elan-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. elan_sdk-0.1.0/.gitignore +45 -0
  2. elan_sdk-0.1.0/LICENSE +202 -0
  3. elan_sdk-0.1.0/PKG-INFO +213 -0
  4. elan_sdk-0.1.0/README.md +188 -0
  5. elan_sdk-0.1.0/pyproject.toml +113 -0
  6. elan_sdk-0.1.0/src/elan_sdk/__init__.py +175 -0
  7. elan_sdk-0.1.0/src/elan_sdk/_tls.py +35 -0
  8. elan_sdk-0.1.0/src/elan_sdk/_version.py +8 -0
  9. elan_sdk-0.1.0/src/elan_sdk/actions.py +253 -0
  10. elan_sdk-0.1.0/src/elan_sdk/agents.py +44 -0
  11. elan_sdk-0.1.0/src/elan_sdk/analytics.py +323 -0
  12. elan_sdk-0.1.0/src/elan_sdk/approvals.py +182 -0
  13. elan_sdk-0.1.0/src/elan_sdk/artifacts.py +213 -0
  14. elan_sdk-0.1.0/src/elan_sdk/auth.py +182 -0
  15. elan_sdk-0.1.0/src/elan_sdk/autonomy.py +166 -0
  16. elan_sdk-0.1.0/src/elan_sdk/client.py +210 -0
  17. elan_sdk-0.1.0/src/elan_sdk/config.py +83 -0
  18. elan_sdk-0.1.0/src/elan_sdk/errors.py +297 -0
  19. elan_sdk-0.1.0/src/elan_sdk/http.py +269 -0
  20. elan_sdk-0.1.0/src/elan_sdk/models/__init__.py +14 -0
  21. elan_sdk-0.1.0/src/elan_sdk/models/actions.py +436 -0
  22. elan_sdk-0.1.0/src/elan_sdk/models/agents.py +100 -0
  23. elan_sdk-0.1.0/src/elan_sdk/models/events.py +183 -0
  24. elan_sdk-0.1.0/src/elan_sdk/models/invocations.py +194 -0
  25. elan_sdk-0.1.0/src/elan_sdk/models/money.py +601 -0
  26. elan_sdk-0.1.0/src/elan_sdk/money.py +58 -0
  27. elan_sdk-0.1.0/src/elan_sdk/py.typed +0 -0
  28. elan_sdk-0.1.0/src/elan_sdk/runs.py +185 -0
  29. elan_sdk-0.1.0/src/elan_sdk/runtime.py +277 -0
  30. elan_sdk-0.1.0/src/elan_sdk/sessions.py +192 -0
  31. elan_sdk-0.1.0/src/elan_sdk/stream.py +294 -0
  32. elan_sdk-0.1.0/src/elan_sdk/sync.py +238 -0
  33. elan_sdk-0.1.0/src/elan_sdk/tickets.py +71 -0
  34. elan_sdk-0.1.0/src/elan_sdk/tools.py +84 -0
  35. elan_sdk-0.1.0/src/elan_sdk/wallets.py +197 -0
@@ -0,0 +1,45 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .env
5
+ .env.docker
6
+ .uvcache/
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ node_modules/
11
+ .next/
12
+ # TypeScript incremental build cache: rewritten by every portal build, so
13
+ # tracking it dirties the tree on each one and now on every CI run.
14
+ *.tsbuildinfo
15
+ .terraform/
16
+ .terraform.lock.hcl
17
+ tfplan
18
+ *.tfstate*
19
+ .pytest_cache/
20
+ .ruff_cache/
21
+ catalog.json
22
+ .ref/
23
+
24
+ .local/
25
+ # Per environment (ADR-0179): one shared file meant building for a second
26
+ # environment overwrote the first's recorded digests.
27
+ .platform-digests.*
28
+
29
+ # Terraform plan files. Build artefacts, and a plan can carry values read
30
+ # from state — including ones marked sensitive. `tfplan` alone did not match
31
+ # `np.tfplan`, which is how one came to be committed.
32
+ *.tfplan
33
+
34
+ # Per-developer Claude Code settings. `.claude/settings.json` is the shared,
35
+ # checked-in one; this is the personal override beside it, and it routinely
36
+ # holds machine-specific permission grants — a `kubectl exec` allowance for
37
+ # somebody's own cluster has no business in a repo that is also the starter
38
+ # template for new projects.
39
+ .claude/settings.local.json
40
+
41
+ # GENERATED AT BUILD from the prerendered documentation, by
42
+ # ui/console/scripts/gen-llms.mjs. A build artifact like `.next` and the SDK's
43
+ # `dist`: committing it would mean a second copy of every documentation page
44
+ # in the history, going stale between builds.
45
+ ui/console/public/llms-full.txt
elan_sdk-0.1.0/LICENSE ADDED
@@ -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,213 @@
1
+ Metadata-Version: 2.5
2
+ Name: elan-sdk
3
+ Version: 0.1.0
4
+ Summary: The Elan API, as a developer's backend calls it
5
+ Project-URL: Homepage, https://openelan.ai
6
+ Project-URL: Documentation, https://openelan.ai/app/docs
7
+ Author-email: Elan <support@openelan.ai>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: adk,agent-platform,agents,ai,llm
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.12
19
+ Requires-Dist: certifi>=2024.2.2
20
+ Requires-Dist: elan-agentkit-contracts
21
+ Requires-Dist: httpx>=0.27
22
+ Requires-Dist: pydantic>=2.9
23
+ Requires-Dist: websockets>=13.0
24
+ Description-Content-Type: text/markdown
25
+
26
+ # elan-sdk
27
+
28
+ Call the Elan platform's agents, approvals and billing from your own backend.
29
+
30
+ Async-first, with a synchronous facade for scripts and notebooks. It talks to
31
+ the same API the CLI and the console do.
32
+
33
+ ```bash
34
+ uv add elan-sdk # or: pip install elan-sdk
35
+ ```
36
+
37
+ Requires Python 3.12 or newer.
38
+
39
+ ## The five-line version
40
+
41
+ ```python
42
+ from elan_sdk import Elan
43
+
44
+ elan = Elan.from_env()
45
+ reply = elan.runtime.run("invoice-triage", "What do I owe on INV-9?")
46
+ print(reply.text)
47
+ ```
48
+
49
+ `from_env()` reads `ELAN_CLIENT_ID`, `ELAN_CLIENT_SECRET` and `ELAN_PROJECT`.
50
+ `ELAN_API_URL` defaults to the production API, so you set it only to point
51
+ somewhere else.
52
+
53
+ That one call subscribes to the event stream, waits for the subscription to be
54
+ acknowledged, publishes the invocation, filters the stream to this run, joins
55
+ the reply's parts, stops at a terminal event and closes the socket. Every one of
56
+ those steps is something a hand-rolled client has got wrong.
57
+
58
+ `AsyncElan` is the same surface with `await`.
59
+
60
+ ## What it covers
61
+
62
+ | Namespace | What it is for |
63
+ |---|---|
64
+ | `runtime` | start a run, watch its events, resume a paused one |
65
+ | `runs` | read a finished run back |
66
+ | `sessions` | conversations: create, list, read back and delete — from your agent's own database |
67
+ | `actions` | the approval inbox, and deciding a tool confirmation |
68
+ | `approvals` | approvals asked of somebody outside the conversation |
69
+ | `tools` | long-running tool calls your own backend owes an answer to |
70
+ | `autonomy` | what a tool may do without asking, per user and per tenant |
71
+ | `wallets` / `credit` | your end users' balances — read and write, split apart |
72
+ | `usage` / `analytics` | what your agents have consumed, and your own balance |
73
+ | `artifacts` | files an agent can read, uploaded without passing through us |
74
+ | `tickets` | a short-lived credential so a browser can watch a run |
75
+ | `agents` | what is deployed, and what it declares |
76
+
77
+ ## Watching events yourself
78
+
79
+ The rest of this page uses `AsyncElan`, since streaming is where `await` earns
80
+ its keep. `Elan` has every one of these methods too, without the `await`.
81
+
82
+ Subscribe **before** you invoke. That ordering is the whole reason this is a
83
+ context manager — subscribing afterwards loses the entire reply on a warm agent.
84
+
85
+ ```python
86
+ async with elan.runtime.watching("sess-ada-1") as stream:
87
+ await elan.runtime.invoke("hotel-concierge", "hi", session_id="sess-ada-1")
88
+ async for event in stream.events():
89
+ print(event.kind, event.text)
90
+ ```
91
+
92
+ ## Running for one of your end users
93
+
94
+ `invoke` takes `end_user_id`; `run` deliberately does not. Naming a user
95
+ addresses that run's events to **them**, so a backend that invoked and watched
96
+ in one process would see nothing — the SDK raises `EndUserEventsElsewhere`
97
+ rather than hanging.
98
+
99
+ ```python
100
+ await elan.runtime.invoke(
101
+ "hotel-concierge", "refund my last night",
102
+ session_id="sess-ada-1", end_user_id="ada")
103
+ ```
104
+
105
+ Their browser cannot hold your client secret, so mint a **ticket** — it opens
106
+ the event stream and nothing else:
107
+
108
+ ```python
109
+ ticket = await elan.tickets.mint(end_user_id="ada",
110
+ origin="https://app.acme.example")
111
+ ```
112
+
113
+ ## Seeding state and bounding a run
114
+
115
+ `invoke`, `run` and `Conversation.say` take two of ADK's own `run_async`
116
+ options. Both are sent only when set, so an ordinary message is unchanged.
117
+
118
+ ```python
119
+ reply = await elan.runtime.run(
120
+ "hotel-concierge", "Is late checkout available?",
121
+ session_id="sess-ada-1",
122
+ state_delta={"room": "412"},
123
+ run_config={"max_llm_calls": 5,
124
+ "custom_metadata": {"request_id": "req-81c2"}})
125
+ ```
126
+
127
+ - `state_delta` writes keys into **this conversation's** state on this turn.
128
+ `app:`, `user:`, `temp:` and `agentkit:` keys are refused with a `BadRequest`
129
+ naming the key — they would reach other users or other conversations, or
130
+ would not be kept. At most 64 KiB.
131
+ - `run_config` accepts `max_llm_calls`, which can only **lower** the agent's
132
+ own limit, and `custom_metadata`, which ADK stamps on every event the run
133
+ emits. Anything else is refused by name.
134
+
135
+ An agent deployed before these options existed must be **redeployed once**
136
+ before it accepts an invocation carrying either.
137
+
138
+ ## Conversations
139
+
140
+ A conversation lives in your agent's own database, and `elan.sessions` reads
141
+ it there, through ADK's own session service — so the history is exactly what
142
+ the agent saw.
143
+
144
+ ```python
145
+ await elan.sessions.create("hotel-concierge", session_id="sess-ada-1",
146
+ user="ada", state={"plan": "pro"},
147
+ title="Late checkout for room 412") # the agent never sees it
148
+
149
+ for s in await elan.sessions.list("hotel-concierge", user="ada"):
150
+ print(s.id, s.title, s.state_keys) # newest first
151
+
152
+ events = await elan.sessions.events("hotel-concierge", "sess-ada-1",
153
+ user="ada", recent=200)
154
+ for turn in await elan.sessions.turns("hotel-concierge", "sess-ada-1", user="ada"):
155
+ print(turn.role, turn.text)
156
+
157
+ await elan.sessions.delete("hotel-concierge", "sess-ada-1", user="ada")
158
+ ```
159
+
160
+ - **`events()` returns the same `AgentEvent`s the stream delivers**, so one
161
+ fold renders a live run and a reopened conversation, and `ends_the_run`
162
+ ends each turn in both. `turns()` is the messages alone; `get()` is the
163
+ state without the events; `run()` is a workflow's steps and pause.
164
+ - **`user=` names one of your end users** by your own id and needs a tenant
165
+ admin. Without it, every method acts on the caller's own conversations.
166
+ Create and invoke for the same person — a conversation you create as
167
+ yourself is not the one an `end_user_id` invocation runs in.
168
+ - **`recent` and `after` page a long conversation.** `after` is inclusive and
169
+ `seq` is numbered per response, so dedupe on `emitted_at`.
170
+ - **A `Conflict` saying "redeploy it once" means exactly that**: the agent was
171
+ deployed before its history could be read.
172
+ - Every method takes `project=`; without it, the client's own.
173
+
174
+ `elan.runs` answers a different question — how one run ended and what it cost.
175
+
176
+ ## Paused runs
177
+
178
+ A run that stops to ask a person something emits **no terminal event**. A client
179
+ waiting for one waits out its whole timeout. Read the interrupt instead:
180
+
181
+ ```python
182
+ from elan_sdk.models.events import ends_the_run
183
+
184
+ async for event in stream.events():
185
+ if ends_the_run(event):
186
+ break
187
+ ```
188
+
189
+ ## Money
190
+
191
+ Everything a wallet reports is **micro-USD** — divide by 1,000,000. Your
192
+ tenant's own balance is in **tokens**, which is why the two use different field
193
+ names (`balance_micros` against `balance_units`) rather than one whose unit a
194
+ reader has to know.
195
+
196
+ Reads and writes are deliberately separate objects: `elan.wallets` issues no
197
+ non-GET at all, so a read-only credential can be handed it and a future write
198
+ cannot quietly land on it. `elan.credit` is the write half.
199
+
200
+ ## Errors
201
+
202
+ Every failure is an `ElanError` subclass carrying the status and the service's
203
+ own message — `BadRequest`, `Unauthorized`, `Forbidden`, `NotFound`,
204
+ `Conflict`, `TransportError`. Nothing raises a bare `httpx` exception.
205
+
206
+ ## Documentation
207
+
208
+ Full guides, the API reference and the TypeScript half are at
209
+ <https://openelan.ai/app/docs>.
210
+
211
+ ## Licence
212
+
213
+ Apache-2.0. See `LICENSE`.
@@ -0,0 +1,188 @@
1
+ # elan-sdk
2
+
3
+ Call the Elan platform's agents, approvals and billing from your own backend.
4
+
5
+ Async-first, with a synchronous facade for scripts and notebooks. It talks to
6
+ the same API the CLI and the console do.
7
+
8
+ ```bash
9
+ uv add elan-sdk # or: pip install elan-sdk
10
+ ```
11
+
12
+ Requires Python 3.12 or newer.
13
+
14
+ ## The five-line version
15
+
16
+ ```python
17
+ from elan_sdk import Elan
18
+
19
+ elan = Elan.from_env()
20
+ reply = elan.runtime.run("invoice-triage", "What do I owe on INV-9?")
21
+ print(reply.text)
22
+ ```
23
+
24
+ `from_env()` reads `ELAN_CLIENT_ID`, `ELAN_CLIENT_SECRET` and `ELAN_PROJECT`.
25
+ `ELAN_API_URL` defaults to the production API, so you set it only to point
26
+ somewhere else.
27
+
28
+ That one call subscribes to the event stream, waits for the subscription to be
29
+ acknowledged, publishes the invocation, filters the stream to this run, joins
30
+ the reply's parts, stops at a terminal event and closes the socket. Every one of
31
+ those steps is something a hand-rolled client has got wrong.
32
+
33
+ `AsyncElan` is the same surface with `await`.
34
+
35
+ ## What it covers
36
+
37
+ | Namespace | What it is for |
38
+ |---|---|
39
+ | `runtime` | start a run, watch its events, resume a paused one |
40
+ | `runs` | read a finished run back |
41
+ | `sessions` | conversations: create, list, read back and delete — from your agent's own database |
42
+ | `actions` | the approval inbox, and deciding a tool confirmation |
43
+ | `approvals` | approvals asked of somebody outside the conversation |
44
+ | `tools` | long-running tool calls your own backend owes an answer to |
45
+ | `autonomy` | what a tool may do without asking, per user and per tenant |
46
+ | `wallets` / `credit` | your end users' balances — read and write, split apart |
47
+ | `usage` / `analytics` | what your agents have consumed, and your own balance |
48
+ | `artifacts` | files an agent can read, uploaded without passing through us |
49
+ | `tickets` | a short-lived credential so a browser can watch a run |
50
+ | `agents` | what is deployed, and what it declares |
51
+
52
+ ## Watching events yourself
53
+
54
+ The rest of this page uses `AsyncElan`, since streaming is where `await` earns
55
+ its keep. `Elan` has every one of these methods too, without the `await`.
56
+
57
+ Subscribe **before** you invoke. That ordering is the whole reason this is a
58
+ context manager — subscribing afterwards loses the entire reply on a warm agent.
59
+
60
+ ```python
61
+ async with elan.runtime.watching("sess-ada-1") as stream:
62
+ await elan.runtime.invoke("hotel-concierge", "hi", session_id="sess-ada-1")
63
+ async for event in stream.events():
64
+ print(event.kind, event.text)
65
+ ```
66
+
67
+ ## Running for one of your end users
68
+
69
+ `invoke` takes `end_user_id`; `run` deliberately does not. Naming a user
70
+ addresses that run's events to **them**, so a backend that invoked and watched
71
+ in one process would see nothing — the SDK raises `EndUserEventsElsewhere`
72
+ rather than hanging.
73
+
74
+ ```python
75
+ await elan.runtime.invoke(
76
+ "hotel-concierge", "refund my last night",
77
+ session_id="sess-ada-1", end_user_id="ada")
78
+ ```
79
+
80
+ Their browser cannot hold your client secret, so mint a **ticket** — it opens
81
+ the event stream and nothing else:
82
+
83
+ ```python
84
+ ticket = await elan.tickets.mint(end_user_id="ada",
85
+ origin="https://app.acme.example")
86
+ ```
87
+
88
+ ## Seeding state and bounding a run
89
+
90
+ `invoke`, `run` and `Conversation.say` take two of ADK's own `run_async`
91
+ options. Both are sent only when set, so an ordinary message is unchanged.
92
+
93
+ ```python
94
+ reply = await elan.runtime.run(
95
+ "hotel-concierge", "Is late checkout available?",
96
+ session_id="sess-ada-1",
97
+ state_delta={"room": "412"},
98
+ run_config={"max_llm_calls": 5,
99
+ "custom_metadata": {"request_id": "req-81c2"}})
100
+ ```
101
+
102
+ - `state_delta` writes keys into **this conversation's** state on this turn.
103
+ `app:`, `user:`, `temp:` and `agentkit:` keys are refused with a `BadRequest`
104
+ naming the key — they would reach other users or other conversations, or
105
+ would not be kept. At most 64 KiB.
106
+ - `run_config` accepts `max_llm_calls`, which can only **lower** the agent's
107
+ own limit, and `custom_metadata`, which ADK stamps on every event the run
108
+ emits. Anything else is refused by name.
109
+
110
+ An agent deployed before these options existed must be **redeployed once**
111
+ before it accepts an invocation carrying either.
112
+
113
+ ## Conversations
114
+
115
+ A conversation lives in your agent's own database, and `elan.sessions` reads
116
+ it there, through ADK's own session service — so the history is exactly what
117
+ the agent saw.
118
+
119
+ ```python
120
+ await elan.sessions.create("hotel-concierge", session_id="sess-ada-1",
121
+ user="ada", state={"plan": "pro"},
122
+ title="Late checkout for room 412") # the agent never sees it
123
+
124
+ for s in await elan.sessions.list("hotel-concierge", user="ada"):
125
+ print(s.id, s.title, s.state_keys) # newest first
126
+
127
+ events = await elan.sessions.events("hotel-concierge", "sess-ada-1",
128
+ user="ada", recent=200)
129
+ for turn in await elan.sessions.turns("hotel-concierge", "sess-ada-1", user="ada"):
130
+ print(turn.role, turn.text)
131
+
132
+ await elan.sessions.delete("hotel-concierge", "sess-ada-1", user="ada")
133
+ ```
134
+
135
+ - **`events()` returns the same `AgentEvent`s the stream delivers**, so one
136
+ fold renders a live run and a reopened conversation, and `ends_the_run`
137
+ ends each turn in both. `turns()` is the messages alone; `get()` is the
138
+ state without the events; `run()` is a workflow's steps and pause.
139
+ - **`user=` names one of your end users** by your own id and needs a tenant
140
+ admin. Without it, every method acts on the caller's own conversations.
141
+ Create and invoke for the same person — a conversation you create as
142
+ yourself is not the one an `end_user_id` invocation runs in.
143
+ - **`recent` and `after` page a long conversation.** `after` is inclusive and
144
+ `seq` is numbered per response, so dedupe on `emitted_at`.
145
+ - **A `Conflict` saying "redeploy it once" means exactly that**: the agent was
146
+ deployed before its history could be read.
147
+ - Every method takes `project=`; without it, the client's own.
148
+
149
+ `elan.runs` answers a different question — how one run ended and what it cost.
150
+
151
+ ## Paused runs
152
+
153
+ A run that stops to ask a person something emits **no terminal event**. A client
154
+ waiting for one waits out its whole timeout. Read the interrupt instead:
155
+
156
+ ```python
157
+ from elan_sdk.models.events import ends_the_run
158
+
159
+ async for event in stream.events():
160
+ if ends_the_run(event):
161
+ break
162
+ ```
163
+
164
+ ## Money
165
+
166
+ Everything a wallet reports is **micro-USD** — divide by 1,000,000. Your
167
+ tenant's own balance is in **tokens**, which is why the two use different field
168
+ names (`balance_micros` against `balance_units`) rather than one whose unit a
169
+ reader has to know.
170
+
171
+ Reads and writes are deliberately separate objects: `elan.wallets` issues no
172
+ non-GET at all, so a read-only credential can be handed it and a future write
173
+ cannot quietly land on it. `elan.credit` is the write half.
174
+
175
+ ## Errors
176
+
177
+ Every failure is an `ElanError` subclass carrying the status and the service's
178
+ own message — `BadRequest`, `Unauthorized`, `Forbidden`, `NotFound`,
179
+ `Conflict`, `TransportError`. Nothing raises a bare `httpx` exception.
180
+
181
+ ## Documentation
182
+
183
+ Full guides, the API reference and the TypeScript half are at
184
+ <https://openelan.ai/app/docs>.
185
+
186
+ ## Licence
187
+
188
+ Apache-2.0. See `LICENSE`.