Metadata-Version: 2.4
Name: driftseer
Version: 0.0.1
Summary: Capture an agent run's shape and economics into a local runs file, with an opt-in cloud upload
Author: Avtaar Labs
Project-URL: Homepage, https://driftseer.dev
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: System :: Monitoring
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# driftseer

> **Pre-launch release.** This early version is published ahead of the full launch. See https://driftseer.dev for status.

Capture the shape and economics of an agent run (tokens, latency, status,
structure), write it to a local file, and optionally upload it to the DriftSeer
cloud. Zero runtime dependencies.

**Your content never leaves the machine.** Each finished run is one JSON packet:

- `~/.driftseer/runs.jsonl` holds exactly what the cloud receives. Never content.
- `~/.driftseer/content.jsonl` holds the same packet, plus content when you turn
  `capture_content` on. Build your own dashboard from it if you like.

Cloud upload is off until you turn it on. The line in the runs file, without its
newline, is byte for byte the body that is uploaded, so you can see what is sent.

## Install

```bash
pip install driftseer
```

## Use

```python
import driftseer

lens = driftseer.init(project="rag-agent")        # capture_content=False by default

@lens.track(model="text-embedding-3-small")
def embed(query):
    resp = client.embeddings.create(model="text-embedding-3-small", input=query)
    driftseer.record(input_tokens=resp.usage.prompt_tokens)
    return resp.data[0].embedding

@lens.track(model="gpt-4o-mini")
def answer(query, context):
    resp = client.chat.completions.create(model="gpt-4o-mini", messages=[...])
    driftseer.record(resp.usage.prompt_tokens, resp.usage.completion_tokens,
                     content={"answer": resp.choices[0].message.content})
    return resp.choices[0].message.content

@lens.track
def ask(query):                    # the outermost tracked call is the run
    driftseer.annotate(route="rag")
    result = answer(query, embed(query))
    driftseer.outcome(accepted=True)
    return result
```

- `@lens.track(name=None, model=None)` works on functions, coroutines,
  generators and async generators. A stream's step stays open until the stream
  ends.
- `driftseer.record(input_tokens, output_tokens, content=None, model=None)`
  reports usage for the current step. `model=` replaces a model chosen at
  decoration time.
- `driftseer.annotate(**labels)` adds labels to the run's metadata. Labels are
  uploaded, so keep personal data out of them.
- `driftseer.outcome(accepted, wasted=[step names])` labels the run explicitly.
- `driftseer.carry(fn)` keeps the run when work goes to a thread:
  `pool.submit(driftseer.carry(worker), item)`.
- Misuse (for example `record()` outside any tracked function) warns and is
  dropped. Capture never raises into your program.

Costs are not computed locally: every step carries `cost` null and the cloud
prices it from tokens and model. Errors upload as the exception type only; with
`capture_content` on, the message goes to the content file.

## Cloud upload

```bash
driftseer cloud on --url <ingest url>   # also needs DRIFTSEER_CLOUD_KEY in the environment
driftseer cloud off
driftseer cloud status                  # switch, URL, key set or not, runs waiting/rejected
```

Upload needs all three: the switch on, a saved URL, and `DRIFTSEER_CLOUD_KEY` set.
The key is never written to disk. A failed upload is resent at the next
`driftseer.init()`, or after the next successful upload; a run the cloud refuses
for good (HTTP 413 or 422) is kept in `~/.driftseer/rejected/`.

## Crash safety

While a run is live, each step is journaled in `~/.driftseer/inflight/`. If the
process dies, the next `driftseer.init()` on the machine delivers that run with
status `abandoned` and every step that finished.

## Files

`DRIFTSEER_HOME` relocates the whole folder: `runs.jsonl`, `content.jsonl`,
`settings.json`, `inflight/`, `rejected/`.

## Claude Code

```bash
python -m driftseer.otel.claude_code_tel --project claude-code --port 4318
```

Each Claude Code turn becomes one run, with Claude Code's own `cost_usd` kept.
See the module docstring for the OTEL environment variables.

