Skip to main content

Python SDK for Introspection — continuously improve your AI systems with production feedback and frontier practices

Project description

Build frontier AI systems that self-improve.

Website PyPI version License Follow on X

Introspection continuously improves your AI systems with production feedback and frontier practices. This is the Python SDK.

Install

uv add introspection-sdk
# or
pip install introspection-sdk

The default install is REST-only — no OpenTelemetry pulled in. Add the [otel] extra to enable analytics events and trace export:

pip install 'introspection-sdk[otel]'

Optional extras

Per-framework convenience installs (init() auto-detects frameworks however they were installed — these are just one-command setup):

pip install 'introspection-sdk[anthropic]'      # Anthropic SDK
pip install 'introspection-sdk[gemini]'         # Google Gemini (google-genai)
pip install 'introspection-sdk[openai-agents]'  # OpenAI Agents SDK
pip install 'introspection-sdk[claude-agent]'   # Claude Agent SDK
pip install 'introspection-sdk[langchain]'      # LangChain / LangGraph
pip install 'introspection-sdk[logfire]'        # Logfire
pip install 'introspection-sdk[all]'            # Everything above

Three independent surfaces

The Python SDK exposes three surfaces you can adopt independently:

  1. Introspection API (runtimes, tasks, files, conversations) with IntrospectionClient — the main Introspection API. Zero OpenTelemetry imports. Always available.
  2. Analytics events (track, feedback, identify) with IntrospectionLogs — OTel logs exporter with baggage helpers. Owns its own LoggerProvider. Lives at introspection_sdk.IntrospectionLogs. Requires the [otel] extra.
  3. Traces (span processors + instrumentors) with IntrospectionSpanProcessor and friends — IntrospectionTracingProcessor, ClaudeTracingProcessor, the LangChain callback handler, AnthropicInstrumentor, GeminiInstrumentor. Plus the introspection_sdk.init() convenience that auto-wires every supported framework. All under introspection_sdk.otel (or the dedicated introspection_sdk.integrations.langchain subpath for the LangChain handler). Requires the [otel] extra.

1. Introspection API (runtimes, tasks, files) with IntrospectionClient

The main Introspection API surface. No OTel packages required — install just the SDK:

pip install introspection-sdk
from introspection_sdk import IntrospectionClient

client = IntrospectionClient()  # token from INTROSPECTION_TOKEN

runner = client.runtimes("customer-agent").run()

run = runner.tasks.start(prompt="Say hello in one sentence.")

for event in run.stream():
    print(f"[{event.event}] {event.data}")

runner.close()
client.shutdown()

A Runner exposes three DP-bound namespaces side by side: runner.tasks, runner.files, and the read-only runner.conversations. The conversations namespace lists conversation summaries (runner.conversations.list()), loads the latest LLM turn of a conversation as a Responses-API-style view (runner.conversations.retrieve(conversation_id)), and walks a conversation's per-turn items (runner.conversations.items.list(...)).

Every list() returns a Pager: iterate it to stream every item across pages (fetched lazily), or call .page() for the first page with its envelope metadata (counts, cursors):

# Stream every summary across all pages.
for summary in runner.conversations.list(limit=20):
    response = runner.conversations.retrieve(summary.conversation_id or summary.trace_id)
    if response is not None:
        print(response.model, len(response.input_messages))

# Or just the first page, with totals.
first = runner.files.list(include_total=True).page()
print(first.total_count, len(first.records))

See examples/api/runtimes.py for an end-to-end walkthrough.

2. Analytics events (track, feedback, identify) with IntrospectionLogs

Install the SDK with the [otel] extra:

pip install 'introspection-sdk[otel]'
from introspection_sdk import IntrospectionLogs

logs = IntrospectionLogs(
    token="intro_xxx",        # or env: INTROSPECTION_TOKEN
    service_name="my-service",
    base_url="https://otel.introspection.dev",  # or env: INTROSPECTION_BASE_OTEL_URL
    project_id="proj_…",      # or env: INTROSPECTION_PROJECT_ID — optional
)

with logs.identify("user_123", traits={"plan": "pro"}):
    with logs.conversation("conv_456", previous_response_id="msg_123"):
        logs.feedback("thumbs_up", comments="Great response!")

logs.track("checkout_completed", {"amount": 42})
logs.shutdown()

Methods

Method Description
track(event, properties=) Track any user action
feedback(type, **kwargs) Track feedback on AI responses
identify(user_id, traits=) Associate a user with traits (context manager)
flush(timeout_ms=30000) Flush pending events
shutdown() Shutdown and flush

Context managers

Method Description
conversation(id?, previous_response_id?) Set conversation context
with_user_id(id) Set user context
with_agent(name, id?) Set agent context
with_anonymous_id(id) Set anonymous ID
with_baggage(**values) Set arbitrary baggage values

3. Traces (span processors + instrumentors) with IntrospectionSpanProcessor

Install the SDK with the [otel] extra plus your framework extras of choice (or [all]):

pip install 'introspection-sdk[otel,anthropic,gemini,openai-agents,claude-agent,langchain]'

Auto-wired via init() — recommended

introspection.init() detects every supported LLM framework you have installed and wires them all into a single trace pipeline:

import introspection_sdk as introspection

introspection.init()  # token from INTROSPECTION_TOKEN

# ...use Anthropic, Gemini, OpenAI Agents, Claude Agent, Logfire as usual —
# their calls are now traced automatically.

Auto-detected frameworks: Anthropic SDK, Google Gemini (google-genai), OpenAI Agents SDK, Claude Agent SDK, Logfire / OpenInference (configure Logfire before init()), and LangChain / LangGraph (attach get_handler() — see below).

LangChain callbacks are per-invoke, so init() prepares the handler and you attach it:

import introspection_sdk as introspection
from introspection_sdk.integrations.langchain import get_handler

introspection.init()
response = model.invoke("Hello!", config={"callbacks": [get_handler()]})

After init(), the module-level introspection.track() / introspection.feedback() / introspection.identify() shortcuts proxy to the global IntrospectionLogs.

Manual / advanced setup

init() is the recommended entry point, but the individual processors and instrumentors remain fully supported for custom wiring (sharing a TracerProvider, dual-export, testing). See docs/advanced.md for opting out of auto-discovery, passing your own provider, standalone processor construction, and testing with an in-memory exporter.

See examples/ for complete integration patterns including dual-export with Arize, Langfuse, Braintrust, and LangSmith.

Environment variables

# Introspection API (IntrospectionClient)
export INTROSPECTION_TOKEN="intro_xxx"
export INTROSPECTION_BASE_API_URL="https://api.introspection.dev"   # optional
export INTROSPECTION_PROJECT_ID="proj_…"                            # optional

# OTel (IntrospectionLogs + span processors + instrumentors)
export INTROSPECTION_BASE_OTEL_URL="https://otel.introspection.dev" # optional
export INTROSPECTION_SERVICE_NAME="my-service"                      # optional

Documentation

Full documentation is available at docs.introspection.dev.

License

Apache-2.0

Project details


Download files

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

Source Distribution

introspection_sdk-0.4.5.tar.gz (90.3 kB view details)

Uploaded Source

Built Distribution

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

introspection_sdk-0.4.5-py3-none-any.whl (122.4 kB view details)

Uploaded Python 3

File details

Details for the file introspection_sdk-0.4.5.tar.gz.

File metadata

  • Download URL: introspection_sdk-0.4.5.tar.gz
  • Upload date:
  • Size: 90.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for introspection_sdk-0.4.5.tar.gz
Algorithm Hash digest
SHA256 c0c20f31071b0b1e6e399c48f2af638d7012204623f9795ac6f71ba8c8eb3ad4
MD5 08eb69b2138e7a43f4815a4cd38aa6a9
BLAKE2b-256 418652fe183e316e2d38954cbf82be18ea1147c59252dcca71420a31962dae4e

See more details on using hashes here.

Provenance

The following attestation bundles were made for introspection_sdk-0.4.5.tar.gz:

Publisher: publish.yml on introspection-org/introspection-python-sdk

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

File details

Details for the file introspection_sdk-0.4.5-py3-none-any.whl.

File metadata

File hashes

Hashes for introspection_sdk-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1d30c48a9206c777fffdb8067cdb9a446abbb2fa0b06b4316b30281a9d6e0130
MD5 a4570c9856c5e4ee2419a2bfed7db787
BLAKE2b-256 0bd70a3f726a9c881cd4b16341bfbefa7fd2077aef27fe95df58fc28c60aae75

See more details on using hashes here.

Provenance

The following attestation bundles were made for introspection_sdk-0.4.5-py3-none-any.whl:

Publisher: publish.yml on introspection-org/introspection-python-sdk

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

Supported by

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