Skip to main content

promptstore-telemetry (Python SDK)

Fail-safe agentic-harness observability for promptstore. Emits canonical spans (loops, tool calls, sub-agents, model calls, context-lifecycle events) to a promptstore telemetry endpoint.

Safety guarantees

This SDK is designed so that promptstore can never impact your application:

  • Non-blocking — spans are enqueued to a bounded in-memory buffer and flushed by a background daemon thread.
  • Never raises into your code — every telemetry operation is guarded. Your own exceptions inside a with span(...) still propagate (and are recorded as an error status).
  • Bounded memory — under backpressure the buffer drops the oldest spans.
  • Circuit breaker — repeated failures open a breaker and the SDK stops trying (and stops buffering) until a cooldown elapses.
  • Zero runtime dependencies — standard library only.

Install

From PyPI:

pip install promptstore-telemetry

Requires Python 3.10+. The SDK has zero runtime dependencies (standard library only).

Pin a version for reproducible builds:

pip install "promptstore-telemetry==0.1.0"

Or add it to your project:

# pyproject.toml
dependencies = ["promptstore-telemetry>=0.1.0"]
# requirements.txt
promptstore-telemetry>=0.1.0

From source

To develop against a checkout of this repo (editable install):

pip install -e sdk/python          # add [dev] for the test extras: pip install -e "sdk/python[dev]"

Usage

import promptstore_telemetry as ps

ps.configure(base_url="https://promptstore.example.com", api_key="pst_...")
# or set PROMPTSTORE_URL and PROMPTSTORE_TELEMETRY_KEY

with ps.trace("research-agent") as run:
    for turn in range(max_turns):
        with ps.span(ps.SpanKind.LOOP_ITERATION, f"turn-{turn}"):
            with ps.span(ps.SpanKind.MODEL_CALL, "plan") as m:
                m.set_model(provider="anthropic", response_model="claude-3-5-sonnet-20241022")
                m.set_usage(prompt_tokens=1200, completion_tokens=300, cached_tokens=800)

            # context lifecycle — powers the Context view (budget chart,
            # composition, change cards). Include sources=[...] for full
            # per-source attribution; see docs/telemetry-sdk.md
            # ("Instrumenting context") and examples/multi_agent.py.
            ps.context_event(ps.ContextEventName.COMPACT,
                             sources=[{"source": "history", "tokens": 30000,
                                       "label": "summary of earlier turns"}],
                             window_tokens_before=180000, window_tokens_after=90000,
                             window_limit=200000,
                             tokens_reclaimed=90000, method="summarize")

@ps.tool("web_search")
def web_search(q): ...

# sub-agents across processes
with ps.subagent("researcher") as sub:
    traceparent = ps.get_traceparent()   # hand to the child process

Conversations (multi-turn, human-in-the-loop)

A multi-turn chat is modelled as one run: each user turn is a LOOP_ITERATION and waiting on the user is a first-class HITL_PAUSE span (its duration is the user's think-time). It shows as a single row in Harness Traces with status active / awaiting user / done, and the waterfall shows each turn separated by a "waiting for user" pause. Ids are derived from your conversation id, so turns in separate processes/requests stitch into the same run with no shared state:

# per incoming user message for `conv_id`, at turn index `n`:
with ps.conversation(conv_id, close_on_exit=False):
    ps.hitl_pause_close(index=n - 1)          # the user just replied
    with ps.turn(index=n):
        with ps.span(ps.SpanKind.MODEL_CALL, "respond") as m:
            m.set_usage(prompt_tokens=1000, completion_tokens=120)
    ps.hitl_pause_open(index=n)               # yield back to the user
# when the conversation ends:
ps.end_conversation(conv_id)

For a single long-lived loop that owns the whole conversation, keep the block open and let the default close_on_exit=True close it. A conversation parked on an open HITL_PAUSE is exempt from the stale-run reaper. See docs/telemetry-sdk.md.

Get a write-only telemetry key from promptstore: POST /api/workspaces/:workspaceId/telemetry-keys.

Configuration

configure(base_url, api_key, *, flush_interval=2.0, max_batch=128, max_buffer=10000, emit_on_start=True, timeout=5.0, circuit_fail_threshold=5, circuit_cooldown=30.0, redactor=None, deny_keys=None, session_id=None, enabled=True)

  • emit_on_start — also emit a span when it opens (enables the live view). The server upserts start+end into one row.
  • redactor / deny_keys — PII redaction hooks applied to attributes and event payloads before they leave the process.
  • session_id — default conversation/session id stamped on every span; usually set per-conversation via ps.conversation(...) instead.

Download files

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

Source Distribution

promptstore_telemetry-0.1.1.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

promptstore_telemetry-0.1.1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file promptstore_telemetry-0.1.1.tar.gz.

File metadata

  • Download URL: promptstore_telemetry-0.1.1.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for promptstore_telemetry-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9fa6c78bb4ac9bcbeb7870ace0969e51b7d8448eda16945c95fa89b8c8d2440b
MD5 c465c72a3d28a7958f2a0647a7d4765f
BLAKE2b-256 f6691262a5bbb98219d960b6229370bd03438e511c61018bf6ca95ea60b26863

See more details on using hashes here.

File details

Details for the file promptstore_telemetry-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for promptstore_telemetry-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad4e0084804613f4745537a7cf7d847a6aa1798f9ab83d73e265fc1eebbcf162
MD5 e54ac9892fcf87adcad66f58352a0c66
BLAKE2b-256 5b8630754e58423c16361b5c6936aa08cf5cb66c5653ed93a1dc6dae1ff89270

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

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