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) 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()

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.3.tar.gz (84.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.3-py3-none-any.whl (114.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: introspection_sdk-0.4.3.tar.gz
  • Upload date:
  • Size: 84.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.3.tar.gz
Algorithm Hash digest
SHA256 84f84d22bd4631de418f5ad03e87b02375f8946529181c6ca725f62fe565d3ca
MD5 a69a69512e90c66474702e0deff4dce5
BLAKE2b-256 f8ce50445f2ae928dc4c5445ece90e64c9a21d35a2c50822d2d5d711d6d42f99

See more details on using hashes here.

Provenance

The following attestation bundles were made for introspection_sdk-0.4.3.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.3-py3-none-any.whl.

File metadata

File hashes

Hashes for introspection_sdk-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ba3900cef9c68fcf597c0dc57ecf9a3240437ea342a4ce668d9ad69708b7924e
MD5 24635b68fe35d5227f6fd2c894da3b45
BLAKE2b-256 6427fd878ae1cb1ef00f705f270bc12f2650a9742a853d8292dc4b1662fea8a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for introspection_sdk-0.4.3-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