Skip to main content

generalcontext

Record your agent's model calls for the General Context platform. No dependencies, and never in your agent's way: calls are sent from a background thread, and our failures are logged, not raised.

pip install generalcontext
export GENERALCONTEXT_API_KEY=gck_...   # from your workspace's Connect page
import generalcontext
generalcontext.initialize(app_name="support-agent")   # once per process, at startup

# Optional: group every call in one conversation under your own id
with generalcontext.session(conversation_id, user_id=customer_id, channel="chat"):
    with generalcontext.task("triage"):
        reply = client.chat.completions.create(...)   # any OpenAI or Anthropic client

initialize() records every OpenAI (chat.completions, responses) and Anthropic (messages) call in the process, sync and async, streamed or not, from clients created before or after it. SDK clients are always recorded. Raw httpx and requests POSTs to /chat/completions are recorded only with instrument_http=True. Call it in every process: queue workers and forked children do not inherit it.

Flush before exit

On serverless, in jobs, and before os._exit(), send what is queued:

generalcontext.flush()   # synchronous, waits up to 10s, never raises

Outcomes and events

generalcontext.report_outcome(conversation_id, "fail", note="customer reopened the ticket")   # or "success"
generalcontext.log_event(conversation_id, "order.refunded", {"amount": 42.5}, event_id=f"refund:{refund.id}")
generalcontext.log_event(conversation_id, "handoff.to_human", {"reason": "billing"})

Both need the conversation to exist on our side first, so they flush pending calls before sending. Both return True when accepted and never raise. Pass a stable event_id so a retried event is counted once. Properties are flat strings, numbers and booleans.

Redaction

generalcontext.initialize(redact=True)   # emails, phones, card- and SSN-like numbers
generalcontext.initialize(redact=fn)     # or your own: str -> str, applied to every string

Values become stable placeholders (<phone:3f2a1c>) before anything leaves your process. Set GENERALCONTEXT_REDACT_SALT to one secret in every process so placeholders match.

Configuration

Option Default Meaning
api_key GENERALCONTEXT_API_KEY Workspace key. Without it nothing is sent.
base_url GENERALCONTEXT_BASE_URL, else https://generalcontextlabs.com Must be https:// (plain http:// only for localhost).
app_name None Label for this app.
redact False True for built-in PII redaction, or a str -> str function. Also applied to outcomes and events.
before_send None fn(call) -> dict or None, runs on the sender thread before redaction. None or an exception drops the call.
instrument_http False Also record raw httpx/requests POSTs to /chat/completions.
disable_batch False Send each call on its own.
Env var Meaning
GENERALCONTEXT_API_KEY Default api_key.
GENERALCONTEXT_BASE_URL Default base_url.
GENERALCONTEXT_REDACT_SALT Shared secret so redaction placeholders match across processes.
GENERALCONTEXT_DISABLED 1, true or yes makes initialize() do nothing.

HTTPS_PROXY and SSL_CERT_FILE are honored via urllib. Redirects are never followed. Calls over 4 MB are dropped, and the in-memory queue is capped at 64 MB. A second initialize() is ignored. wrap(client) and conversation(...) from 0.1 still work.

Tests: cd python && python -m unittest test_sdk -v.

License

Apache License 2.0. See LICENSE and NOTICE.

Metadata

Release files for generalcontext 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for generalcontext 0.2.0
File Size Uploaded Provenance Actions
generalcontext-0.2.0.tar.gz 21.1 kB With provenance Details for generalcontext-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for generalcontext 0.2.0
File Interpreter ABI Platform Actions
generalcontext-0.2.0-py3-none-any.whl Python 3 none any Details for generalcontext-0.2.0-py3-none-any.whl

Total release size: 37.5 kB

Release files / generalcontext-0.2.0.tar.gz

Download URL generalcontext-0.2.0.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
712c4188eb9c08cf4117837cf246fe4d01ca703eeede298825b5264ea5a3d3af
BLAKE2b-256 checksum
How to use checksums
b5174a4ad6dc2701a16f03fa3c588ac39e0bcaf39c3569fe971ace82c42787ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / generalcontext-0.2.0-py3-none-any.whl

Download URL generalcontext-0.2.0-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72a8c7b6125f22bee9dd5d313dd7677f9bcb4936980eb2f856d08b3fbdc06f4a
BLAKE2b-256 checksum
How to use checksums
ca57b0ef9ff7f89e0ce43c1f3c53360e64951c479397c7ec7bc89a91e640ec73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for generalcontext 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for generalcontext-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page