Metadata-Version: 2.5
Name: requal
Version: 1.1.0
Summary: Connect an AI app's OpenTelemetry traces to Requal: init, wait, disconnect.
Project-URL: Repository, https://github.com/Requal-Inc/requal-cli
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# requal

Keeps the OpenTelemetry traces of an AI app in Requal, on a machine without Node.

```bash
uvx requal@1.1.0 init
```

One Allow in the browser and one use of the app: it prints `DONE <trace link>`.

This is the npm package `@requal/cli` for Python apps: the same commands, flags, exit codes and `--agent` lines, the same device flow and the same `.requal/connect.json`, so either package can finish what the other began. `npx -y @requal/cli@1.1.0 wait` works on what `uvx requal@1.1.0 init` wrote, and the other way round. Python 3.10 and up, standard library only. Any other app stops with `unsupported_stack` and names the `npx` command to run.

Or give a coding agent (Claude Code, Codex, Cursor) this prompt:

```
Set up Requal tracing in this repository.
Run: npx -y @requal/cli@1.1.0 init --agent
Without Node, run: uvx requal@1.1.0 init --agent
It needs network access. Do what each "next" line says. When it prints a link for me, ask me to open it, and wait.
Stop when it prints DONE with a trace link, and show me the link.
Change only what it asks for, and show me each diff first. Never print, log or commit the ingest key.
```

## Commands

```
requal init [--agent] [--dir PATH] [--api URL] [--timeout SECONDS] [--no-browser] [--no-start] [--proxy | --claude-code]
requal wait [--agent] [--timeout SECONDS]
requal disconnect [--agent]
requal --version | requal version | requal help
```

| Flag | |
|---|---|
| `--agent` | JSON lines on stdout. Never installs or starts anything |
| `--dir` | The app, inside this folder. Without it: this folder if it has an AI library or is a Next.js app, else the only app with an AI library two levels down or in a workspace the repository declares |
| `--api` | `REQUAL_API_URL`, else `https://app.requal.ai`. https only; http only on this machine |
| `--timeout` | How long each wait lasts, 1 to 600 seconds, with up to 30 seconds more for a request the server has not answered. Default 600; under `--agent`, `init` 60 and `wait` 90 |
| `--no-browser` | Prints the link and opens nothing |
| `--no-start` | Leaves starting the app to you |
| `--proxy`, `--claude-code` | The npm package's recipes: these stop and name `npx` |

Exit codes: 0 done, or handed on with a `next`; 2 stopped; 1 an unexpected error.

### init

1. Detects the app and plans. Anything that stops it stops here, before any network call, except what can only be known after Allow: git's last word on the env file, or a file that appeared in the meantime.
2. Asks Requal for a link. It sends the CLI's version, the stack, the repository's name and the plan's paths and packages, never code or file contents. The code `XXXX-XXXX` on the page matches the one in the terminal.
3. After Allow, it gets the ingest key and writes: a line in the `.gitignore` beside the env file first, so git ignores it before the key is there (`.requal/` ignores itself), then the env file, one new file, and at most one change to your code. A second change it needs, or one to a file it cannot write, is handed to you or your agent.
4. Installs with your package manager, starts your server, and waits for the first trace with a model call. If a change was left for you, it stops before starting the app: make the change, start the app and run `wait`.
5. Prints `DONE <trace link>` and keeps the app in the foreground until Ctrl-C.

Under `--agent` the first run ends at the link. Run it again after Allow; it writes what it can, always including the env file, so the agent never sees the key. Then it hands on the install, any change it could not place, starting the app, using it once, and `wait --agent`. A link that ran out, or a plan that changed since, is replaced with a new one.

### wait

Polls for the first trace with a model call: `DONE <trace link>`. The status token lasts a day.

### disconnect

Removes the env block or `.env.requal`, the one change if it is still what init wrote, the new file if init placed it, it is unchanged and nothing still loads it (a line you added from a hand-off counts), and `.requal/`. Leaves the packages, the line in `.gitignore` and a change you made from a hand-on, and names them. Calls no server: revoke the key on the AI system's page.

It undoes what the npm package wrote too, whatever the stack: what init put in `.requal/` goes whatever it holds, unless git tracks it, a line in your source that names a new file in .NET, Go, Ruby or Rust counts as one that loads it, and it names what each stack needs from you, as `unset` in a shell that loaded the Java agent's variables.

## How it finds the app

As the npm package does, so that both choose the same folder. It reads the manifests in this folder, two levels down, and wherever a workspace declaration reaches (a uv workspace, Poetry's path dependencies, npm's and yarn's `workspaces`, `pnpm-workspace.yaml`, Cargo's `[workspace]`, `go.work`, Maven's modules, Gradle's settings, a `.sln`). One app with an AI library is chosen by itself; several list their `--dir` commands. A package beside an app that starts, and an example beside an app that is not one, are not choices.

It only reads, runs nothing of the repository's, and sends nothing. It skips what is built, vendored, hidden or a test's, follows no link while looking, stops after 5,000 folders, and reads only plain files, never a device or a pipe behind a link. The libraries it looks for, in each language, are in `recipes.json`.

A folder with a `package.json` naming `next` and the AI SDK, or a library the npm package traces on Node.js (`openai`, `@anthropic-ai/sdk`, `@aws-sdk/client-bedrock-runtime`, LangChain, `@openai/agents`, `llamaindex`, `@mastra/core`), is not a Python app here even with a `requirements.txt` beside it: the npm package would set it up, so this one names that command. So is a `deno.json` with no `package.json` and no Python library beside it.

## What it writes

| Found by | Env file | New file | One change | Installs |
|---|---|---|---|---|
| `pyproject.toml` or `requirements*.txt`, naming a library in "Python libraries" below | `.env.requal` | `requal_otel.py` | `import requal_otel`, in a `try` so the app starts without it, first in the module your server loads | `opentelemetry-sdk`, `opentelemetry-exporter-otlp-proto-http`, OpenInference's instrumentor for each library that has one, with `uv add`, `poetry add` or pip in your virtual environment; with pip, also in `requirements.txt`, or handed to you for a `pyproject.toml`, which pip does not write to |

Variables: `REQUAL_OTLP_ENDPOINT` and `REQUAL_INGEST_KEY`, at mode 0600. Never `OTEL_*`, which would redirect your own exporters. The new file does nothing while either is missing, does not stop the app when it fails (one line on stderr, each library in its own `try`), exports over OTLP/HTTP protobuf through a batch processor, with the key in the `authorization` header, and sets `service.name` to the repository's name. Its first line ends with a hash of the rest of the file, leaving out what a formatter changes: while that holds, any later `init`, on any machine, version or package, may replace it and `disconnect` may remove it. Its words on that line name `npx -y @requal/cli disconnect`, whichever package wrote it, so that the file is byte for byte the same.

Its provider is its own, never the global one. It samples everything: your app's own sampling does not decide what Requal sees.

Packages are exact pins, each checked against the others, with the day each came out and the day it was read (`recipes.json`). The bootstrap is `templates/requal_otel.py`. Both are copies of the npm package's, and a test in each package holds them equal. They need Python 3.10 to 3.14 (3.13 with `crewai`: its releases and its instrumentor's say so, and pip keeps to that, though uv installs and runs them on 3.14). With Poetry the pins carry a Python constraint in `pyproject.toml`, so a default range such as `^3.11` still resolves.

## Python libraries

Each row was run for real: the library, the pin and the bootstrap, against a fake model, from the lowest version named to the newest. A version comes from what is installed, then a lockfile, then an exact pin; a range alone counts as the newest it allows.

| Library | Names in a manifest | From | Traced by | What is missing |
|---|---|---|---|---|
| OpenAI SDK | `openai` | 1.69 | Instrumentor | No tool span: the app runs the tool, so the call is in the model span's messages. The same for the next seven rows |
| Anthropic SDK | `anthropic` | 0.84 | Instrumentor | |
| google-genai | `google-genai` | 1.8 | Instrumentor | |
| Vertex AI | `google-cloud-aiplatform`, `vertexai` | 1.63 | Instrumentor | Run over REST only; gRPC, its default, is not proven |
| Bedrock | `boto3`, with `"bedrock-runtime"` in the app's own Python | 1.34 | Instrumentor | Below 1.34 the instrumentor would stop the app when it makes a client, so it stops here instead. `aioboto3` is not traced |
| Mistral | `mistralai` | 1.0 | Instrumentor | |
| Groq | `groq` | 0.9 | Instrumentor | |
| LiteLLM | `litellm` | 1.65 | Instrumentor | litellm 1.106.6 fails on `tools=` unless `mcp` is installed, with or without Requal. An async stream's span has no output or tokens |
| LangChain | `langchain`, `langchain-*` | core 0.2.2 | Instrumentor | A tool has a span only when it runs through LangChain |
| LangGraph | `langgraph`, `langgraph-*` | core 0.2.2 | Instrumentor | |
| LlamaIndex | `llama-index`, `llama-index-*` | core 0.12.37 | Instrumentor | Each tool-calling turn adds an LLM span that calls nothing (`_prepare_chat_with_tools`). A stream has no tokens |
| CrewAI | `crewai`, `crewai-tools` | 1.10.1 | Instrumentor, with OpenAI's beside it for its model calls | Its Anthropic and LiteLLM providers were not run |
| OpenAI Agents SDK | `openai-agents` | 0.2.6 | Instrumentor, keeping the SDK's own processors | |
| DSPy | `dspy`, `dspy-ai` | 2.6.19 | Instrumentor, with LiteLLM's beside it for tokens | A tool span has its name only in the span's name |
| Haystack | `haystack-ai` | 2.18 | Instrumentor, with OpenAI's beside it | An Agent's tools have no span. Each Agent turn is its own trace unless the Agent is in a Pipeline. Under `run_async` only the OpenAI SDK's span comes, so a generator on another provider has none there |
| Google ADK | `google-adk` | 1.2.1 | Instrumentor | It takes ADK's own spans from any exporter of yours: with one, run it without Requal or accept that. The pin for 2.13 was one day old when read, because no older one sees a model call there |
| AutoGen AgentChat | `autogen-agentchat`, `autogen-core`, `autogen-ext`, `pyautogen` from 0.10 | 0.5.1 | Instrumentor | |
| AG2 below 1.0 | `ag2` from 0.14, `autogen`, `pyautogen` below 0.10 | 0.5 | Instrumentor, with OpenAI's beside it for its model calls | Another provider's model calls show only if its SDK is in the manifest |
| AG2 1.x | `ag2` from 1.0 | 1.0 | Its own middleware, added to each `Agent` | |
| smolagents | `smolagents` | 1.24 | Instrumentor | |
| Agno | `agno` | 2.0 | Instrumentor | |
| MCP | `mcp` below 2, beside another library here | 1.6 | Instrumentor, which only carries trace context across a call | It makes no spans, so `mcp` alone is not traced. mcp 2 carries the context itself and gets nothing from Requal; its own spans go to the global provider and do not reach Requal. `fastmcp` was not run |
| Claude Agent SDK | `claude-agent-sdk` | 0.1.45 | Instrumentor | No model span can exist: the calls happen in the `claude` process. The agent span holds the model, tokens and cost, and only the prompt and the answer of each query |
| Pydantic AI | `pydantic-ai`, `pydantic-ai-slim` | 0.2 | Its own `Agent.instrument_all` | A later `instrument_all` of yours, `logfire.instrument_pydantic_ai()`, or `instrument=` on an Agent replaces Requal's for those agents |
| Strands | `strands-agents`, `strands-agents-*` | 1.0 | Its own telemetry, reached by wrapping its one `Tracer` | Set a provider of your own before your first Agent: one set after it gets no Strands spans |
| Microsoft Agent Framework | `agent-framework`, `agent-framework-*` | 1.0 | Its own telemetry, reached by replacing `observability.get_tracer` | With a provider of your own, prompts reach Requal only if you set `ENABLE_SENSITIVE_DATA` |

Older versions take older pins. Three of those pins pass wrapt 2 a keyword it removed, so `wrapt` 1.17.3 goes beside them: for google-genai below 1.55, mistralai below 2, and agno below 2.5.

One OpenTelemetry version goes in for the whole plan: 1.45.1, or the lowest any library here needs. google-adk from 1.15, crewai below 1.15.21, mistralai 1.10 to 1.12.1 and 2.0 to 2.9.1, Pydantic AI below 1.32 and autogen-agentchat 0.6.2 and 0.6.3 cap it, each by its version, and `recipes.json` holds what each takes. Two libraries with no version in common stop before Allow.

An `opentelemetry-*` package the app declares stops too, before Allow, when it cannot sit with that version: a bound on the sdk or api that leaves the version out, an instrumentation or semantic-conventions pin of another train (1.45.1 takes only 0.66b1), a retired one such as `opentelemetry-instrumentation-elasticsearch`, or one locked or installed on another train, which the install would replace. What a lock or a venv holds only for a library's own needs moves with the install. A pip constraints file named by `-c` or `--constraint` counts the same way, for what the app asks for and what the plan installs. `traceloop-sdk` stops too when what you declare cannot resolve beside that version, as do the other 49 distributions in `otel_capped` in `recipes.json`, each shown not to by the resolver and by real pip, with its version: the stop says what to move it to, or to take it out, or to run `init --proxy`, which adds no package. For these a lock or a venv is no pin: a version in it that fits stays, one that does not moves inside your range at the next install, so only a range whose newest cannot resolve stops. Anything outside `otel_own` and `otel_capped` is not judged: if it caps OpenTelemetry, your next `pip install -r requirements.txt` fails with `ResolutionImpossible`, and `uv add` or `poetry add` fails after the key is spent. `disconnect` takes Requal's lines back.

The bootstrap never touches the global tracer provider. With a provider of your own, your spans stay yours. Strands' and Agent Framework's spans reach both: Requal's processor goes on your provider, so your sampler decides which of them Requal sees, and it sees your other spans too; a trace with no AI span is deleted at close. Everywhere else the bootstrap's own provider samples everything, whatever your sampling says. It does two things to what it sends:

- An SDK's span below LangChain's, LangGraph's, LlamaIndex's or LiteLLM's model call is dropped, so one call is one model span, with the framework's span holding it. A raw SDK call beside them keeps its span.
- A span whose parent is not one of its own, such as your request's span from your own provider, says its parent is remote. That parent never reaches Requal, so the trace closes 30 seconds after its top span, not 10 minutes after its last.

When any of this cannot run (an import fails, a library has moved), the app runs on, with one line on stderr.

Run with `uvicorn --workers` and with gunicorn, with and without `--preload`. The bootstrap starts no thread at import, because on macOS a worker forked from a process that ever had a thread can die at its first model call, in the system's proxy lookup. That can still happen there with LlamaIndex and the OpenAI Agents SDK, whose instrumentors bring it on at import, with CrewAI and Vertex AI, which start a thread themselves with or without Requal, and in an app that calls a model before it forks. `no_proxy=*` in the environment stops it: run on the LlamaIndex, OpenAI Agents and model-call cases. Not run on Linux, which has no such lookup.

Not run: any real model, and everything named above as not run. Run on Python 3.10, 3.12 and 3.14 for all but older versions, and resolved on 3.11 and 3.13.

## What stays out of a trace

- **Beside a tracer of your own:** Requal has a tracer provider of its own beside Sentry, Logfire, Langfuse and Datadog, and each keeps receiving what it did. Their own spans (Sentry's `gen_ai.chat`, Datadog's `openai.request`, Langfuse's generation) do not reach Requal, and Requal's traces are not joined to theirs. Where Logfire's `instrument_*` takes a model library from Requal's instrumentation, so that Requal gets nothing, one line for `logfire.configure` is handed on: `later`, until your code shows such a call.
- **A pre-release:** an OpenInference instrumentor declines a library's pre-release, such as `langchain_core` 1.3.0a2 or `dspy` 3.0.0b3, with no error. Its own spans do not come; a model call still shows where an SDK's or LiteLLM's instrumentor is beside it.
- **A notebook:** no recipe. A repository of notebooks gets the plain stop, or the hand-off to put the import in a module, which a notebook has no place for.

## What stops it

| `stop` code | When |
|---|---|
| `existing_provider` | A `requal_otel.py` that is not Requal's, or has Requal's first line and a hash that no longer holds, because someone edited it |
| `env_file_tracked`, `env_file_not_ignored` | Git would commit the env file: it is tracked (found before asking anything), or a `.gitignore` undoes the rule (found after Allow, and that key is not saved). The same for a tracked `.requal/.gitignore`, which the CLI replaces whole from its first save |
| `env_file_unusable` | The env file is a link or hard linked (the key would go into the other name too), leads out of this folder, is a folder, unreadable, or not UTF-8 |
| `git_failed` | A repository is here and git cannot answer for it within 30 seconds, so the CLI cannot tell what would be committed |
| `cannot_write` | It cannot write what it would need to, a file or folder is in the way, a file a plan must read is a pipe or a device or past 64 MiB, or a file appeared in the wait for Allow |
| `state_tracked` | Git tracks `.requal/connect.json`: it may have come with the repository, and nothing in it is used |
| `state_unusable` | `disconnect` with a `.requal/connect.json` it refuses (cut short, a link, wider modes than the CLI gives it, or an edit that does more than add Requal's words): it is the only record of what `init` changed, so nothing is changed. `init` moves such a file aside to `connect.json.refused`, then `.refused.1` and so on, which stay until you delete `.requal`, and starts again; with twenty there already, it stops instead of losing one |
| `unsupported_version` | A Python library below the first version Requal traces ("From" in "Python libraries"); a declared lower bound alone does not count, only a range that cannot reach the floor. The OpenAI SDK below 1.69 beside CrewAI or AG2, whose model calls show only through it. Two Python libraries with no OpenTelemetry version in common, naming both. A different `==` pin of a package Requal needs. An `opentelemetry-*` package the app declares that cannot sit with the OpenTelemetry version the plan installs ("Python libraries" says which). Python below 3.10, or from 3.15 (3.14 with `crewai`), in a virtual environment, `.python-version`, `runtime.txt`, `.tool-versions`, a Dockerfile's `FROM python`, `requires-python`, or what pip names. No pip, or a virtual environment with none |
| `unsupported_stack` | Anywhere but a Python app, naming the `npx` command: Next.js, Node, Java, .NET, Go, Ruby, Rust, Deno, `--proxy` or `--claude-code`, or a connection the npm package made for one of them. Also no manifest, or no AI library it has a recipe for: `boto3` with no `"bedrock-runtime"` in the app's own Python is not one, nor is `mcp` alone, which says so. Or a virtual environment's `python` that git tracks |
| `multiple_apps` | Several apps with an AI library, one of them Python: it lists the `--dir` commands, twenty at most. With none of them Python, `unsupported_stack` lists them for `npx` |
| `not_connected`, `connection_expired` | `wait` with no connection here, or a status token past its day |
| `refused`, `unreachable` | Requal said no (`server_code` has its code), or did not answer. A 404 on the device route says Requal does not take this version yet. A Python that trusts no certificate says what to do: its `Install Certificates.command`, `SSL_CERT_FILE`, or a Python uv manages. Behind a proxy, `HTTPS_PROXY` is used when it is an http URL. Any other value is named and left unused, an https one too: the standard library speaks to a proxy in the clear, and a password in it would go out as plain text |

## `--agent` lines

Each line is one object, `{"v": 1, "type": ...}`. Diagnostics go to stderr. No line ever holds the key, the device code or the status token. The commands a line names are `uvx requal@1.1.0 ...`.

| `type` | Fields |
|---|---|
| `found` | `stack`, `dir`, `repository`, `package_manager`, `ai` |
| `plan` | `env_file`, `env`, `files`, `edits`, `codemod` (each with its unified `diff`), `packages`, `install` |
| `link` | `url`, `code`, `expires_at` |
| `connected` | `organisation`, `ai_system`, `ai_system_id`, `environment` |
| `wrote` | `path`, `kind`: `env`, `file` or `edit` |
| `removed` | `path` |
| `waiting` | `for`: `allow` or `first_trace`; `spans_received` |
| `next` | `do`: `ask_person` (`say`, `then`), `run` (`run`, `background`), `edit` (`path`, `line`, `where`) or `change` (`language`, `packages`, `code`, `where`), the npm package's line for what to add in a language it does not edit: no plan of a Python app holds one yet |
| `done` | `say`, `trace_url`, `model_calls`, `has_prompts`, `fixes` |
| `stop` | `code`, `say`, `server_code` |

## Local files

`.requal/connect.json`, mode 0600 in a 0700 folder, naming this folder's path: the link until it is used, then the status token, and what init wrote so disconnect can undo it. Never the key. It is saved before anything is written, and anything wider is not trusted. One written for another folder means this one was moved or copied: `disconnect` undoes what it finds here, `init` keeps only its record of what changed and makes a new key, and its address and tokens are never used. A state can come with an archive, so what it holds is checked: an edit may only add Requal's words, and no path reaches `.git`, even through a link.

The CLI itself loads no tracked code of a repository before Allow: pip is looked for in a virtual environment's folders and asked with no `PYTHONPATH`, `python3` runs with `-I`, git is told to ignore a repository's `core.fsmonitor`, and `node_modules/.bin`, any relative folder and any empty entry are taken off the PATH of its git and pip calls and of the browser it opens. It reads only plain files, never a device or a pipe behind a link, and none past 64 MiB. A folder whose name is not UTF-8 is no folder here, as for Node: a state could not save it. The console script does not put this folder on Python's path. uvx puts this CLI's own environment first on PATH: that is taken off again for what it runs, so that pip, your install and your app find your Python and not this tool's. uvx 0.13 reads no `uv.toml` or `[tool.uv]` of the repository to fetch this package.

But Python reads `PYTHONPATH` before any of this runs. With one that names this folder, or an empty entry, as a Python image's `ENV PYTHONPATH=/app` does, a repository's own `requal_cli/` loads in this package's place, and on Python 3.10 also a module Python loads as it starts, such as `os.py`. This package takes everything else off it as it starts, and leaves it out of what it asks of pip and git, so a repository's `re.py` or `http/` is not imported by this process or by those. Unset it, and run this only in a repository you trust.

## Where it runs

Tested on macOS and on Linux, on Python 3.10 to 3.14. Windows and WSL are not tested yet.

## Development

```bash
(cd ../cli && npm ci && npm run build)
uv sync --locked
uv run --locked ruff check .
REQUAL_REQUIRE_NODE_PARITY=1 uv run --locked pytest
uv build --wheel
```

`tests/test_parity.py` runs the built Node CLI and this package over the same fixture apps against one stub device server, and compares every line, every file with its mode, every exit code and every request. Without Node it skips, saying so; `REQUAL_REQUIRE_NODE_PARITY=1` makes that a failure, and so is Node with no build. A change in `cli/` that a Python app can see belongs here too, and that test says where. `REQUAL_REAL_RUN=1` adds `tests/test_real_run.py`: the wheel under `uvx`, with no Node on PATH, a real FastAPI app, a fake model and a sink.
