aight 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.
aight-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.
aight-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: aight
3
+ Version: 0.1.0
4
+ Summary: Attribute LLM spend to the exact source line, and push it to the AIght Workspace at aight.studio.
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://aight.studio
7
+ Project-URL: Repository, https://github.com/theunknownport/aight-clients
8
+ Requires-Python: >=3.11
9
+ License-File: LICENSE
10
+ Requires-Dist: opentelemetry-api>=1.27
11
+ Requires-Dist: opentelemetry-sdk>=1.27
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest; extra == "dev"
14
+ Requires-Dist: ruff; extra == "dev"
15
+ Provides-Extra: examples
16
+ Requires-Dist: langgraph>=0.2; extra == "examples"
17
+ Provides-Extra: openai
18
+ Requires-Dist: opentelemetry-instrumentation-openai>=0.30.0; extra == "openai"
19
+ Provides-Extra: anthropic
20
+ Requires-Dist: opentelemetry-instrumentation-anthropic>=0.30.0; extra == "anthropic"
21
+ Dynamic: license-file
aight-0.1.0/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # aight (Python SDK)
2
+
3
+ Attributes LLM spend to the exact source line that issued it, and pushes it
4
+ to your [aight.studio](https://aight.studio) AIght Workspace.
5
+
6
+ No price table ships in this SDK, by design. The SDK sends the model and the
7
+ token counts; **the platform prices them** — it recomputes `cost_usd` for
8
+ every row at receive time — so the dollar figures in the AIght Workspace are
9
+ always the platform's current prices, never a snapshot frozen at install
10
+ time. `traced_llm_call` therefore returns `None`, not a cost.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pip install aight
16
+ ```
17
+
18
+ That is the whole install, and it also puts `aight-collect` on your path — the
19
+ Claude Code collector, which is a separate thing from the SDK and is described
20
+ under [External agents](#external-agents-claude-code) below.
21
+
22
+ ## Deploy with your AI coding agent
23
+
24
+ Paste this into Claude Code, Cursor, or any other coding agent, in whatever
25
+ project you want traced:
26
+
27
+ > Run `pip install "aight[openai,anthropic]"`, then read the `AGENTS.md` file
28
+ > next to the installed `aight` package and follow it to wire up cost
29
+ > attribution for this project.
30
+
31
+ `AGENTS.md` ships inside the package (`python -c "import aight, pathlib; print(pathlib.Path(aight.__file__).parent / 'AGENTS.md')"`)
32
+ so the agent has the full integration recipe locally — no extra fetch, and
33
+ nothing it has to be able to reach over the network.
34
+
35
+ ## Use
36
+
37
+ ```python
38
+ from aight.tracing import traced_llm_call, COST_PROCESSOR
39
+ from aight.remote import push
40
+
41
+ traced_llm_call("gpt-4o-mini", input_tokens=180, output_tokens=60)
42
+ # ...wrap every LLM call your agent makes the same way...
43
+
44
+ push(COST_PROCESSOR.buckets) # reads AIGHT_API_KEY from the environment
45
+ ```
46
+
47
+ Get an API key from the Integrate tab of your AIght Workspace, then:
48
+
49
+ ```bash
50
+ export AIGHT_API_KEY="aight_..."
51
+ ```
52
+
53
+ `traced_llm_call` walks the call stack past known framework packages
54
+ (LangGraph, LangChain) to attribute the span to your code, not theirs.
55
+
56
+ ### Latency is yours to measure
57
+
58
+ This SDK does not time the LLM call. It is called *after* your call returns,
59
+ not around it, so a duration taken here would measure the cost of recording
60
+ rather than the cost of the model. Time the call yourself and pass it:
61
+
62
+ ```python
63
+ import time
64
+ from aight.tracing import traced_llm_call
65
+
66
+ started = time.perf_counter()
67
+ response = client.chat.completions.create(...)
68
+ elapsed_ms = (time.perf_counter() - started) * 1000
69
+
70
+ traced_llm_call(model, input_tokens, output_tokens, latency_ms=elapsed_ms)
71
+ ```
72
+
73
+ Leave `latency_ms` out and no latency is claimed — the Workspace shows "—" on
74
+ that agent's Speed axis rather than an impossibly fast number. The
75
+ auto-instrumented path cannot measure it either, so rows it records carry
76
+ none: if you want Speed for a call, wrap that call by hand.
77
+
78
+ ## Auto-instrument (no manual wrapping)
79
+
80
+ ```bash
81
+ pip install "aight[openai]" # or aight[anthropic]
82
+ ```
83
+
84
+ ```python
85
+ from aight.auto import auto_instrument
86
+ from aight.remote import push
87
+ from aight.tracing import COST_PROCESSOR
88
+
89
+ auto_instrument()
90
+ # ...call the OpenAI/Anthropic client exactly as you normally would...
91
+
92
+ push(COST_PROCESSOR.buckets)
93
+ ```
94
+
95
+ `auto_instrument()` silently skips any provider whose instrumentor package
96
+ isn't installed, so it's safe to call unconditionally. It patches the provider
97
+ client, not the call, so the rows it records carry no latency — see above.
98
+
99
+ ## Spent vs earned
100
+
101
+ Report the value your agent generates alongside its spend, to power the
102
+ AIght Workspace's spent-vs-earned view:
103
+
104
+ ```python
105
+ from aight.tracing import report_value, VALUE_BY_FILE
106
+ from aight.remote import push_value
107
+
108
+ report_value(49.0) # a closed deal, a resolved ticket — whatever you count
109
+ push_value(VALUE_BY_FILE)
110
+ ```
111
+
112
+ `push_value` sends what has accumulated and clears it once the server has
113
+ acknowledged — so calling it every flush sends each earning once, and a failed
114
+ push keeps the total for the retry instead of losing it.
115
+
116
+ ## Local-only mode
117
+
118
+ Skip `push()` and call `COST_PROCESSOR.report()` instead — a plain-text
119
+ calls-and-tokens-by-line report with no network calls, useful for local
120
+ debugging or fully offline use. It has no dollar figure: pricing is the
121
+ platform's, so spend only appears in the AIght Workspace once you push.
122
+
123
+ ```
124
+ examples/snippet_check.py:19 (plan_step) [gpt-4o-mini] = 3 call(s), 540 in / 180 out
125
+ ```
126
+
127
+ ## External agents (Claude Code)
128
+
129
+ Everything above is for an agent *you wrote*: the SDK walks your call stack to
130
+ find the line that issued the call. An agent you run but did not write has no
131
+ line of yours on the stack, so there is nothing to instrument and no library to
132
+ import. AIght traces those by reading the agent's own transcripts instead.
133
+
134
+ `pip install aight` also installs `aight-collect`:
135
+
136
+ ```bash
137
+ export AIGHT_API_KEY="aight_..."
138
+
139
+ aight-collect --dry-run # print the rows instead of sending them
140
+ aight-collect # push them
141
+ ```
142
+
143
+ It reads Claude Code's transcripts under `~/.claude/projects` and pushes one
144
+ row per step the agent took, under an external agent called `claude-code`. Cost
145
+ lands on the step — the tool it called and the file it touched — rather than on
146
+ a source line, because no source line of yours is involved.
147
+
148
+ Three things are worth knowing before the first run:
149
+
150
+ - **A plain run resumes.** It records the newest call it pushed for each
151
+ transcript file in `~/.aight/`, so a second run sends only what is new.
152
+ Running it repeatedly is the intended use.
153
+ - **`--all-time` does not resume.** It re-sends the whole history, and the API
154
+ *adds* what it receives to what it already holds — so pushing the same calls
155
+ twice doubles the recorded spend permanently. Cost is frozen at receive time
156
+ and there is no repair path. Reach for it only on a transcript that has never
157
+ been pushed.
158
+ - **The key alone decides the destination.** A run prints the project its rows
159
+ landed in and stops rather than resuming when that differs from the project
160
+ its earlier pushes went to. A key copied out of another project's Integrate
161
+ tab otherwise reads exactly like success, and fills a workspace nobody is
162
+ looking at.
163
+
164
+ Without installing anything:
165
+
166
+ ```bash
167
+ uvx --from aight aight-collect --dry-run
168
+ ```
169
+
170
+ ## Example
171
+
172
+ `examples/langgraph_spike.py` traces a 3-node LangGraph agent and prints the
173
+ attribution report (also pushes it, if `AIGHT_API_KEY` is set). It ships in the
174
+ repo rather than in the wheel, so run it from a clone:
175
+
176
+ ```bash
177
+ cd /path/to/aight-clients/python
178
+ pip install ".[examples]" # langgraph; ".[dev,examples]" adds pytest and ruff
179
+ python -m examples.langgraph_spike
180
+ ```
@@ -0,0 +1,60 @@
1
+ aight — instructions for an AI coding agent
2
+ You are integrating aight into a project. aight attributes LLM spend to the exact source line that issued it, and pushes it to the hosted AIght Workspace at aight.studio. This file is your complete instruction set — follow it, don't guess at the API.
3
+ 1. Install
4
+ You already ran the one command that got you here:
5
+ pip install "aight[openai,anthropic]"
6
+ Drop whichever of openai/anthropic the target project doesn't actually use — check its dependencies first.
7
+ 2. Get an API key
8
+ Tell the user to mint one from the project's settings page in the AIght Workspace — the project selector at the top left, then Project settings — and set it as an environment variable, never hardcoded in source:
9
+ export AIGHT_API_KEY="aight_..."
10
+ 3. Instrument the LLM calls — pick ONE path
11
+ Path A — the project calls the OpenAI or Anthropic Python client directly. This is almost always the right path; it needs no changes to call sites:
12
+ from aight.auto import auto_instrument
13
+ auto_instrument() # call once, near process startup, before any LLM calls
14
+ Path B — no supported client library, or you want explicit control. Wrap each call site with traced_llm_call, passing the real model name and token counts from that call's actual response (never estimate them):
15
+ from aight.tracing import traced_llm_call
16
+ traced_llm_call(model, input_tokens=resp.usage.input_tokens, output_tokens=resp.usage.output_tokens)
17
+ traced_llm_call returns None, and that is deliberate: this SDK ships no price table. It records the model and the token counts, and the platform prices them at receive time — the dollar figure lives in the AIght Workspace, never in your process. Never report a cost of your own for it to use.
18
+ Do not do both — auto-instrumentation and manual wrapping of the same call double-count it.
19
+ Latency is the caller's to measure, on both paths. This SDK records a call after it returns, not around it, so it has no duration of its own to report and must not invent one: time the call yourself and pass it as latency_ms=elapsed_ms, and let it be absent where you didn't measure it. A row with no latency shows as "—" on the agent's Speed axis in the Workspace — that is the correct answer for a call nobody timed, not a gap to fill with a guess.
20
+ 4. Push the data home
21
+ Call this after a traced run completes (end of a request handler, a batch job, a shutdown hook — wherever makes sense for how this project runs):
22
+ from aight.remote import push
23
+ from aight.tracing import COST_PROCESSOR
24
+ push(COST_PROCESSOR.buckets)
25
+ 5. Verify before you push
26
+ Confirm attribution worked locally, with no network call, before wiring up push():
27
+ python -c "from aight.tracing import COST_PROCESSOR; print(COST_PROCESSOR.report())"
28
+ You should see the project's own file/line, not a framework's internal dispatch code. The report is calls and tokens per line — the sanity check is that the line and the token counts are right and the model name is real. There is no cost in it; the platform prices the pushed rows.
29
+ 6. Optional: Business value & direct metrics
30
+ Only call report_value() if this project has a real, countable signal for what it earned — never invent or estimate a number:
31
+ from aight.tracing import report_value, VALUE_BY_FILE
32
+ from aight.remote import push_value
33
+ report_value(49.0)
34
+ push_value(VALUE_BY_FILE)
35
+ 7. Optional: Agnostic business matching, Trace IDs & Labels
36
+ To link LLM costs explicitly to business events (like a Stripe checkout, a conversion, or custom tiers) without hardcoding any specific business model, use TraceContext or pass parameters directly:
37
+ Option A — Using TraceContext for an execution scope (recommended for web requests / checkouts):
38
+ import aight.tracing as aight
39
+
40
+ with aight.TraceContext(trace_id="chk_12345_stripe", labels={"tier": "enterprise", "feature": "pdf_extractor"}):
41
+ aight.traced_llm_call("gpt-4", input_tokens=500, output_tokens=150)
42
+ Option B — Passing parameters directly to a call:
43
+ from aight.tracing import traced_llm_call
44
+
45
+ traced_llm_call(
46
+ "gpt-4",
47
+ input_tokens=200,
48
+ output_tokens=50,
49
+ trace_id="custom_event_id",
50
+ labels={"campaign": "black_friday"}
51
+ )
52
+ 8. Optional: Report the business event itself
53
+ A trace_id or labels only tag the LLM cost side — to actually feed cost-vs-value matching, push the business event too (a Stripe checkout succeeding, a ticket closing, a signup). Give it a real event_name and value; leave trace_id unset to fall back to the active TraceContext:
54
+ from aight.remote import push_event
55
+
56
+ push_event("checkout_completed", value=49.0, currency="USD")
57
+ Guardrails
58
+ Never fabricate a metric aight doesn't actually capture — latency included. It is never estimated, never inferred from how long the SDK took, and never defaulted to zero-with-a-mention; it is simply absent until the caller measures and passes it.
59
+ Don't wrap the same call twice (Path A and Path B together).
60
+ AIGHT_API_KEY is a secret: env var or secrets manager, never committed.
@@ -0,0 +1,26 @@
1
+ """AIght SDK: attribute LLM spend to the exact source line that issued it,
2
+ and push that data to your hosted AIght Workspace.
3
+
4
+ Auto-instrument a supported provider so every real call is traced with no
5
+ per-call wrapping. Needs that provider's extra (`aight[openai]` /
6
+ `aight[anthropic]`), installed from the git URL in the README — this SDK is
7
+ not on PyPI:
8
+
9
+ from aight.auto import auto_instrument
10
+ from aight.remote import push
11
+ from aight.tracing import COST_PROCESSOR
12
+
13
+ auto_instrument()
14
+ # ...call your LLM client as normal...
15
+ push(COST_PROCESSOR.buckets)
16
+
17
+ Or trace manually, call by call:
18
+
19
+ from aight.tracing import traced_llm_call, COST_PROCESSOR
20
+ from aight.remote import push
21
+
22
+ traced_llm_call("gpt-4o-mini", input_tokens=180, output_tokens=60)
23
+ push(COST_PROCESSOR.buckets)
24
+ """
25
+
26
+ __version__ = "0.1.0"
@@ -0,0 +1,53 @@
1
+ """Auto-instrumentation: patches supported LLM provider clients so every
2
+ real call is traced without wrapping each one in traced_llm_call().
3
+
4
+ Each provider's OTel instrumentor package is optional. Install the extra
5
+ for whatever you use (`aight[openai]`, `aight[anthropic]`, from the git URL
6
+ in the README — this SDK is not on PyPI); anything not installed is skipped,
7
+ not an error, so a customer using only one provider never has to install the
8
+ other's instrumentor.
9
+
10
+ Auto-instrumented calls carry no latency. A duration is reported only when
11
+ the caller measures the call and passes it to traced_llm_call(), and an
12
+ instrumentor has none to pass — so those rows show "—" on the Speed axis
13
+ rather than a number nobody took.
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import importlib
18
+ import logging
19
+
20
+ logger = logging.getLogger("aight.auto")
21
+
22
+ _INSTRUMENTORS = {
23
+ "openai": ("opentelemetry.instrumentation.openai", "OpenAIInstrumentor"),
24
+ "anthropic": ("opentelemetry.instrumentation.anthropic", "AnthropicInstrumentor"),
25
+ }
26
+
27
+ _instrumented: set[str] = set()
28
+
29
+
30
+ def auto_instrument(providers: list[str] | None = None) -> list[str]:
31
+ """Instrument each named provider's client library (default: every
32
+ known provider). Returns the providers actually instrumented this call.
33
+ A provider whose instrumentor package isn't installed, or that's
34
+ already instrumented, is silently skipped."""
35
+ names = providers if providers is not None else list(_INSTRUMENTORS)
36
+ done = []
37
+ for name in names:
38
+ if name in _instrumented:
39
+ continue
40
+ target = _INSTRUMENTORS.get(name)
41
+ if target is None:
42
+ logger.warning("aight: unknown provider %r, skipping", name)
43
+ continue
44
+ module_name, class_name = target
45
+ try:
46
+ module = importlib.import_module(module_name)
47
+ instrumentor_cls = getattr(module, class_name)
48
+ except (ImportError, AttributeError):
49
+ continue
50
+ instrumentor_cls().instrument()
51
+ _instrumented.add(name)
52
+ done.append(name)
53
+ return done
@@ -0,0 +1,7 @@
1
+ """Collectors for agents the customer runs but did not write.
2
+
3
+ Each reads an agent's own on-disk record of the calls it made and pushes one
4
+ row per step. Unlike the SDKs these instrument nothing — there is no customer
5
+ code on the stack to bind to, which is why the chain they push is a step path
6
+ rather than a source path. See docs/hub/agents.md external-agent section.
7
+ """