Skip to main content

autocontext Python package

This package is the Python control plane for autocontext: scenario runs, solve, simulations, investigations, MCP/HTTP surfaces, persistent knowledge, training-data export, and local training hooks.

Use it when you want the full harness in Python, a CLI installed with uv/pip, or the MCP/HTTP server that coding agents can call.

Install

pip install autocontext
# or, for an isolated CLI tool:
uv tool install autocontext

Optional extras:

pip install 'autocontext[browser]'          # Chrome/CDP capture
pip install 'autocontext[primeintellect]'   # PrimeIntellect sandbox backend
pip install 'autocontext[mcp]'              # MCP server dependencies

The CLI entrypoint is autoctx. Provider env vars are listed in the repo-level .env.example.

Run from a checkout

cd autocontext
uv venv
source .venv/bin/activate
uv sync --group dev

AUTOCONTEXT_AGENT_PROVIDER=deterministic \
uv run autoctx solve "improve customer-support replies for billing disputes" --iterations 3

Use a real provider by changing AUTOCONTEXT_AGENT_PROVIDER and setting its credential:

AUTOCONTEXT_AGENT_PROVIDER=anthropic \
ANTHROPIC_API_KEY=... \
uv run autoctx solve "improve customer-support replies for billing disputes" --iterations 3

Pi and local CLI providers avoid API-key plumbing when those tools are already authenticated:

AUTOCONTEXT_AGENT_PROVIDER=pi AUTOCONTEXT_PI_COMMAND=pi uv run autoctx solve "..." --iterations 3
AUTOCONTEXT_AGENT_PROVIDER=claude-cli AUTOCONTEXT_CLAUDE_MODEL=sonnet uv run autoctx solve "..." --iterations 3
AUTOCONTEXT_AGENT_PROVIDER=codex AUTOCONTEXT_CODEX_MODEL=o4-mini uv run autoctx solve "..." --iterations 3

Common commands

Command Purpose
uv run autoctx solve "..." --iterations 3 Generate and run a scenario from a plain-language goal
uv run autoctx run <scenario> --iterations 3 Improve an existing scenario
uv run autoctx simulate --description "..." Create/replay/compare modeled-world simulations
uv run autoctx investigate --description "..." Run synthetic or iterative investigations
uv run autoctx list / status <run_id> / show <run_id> Inspect runs
uv run autoctx replay <run_id> --generation 1 Replay a generation before accepting knowledge
uv run autoctx queue add --task-prompt "..." --rubric "..." Queue evaluation/improvement work
uv run autoctx serve --host 127.0.0.1 --port 8000 Start the local HTTP API
uv run autoctx worker --poll-interval 5 --concurrency 2 Process queued tasks beside the API server
uv run autoctx mcp-serve Expose the MCP tool surface
uv run autoctx export-training-data --scenario <name> --all-runs --output data.jsonl Build a training corpus (quarantined scores excluded by default; --include-quarantined to keep them)
uv run autoctx train --scenario <name> --data data.jsonl --time-budget 300 Run the local training hook
uv run autoctx epoch list [--scenario <name>] List evaluator-epoch registry records (candidate/active)
uv run autoctx epoch approve <scenario> <epoch_id> --charter ambient-charter.yaml Approve a candidate evaluator epoch and clear its quarantine
uv run autoctx hermes inspect --json Inspect Hermes Curator state

Saved custom scenarios under knowledge/_custom_scenarios/ can be rerun and benchmarked by name after their spec.json is persisted.

HTTP, MCP, and agents

uv sync --group dev --extra mcp
uv run autoctx mcp-serve

Python runtime-backed run and solve calls append provider prompts/responses to run-scoped runtime-session logs. The same logs are readable through the cockpit HTTP API and MCP tools.

Detailed setup moved out of this README:

Contract probes

Contract probes turn observed harness traces into executable checks:

uv run autoctx probes check --suite contract-probes.json
uv run autoctx probes check --suite contract-probes.json --json
uv run autoctx probes extract --trace harness-trace.json --output contract-probes.json

Probe suites are strict JSON: unknown keys fail validation and required observation fields must be present. Pipe stdin with --suite - when another tool generates the suite.

Production traces

Wrap an existing Anthropic/OpenAI client once, then persist emitted traces through a sink:

from anthropic import Anthropic
from autocontext.integrations.anthropic import FileSink, instrument_client

sink = FileSink("./traces/anthropic.jsonl")
client = instrument_client(
    Anthropic(),
    sink=sink,
    app_id="billing-bot",
    environment_tag="prod",
)

For lower-level emit APIs, use autocontext.production_traces.build_trace and write_jsonl. Architecture notes are in ../docs/analytics.md and ../docs/opentelemetry-bridge.md.

Training

uv run autoctx export-training-data \
  --scenario support_triage --all-runs \
  --output training/support_triage.jsonl
uv run autoctx train \
  --scenario support_triage \
  --data training/support_triage.jsonl \
  --time-budget 300

For MLX/CUDA setup and case studies, use:

Repository layout

autocontext/
├── src/autocontext/       # Python package
├── tests/                 # pytest suite
├── docs/                  # package-specific docs
├── demo_data/             # small bundled examples
├── migrations/            # SQLite migrations
└── pyproject.toml

Development

uv run ruff check .
uv run mypy src
uv run pytest

Keep this README concise. Add deep reference prose to docs/ or the repo-level docs index instead.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autocontext-0.13.0.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autocontext-0.13.0-py3-none-any.whl (1.6 MB view details)

Uploaded Python 3

File details

Details for the file autocontext-0.13.0.tar.gz.

File metadata

  • Download URL: autocontext-0.13.0.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for autocontext-0.13.0.tar.gz
Algorithm Hash digest
SHA256 3ea8401e21f6ea82222735e71739e37803a5f1de373945e3e5a32fa17ee93fc6
MD5 d09918eff428039021cb291d4c23030a
BLAKE2b-256 6c90c698fc231907c1ad0f5ed8ce718b5e1dcea29f88d77b23e845b305327f71

See more details on using hashes here.

Provenance

The following attestation bundles were made for autocontext-0.13.0.tar.gz:

Publisher: publish-python.yml on greyhaven-ai/autocontext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file autocontext-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: autocontext-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for autocontext-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a2398c3bb590c7fa1ff9fdcf4094576b7e52500a3c8123fd31087906da6bc28
MD5 f3aa2cde25d620911c3940d87bbf91c1
BLAKE2b-256 04fa2ca24c1a24d342ba5a0dd0be8f2c2244bf28d753aa92f3bc0e6abbb6d108

See more details on using hashes here.

Provenance

The following attestation bundles were made for autocontext-0.13.0-py3-none-any.whl:

Publisher: publish-python.yml on greyhaven-ai/autocontext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.16.1

2 files

0.15.1

2 files

0.15.0

2 files

0.14.0

2 files

This release

0.13.0 This release

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.9

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page