agentflight-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 (87) hide show
  1. agentflight_sdk-0.1.0/.gitignore +9 -0
  2. agentflight_sdk-0.1.0/CHANGELOG.md +203 -0
  3. agentflight_sdk-0.1.0/LICENSE +21 -0
  4. agentflight_sdk-0.1.0/PKG-INFO +836 -0
  5. agentflight_sdk-0.1.0/README.md +783 -0
  6. agentflight_sdk-0.1.0/alembic.ini +37 -0
  7. agentflight_sdk-0.1.0/examples/langgraph_agent.py +72 -0
  8. agentflight_sdk-0.1.0/examples/openai_agent.py +123 -0
  9. agentflight_sdk-0.1.0/examples/replay_agent.py +50 -0
  10. agentflight_sdk-0.1.0/examples/toy_agent.py +82 -0
  11. agentflight_sdk-0.1.0/pyproject.toml +101 -0
  12. agentflight_sdk-0.1.0/scripts/bench_overhead.py +524 -0
  13. agentflight_sdk-0.1.0/scripts/compose_smoke.py +138 -0
  14. agentflight_sdk-0.1.0/scripts/smoke_installed.py +135 -0
  15. agentflight_sdk-0.1.0/src/agentflight/__init__.py +59 -0
  16. agentflight_sdk-0.1.0/src/agentflight/_queue.py +234 -0
  17. agentflight_sdk-0.1.0/src/agentflight/_spool.py +280 -0
  18. agentflight_sdk-0.1.0/src/agentflight/attributes.py +68 -0
  19. agentflight_sdk-0.1.0/src/agentflight/exporter.py +272 -0
  20. agentflight_sdk-0.1.0/src/agentflight/integrations/__init__.py +5 -0
  21. agentflight_sdk-0.1.0/src/agentflight/integrations/langgraph.py +369 -0
  22. agentflight_sdk-0.1.0/src/agentflight/integrations/openai.py +172 -0
  23. agentflight_sdk-0.1.0/src/agentflight/py.typed +0 -0
  24. agentflight_sdk-0.1.0/src/agentflight/replayer.py +436 -0
  25. agentflight_sdk-0.1.0/src/agentflight/sdk.py +803 -0
  26. agentflight_sdk-0.1.0/src/agentflight/server/__init__.py +5 -0
  27. agentflight_sdk-0.1.0/src/agentflight/server/app.py +176 -0
  28. agentflight_sdk-0.1.0/src/agentflight/server/auth.py +87 -0
  29. agentflight_sdk-0.1.0/src/agentflight/server/cli.py +95 -0
  30. agentflight_sdk-0.1.0/src/agentflight/server/db.py +41 -0
  31. agentflight_sdk-0.1.0/src/agentflight/server/limits.py +115 -0
  32. agentflight_sdk-0.1.0/src/agentflight/server/main.py +5 -0
  33. agentflight_sdk-0.1.0/src/agentflight/server/migrations/env.py +38 -0
  34. agentflight_sdk-0.1.0/src/agentflight/server/migrations/script.py.mako +22 -0
  35. agentflight_sdk-0.1.0/src/agentflight/server/migrations/versions/0001_initial.py +58 -0
  36. agentflight_sdk-0.1.0/src/agentflight/server/migrations/versions/0002_event_columns_run_totals.py +168 -0
  37. agentflight_sdk-0.1.0/src/agentflight/server/migrations/versions/0003_unset_status_unknown.py +47 -0
  38. agentflight_sdk-0.1.0/src/agentflight/server/migrations/versions/0004_run_dropped_spans.py +29 -0
  39. agentflight_sdk-0.1.0/src/agentflight/server/models.py +81 -0
  40. agentflight_sdk-0.1.0/src/agentflight/server/schemas.py +91 -0
  41. agentflight_sdk-0.1.0/src/agentflight/server/service.py +483 -0
  42. agentflight_sdk-0.1.0/src/agentflight/server/settings.py +198 -0
  43. agentflight_sdk-0.1.0/src/agentflight/server/viewer/__init__.py +11 -0
  44. agentflight_sdk-0.1.0/src/agentflight/server/viewer/format.py +180 -0
  45. agentflight_sdk-0.1.0/src/agentflight/server/viewer/routes.py +293 -0
  46. agentflight_sdk-0.1.0/src/agentflight/server/viewer/session.py +120 -0
  47. agentflight_sdk-0.1.0/src/agentflight/server/viewer/static/VENDORED.md +32 -0
  48. agentflight_sdk-0.1.0/src/agentflight/server/viewer/static/htmx-2.0.11.min.js +1 -0
  49. agentflight_sdk-0.1.0/src/agentflight/server/viewer/static/viewer.css +104 -0
  50. agentflight_sdk-0.1.0/src/agentflight/server/viewer/templates/_event.html +36 -0
  51. agentflight_sdk-0.1.0/src/agentflight/server/viewer/templates/_runs_table.html +35 -0
  52. agentflight_sdk-0.1.0/src/agentflight/server/viewer/templates/_timeline_rows.html +25 -0
  53. agentflight_sdk-0.1.0/src/agentflight/server/viewer/templates/base.html +26 -0
  54. agentflight_sdk-0.1.0/src/agentflight/server/viewer/templates/event.html +6 -0
  55. agentflight_sdk-0.1.0/src/agentflight/server/viewer/templates/login.html +14 -0
  56. agentflight_sdk-0.1.0/src/agentflight/server/viewer/templates/not_found.html +6 -0
  57. agentflight_sdk-0.1.0/src/agentflight/server/viewer/templates/run.html +45 -0
  58. agentflight_sdk-0.1.0/src/agentflight/server/viewer/templates/runs.html +31 -0
  59. agentflight_sdk-0.1.0/tests/__init__.py +0 -0
  60. agentflight_sdk-0.1.0/tests/conftest.py +58 -0
  61. agentflight_sdk-0.1.0/tests/test_api.py +153 -0
  62. agentflight_sdk-0.1.0/tests/test_auth.py +154 -0
  63. agentflight_sdk-0.1.0/tests/test_bench_script.py +37 -0
  64. agentflight_sdk-0.1.0/tests/test_dropped_spans_server.py +107 -0
  65. agentflight_sdk-0.1.0/tests/test_error_redaction.py +131 -0
  66. agentflight_sdk-0.1.0/tests/test_examples.py +47 -0
  67. agentflight_sdk-0.1.0/tests/test_failure_isolation.py +623 -0
  68. agentflight_sdk-0.1.0/tests/test_failures.py +116 -0
  69. agentflight_sdk-0.1.0/tests/test_fork.py +108 -0
  70. agentflight_sdk-0.1.0/tests/test_langgraph_integration.py +227 -0
  71. agentflight_sdk-0.1.0/tests/test_migrations.py +348 -0
  72. agentflight_sdk-0.1.0/tests/test_openai_integration.py +241 -0
  73. agentflight_sdk-0.1.0/tests/test_payloads.py +127 -0
  74. agentflight_sdk-0.1.0/tests/test_queries.py +193 -0
  75. agentflight_sdk-0.1.0/tests/test_queue_and_drops.py +158 -0
  76. agentflight_sdk-0.1.0/tests/test_replay.py +411 -0
  77. agentflight_sdk-0.1.0/tests/test_retention.py +119 -0
  78. agentflight_sdk-0.1.0/tests/test_run_span_lane.py +180 -0
  79. agentflight_sdk-0.1.0/tests/test_scoped_keys.py +146 -0
  80. agentflight_sdk-0.1.0/tests/test_sdk.py +128 -0
  81. agentflight_sdk-0.1.0/tests/test_span_tree.py +167 -0
  82. agentflight_sdk-0.1.0/tests/test_spool.py +432 -0
  83. agentflight_sdk-0.1.0/tests/test_status_and_limits.py +272 -0
  84. agentflight_sdk-0.1.0/tests/test_totals.py +168 -0
  85. agentflight_sdk-0.1.0/tests/test_viewer_browser.py +189 -0
  86. agentflight_sdk-0.1.0/tests/test_viewer_login.py +261 -0
  87. agentflight_sdk-0.1.0/tests/test_viewer_pages.py +237 -0
@@ -0,0 +1,9 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ *.db
8
+ dist/
9
+ build/
@@ -0,0 +1,203 @@
1
+ # Changelog
2
+
3
+ All notable changes to AgentFlight. The HTTP API is versioned by its `/v1` prefix (see
4
+ "HTTP API versioning" under 0.1.0); every change that can break a client is listed under
5
+ **Behaviour changes**.
6
+
7
+ ## 0.1.0 (not yet released; dated when it is tagged)
8
+
9
+ The first release on PyPI, as **`agentflight-sdk`** (the name `agentflight` is too close
10
+ to an existing PyPI project): `pip install agentflight-sdk` for the SDK,
11
+ `pip install "agentflight-sdk[server]"` for the server and viewer. The import name is
12
+ still `agentflight`. It contains everything
13
+ below (weeks 1-7) plus the changes in this section.
14
+
15
+ ### HTTP API versioning
16
+
17
+ Every endpoint a client uses is under `/v1`: `POST /v1/spans` (ingest),
18
+ `GET /v1/runs`, `GET /v1/runs/{run_id}`, `GET /v1/runs/{run_id}/events/{span_id}` and
19
+ `DELETE /v1/runs/{run_id}`. `/health` and `/ready` are unversioned, and the viewer's
20
+ `/ui` pages are not an API. From 0.1.0 on, `/v1` is stable:
21
+
22
+ - **Only additive changes within `/v1`:** new endpoints, new optional request fields or
23
+ query parameters, new response fields and new values where a field is documented as
24
+ open-ended. Clients must ignore response fields they don't know.
25
+ - **Nothing is removed, renamed or given a new meaning within `/v1`:** paths, methods,
26
+ required fields, field types, status codes, auth scopes, paging and the span JSON that
27
+ `POST /v1/spans` accepts (including the `agentflight.*` attributes the server reads).
28
+ - **A breaking change means `/v2`.** `/v2` would be served next to `/v1` for at least one
29
+ minor release after it ships, and `/v1`'s removal would be announced here under
30
+ Behaviour changes first.
31
+ - **Any SDK 0.1+ works with any server 0.1+** as long as both speak `/v1`; the SDK only
32
+ uses `POST /v1/spans`, and the replayer the read endpoints.
33
+ - Security fixes are the one exception: if a `/v1` behaviour is unsafe it can change in
34
+ a patch release, and the change is listed here.
35
+
36
+ The Python API is not covered by this: while AgentFlight is `0.x`, a minor release
37
+ (0.2, 0.3, ...) can still change it, and every such change is listed under Behaviour
38
+ changes.
39
+
40
+ ### Packaging
41
+
42
+ - **Version 0.1.0**, read by the build from `agentflight.__version__`. Package metadata
43
+ now has classifiers, keywords, project URLs and the license file; README links and
44
+ images are absolute so they work on PyPI; the sdist holds the source, tests, examples
45
+ and scripts only.
46
+ - **Release workflow** (`.github/workflows/release.yml`): pushing a tag `v*` runs the
47
+ full CI suite (`ci.yml`, reused), then builds the sdist and wheel, checks the tag
48
+ matches the version, runs `twine check --strict`, smoke-tests the wheel in a clean venv
49
+ (`scripts/smoke_installed.py`) and only then publishes to PyPI as `agentflight-sdk` with
50
+ Trusted Publishing (environment `pypi`, no stored token).
51
+
52
+ ### Added
53
+
54
+ - **Bounded on-disk spool (opt-in):** `configure(spool_dir=...)` or
55
+ `AGENTFLIGHT_SPOOL_DIR`. Spans whose export failed in a way that may clear up are kept
56
+ on disk and sent at the start of later exports (including after a restart), oldest
57
+ first, within the attempt cap and with the usual 413 splitting. Bounded by size
58
+ (`spool_max_bytes`, 64 MiB) and age (`spool_max_age_s`, 24 h), private (`0700`/`0600`),
59
+ fail-open (full disk, unwritable directory, corrupt files) and never on the agent's
60
+ thread, so it needs `batch=True`.
61
+ - **`agentflight-server migrate [revision]`** applies the database migrations, which now
62
+ ship inside the package (`agentflight/server/migrations`), so a server installed from a
63
+ wheel can create and upgrade its database without a source checkout. `alembic upgrade
64
+ head` from a checkout still works. The Docker image uses the new command.
65
+
66
+ ### Changed
67
+
68
+ - **Benchmark rerun** with run spans on their own lane (5 repeats): every dropped span
69
+ was recorded on its run and every run closed, also in the tight loop that drops about
70
+ half the spans. The benchmark now reports how many runs the server has with a final
71
+ status.
72
+ - **Export errors are reported as `HTTP <status> from <url>`** instead of the httpx
73
+ exception's repr, and other 4xx answers are counted as rejected for good (not spooled).
74
+ - **Run spans skip the batch queue.** A run's root span goes to a small lane of its own,
75
+ sent by a dedicated thread as soon as the run ends (with a deadline, the exporter's
76
+ `timeout`), so a run whose other spans were dropped still closes with its status and
77
+ `dropped_spans` instead of showing as `abandoned`. Ending a run never waits on the
78
+ network; `flush()`/`shutdown()` wait for the lane within their timeouts. The queue
79
+ slots that used to be kept for run spans are gone. New:
80
+ `AgentFlightExporter.export_within(spans, deadline_s)`.
81
+
82
+ ## Week 7 (merged in #5)
83
+
84
+ ### Added
85
+
86
+ - **Configurable batch queue:** `configure(max_queue_size=...)` or
87
+ `AGENTFLIGHT_MAX_QUEUE_SIZE` (then OpenTelemetry's `OTEL_BSP_MAX_QUEUE_SIZE`), passed
88
+ to the batch span processor. The default is unchanged (2048).
89
+ - **Dropped spans are counted.** The SDK refuses spans itself when the queue is full
90
+ (instead of OpenTelemetry silently dropping the oldest queued span), counts them, and
91
+ records each run's count on its run span (`agentflight.run.dropped_spans`, best effort:
92
+ spans dropped after the run span ended can't be on it). The total is
93
+ `get_recorder().dropped_spans`.
94
+ - **Incomplete recordings are visible.** Runs have `dropped_spans` (migration `0004`, 0
95
+ for existing runs) in `/v1/runs` and run detail, and the viewer's run list and run page
96
+ show "incomplete recording: N spans dropped".
97
+ - **Benchmark repeats and ingest rate.** `scripts/bench_overhead.py` now repeats the
98
+ whole benchmark (`--repeats`, default 5) and reports the spread, measures the server's
99
+ ingest rate in spans/s, and counts the spans the SDK dropped. The README's numbers are
100
+ from 5 repeats; the week-6 numbers were a single run.
101
+ - **Replay warns about incomplete recordings** as `replay()`/`fork()` start, and
102
+ `Recording` has `dropped_spans` and `incomplete`.
103
+
104
+ ### Changed
105
+
106
+ - **Split-on-413 retries stop at the first other failure.** A timeout, transport error,
107
+ 5xx or credentials error during an export drops the halves not yet sent instead of
108
+ trying each of them. The attempt cap stays.
109
+ - **`flush()` and `shutdown()` are bounded by AgentFlight**, not only by OpenTelemetry
110
+ (whose 1.45 `force_flush` ignores its timeout). `shutdown()` takes `timeout_millis`
111
+ (default 30 s). `flush()` returns `False` when it runs out of time.
112
+
113
+ ## Week 6 (merged in #4)
114
+
115
+ ### Added
116
+
117
+ - **Span tree in the viewer.** The run page nests each span under its parent (siblings in
118
+ start order) and pages in tree order. Spans whose parent is missing start their own
119
+ subtree. The `/v1` API's event order is unchanged.
120
+ - **README screenshots** of the run list, run page, span tree and a fork run, under
121
+ `docs/screenshots/`, taken by the browser smoke test.
122
+ - **Overhead benchmark.** `scripts/bench_overhead.py` measures what recording adds per
123
+ span (no exporter, serialization only, HTTP with and without batching) and counts what
124
+ the server stored. Results and method are in the README under "Overhead".
125
+
126
+ ### Changed
127
+
128
+ - **Split-on-413 retries are capped per export.** The exporter makes at most
129
+ `max_export_attempts` requests per export (default `32`, `configure(...)` takes it);
130
+ spans still unsent then are dropped. Each export that drops spans now logs one warning
131
+ with the count, instead of one per failed request.
132
+
133
+ ## Week 5 (merged in #3)
134
+
135
+ ### Behaviour changes
136
+
137
+ - **A run whose root span ends without a status is now `unknown`, not `ok`.** Nothing
138
+ reported success, so it no longer looks successful. Migration `0003` updates runs stored
139
+ earlier (its downgrade maps them back to `ok`). Runs recorded with the SDK are not
140
+ affected: the SDK always sets `ok` or `error`.
141
+ - **API keys must be at least 32 characters.** The server refuses to start if
142
+ `AGENTFLIGHT_API_KEY` or any `AGENTFLIGHT_API_KEYS` key is shorter (the error names the
143
+ setting, never the key). There is still no rate limit on failed keys; long random keys
144
+ are what keep guessing impractical until there is.
145
+ - **Runs that stop reporting become `abandoned`, not `running` forever.** A run still
146
+ `running` with no span received for `AGENTFLIGHT_STALE_AFTER_MINUTES` (default `60`,
147
+ `0` turns it off) is shown and filtered as `abandoned`. It is decided when runs are
148
+ read, nothing stored changes, and a late span makes the run `running` again. Clients
149
+ that treat anything other than `running`/`ok`/`error` as unexpected need updating.
150
+ - **`GET /v1/runs?status=` is validated.** Allowed values are `running`, `ok`, `error`,
151
+ `unknown` and `abandoned`; anything else gets `422` instead of an empty list.
152
+ - **Ingest is bounded.** `POST /v1/spans` answers `413` when a request breaks a size limit
153
+ (body size, spans per batch, attribute size or count, events per span) and stores none
154
+ of it. Span and span event names over 255 characters get `422` (on Postgres they used
155
+ to fail with a database error). The body cap defaults to 16 MiB; all limits are
156
+ configurable; see "Ingest limits" in the README. The SDK's exporter splits a batch in
157
+ half and retries when the server answers `413`, so a big batch isn't dropped whole.
158
+ - **Exception messages and stack traces go through the `redact` hook** (keys
159
+ `agentflight.error.message` and `exception.stacktrace`) and are capped at
160
+ `max_attr_chars`. The SDK now builds the OpenTelemetry `exception` span event itself
161
+ instead of calling `span.record_exception()`, so the stored message and stack trace are
162
+ the redacted ones.
163
+
164
+ ### Added
165
+
166
+ - **Viewer** at `/ui`: run list with filters, run timeline with highlighted failures, and
167
+ an event panel with payloads loaded on demand. Server-rendered with Jinja2 and a
168
+ vendored htmx 2.0.11, under a Content-Security-Policy with no inline script or style.
169
+ - **Viewer sign-in** with a key that has the `read` permission, kept as a signed,
170
+ read-only session cookie (`HttpOnly`, `SameSite=Strict`, `Secure` on HTTPS). The
171
+ signing secret is derived from the configured API keys (so it works across workers
172
+ with no setup, and changing a key ends all sessions) unless
173
+ `AGENTFLIGHT_SESSION_SECRET` is set. Sign-in and sign-out posts without a same-host
174
+ `Origin` header are refused. Other new settings: `AGENTFLIGHT_SESSION_HOURS`,
175
+ `AGENTFLIGHT_COOKIE_SECURE`.
176
+ - **Scoped API keys:** `AGENTFLIGHT_API_KEYS="<key>:ingest,<key>:read,<key>:read+delete"`
177
+ next to the all-permission `AGENTFLIGHT_API_KEY`.
178
+ - **Run filters** on `GET /v1/runs`: `name`, `since_ns`, `until_ns`, `has_errors`,
179
+ `model`, `tool` and `meta=key:value`.
180
+ - **Paged run detail:** `GET /v1/runs/{id}` takes `events_limit`, `events_offset` and
181
+ `payloads=false`. The default is unchanged: every event with its payloads.
182
+ - `GET /v1/runs/{run_id}/events/{span_id}` returns one event with its payloads.
183
+ - Run summaries include `last_seen_ns` and `root_span_id`. Run detail includes
184
+ `events_offset` and `events_limit`, and each event has an `omitted` list.
185
+
186
+ ### Changed
187
+
188
+ - Run totals (calls, errors, tokens, cost) are stored on the run row and recomputed in SQL
189
+ for every run an ingest batch touches, so listing runs no longer reads their events.
190
+ Migration `0002` adds the columns and backfills them.
191
+ - Ingest looks up each batch with one query per table and flushes once, instead of once
192
+ per span.
193
+
194
+ ### Fixed
195
+
196
+ - SQLite migrations no longer delete events when a batch migration rebuilds the `runs`
197
+ table (foreign keys are turned off while migrating).
198
+
199
+ ## 0.1.0.dev0 (weeks 1-4)
200
+
201
+ Recorder SDK and OpenTelemetry exporter, ingest API with Postgres and SQLite storage,
202
+ API-key auth, retention, truncation and redaction, OpenAI-style and LangGraph
203
+ integrations, and deterministic replay and fork.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Deepanshu Gautam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.