aight 0.1.0__py3-none-any.whl

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/AGENTS.md ADDED
@@ -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.
aight/__init__.py ADDED
@@ -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"
aight/auto.py ADDED
@@ -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
+ """