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

Optional Extras

pip install 'introspection-sdk[openai-agents]'  # OpenAI Agents SDK
pip install 'introspection-sdk[langfuse]'        # Langfuse
pip install 'introspection-sdk[braintrust]'      # Braintrust
pip install 'introspection-sdk[arize]'           # Arize Phoenix + OpenInference

Environment Variables

export INTROSPECTION_TOKEN="intro_xxx"
export INTROSPECTION_BASE_URL="https://otel.introspection.dev"  # optional

Quickstart

OpenTelemetry Span Processor

from introspection_sdk import IntrospectionSpanProcessor
import logfire

logfire.configure(
    additional_span_processors=[IntrospectionSpanProcessor()],
)

logfire.instrument_openai()

OpenAI Agents SDK

from agents import Agent, Runner, set_trace_processors, tool
from introspection_sdk import IntrospectionTracingProcessor

set_trace_processors([IntrospectionTracingProcessor()])

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Sunny, 72F in {city}"

agent = Agent(name="Weather Bot", tools=[get_weather])
result = await Runner.run(agent, "What's the weather in Tokyo?")

Reasoning Model Support

Some models produce reasoning items that the OpenAI Conversations API rejects. IntrospectionConversationsSession strips those items transparently:

from introspection_sdk import IntrospectionConversationsSession

session = IntrospectionConversationsSession(conversation_id="conv_123")
result = await Runner.run(agent, "Hello!", session=session)

Claude Agent SDK

from introspection_sdk import ClaudeTracingProcessor

processor = ClaudeTracingProcessor()
processor.configure()

# All ClaudeSDKClient instances are now automatically traced

LangChain / LangGraph

from introspection_sdk import IntrospectionCallbackHandler

handler = IntrospectionCallbackHandler(service_name="my-app")
response = model.invoke("Hello!", config={"callbacks": [handler]})

Anthropic SDK

from introspection_sdk.anthropic import AnthropicInstrumentor

instrumentor = AnthropicInstrumentor()
instrumentor.instrument(tracer_provider=provider)

# All client.messages.create calls are traced, including thinking blocks

OpenInference (Arize, Langfuse, Braintrust)

from opentelemetry.sdk.trace import TracerProvider
from openinference.instrumentation.openai import OpenAIInstrumentor
from introspection_sdk import IntrospectionSpanProcessor

provider = TracerProvider()
provider.add_span_processor(IntrospectionSpanProcessor())
OpenAIInstrumentor().instrument(tracer_provider=provider)

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

Client API

from introspection_sdk import IntrospectionClient

client = IntrospectionClient()

with client.set_user_id("user_123"):
    with client.set_conversation("conv_456", previous_response_id="msg_123"):
        client.feedback("thumbs_up", comments="Great response!")

client.shutdown()

Methods

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

Context Managers

Method Description
set_user_id(id) Set user context
set_conversation(id?, response_id?) Set conversation context
set_agent(name, id?) Set agent context
set_anonymous_id(id) Set anonymous ID
set_baggage(**values) Set arbitrary baggage values

Documentation

Full documentation is available at docs.introspection.dev.

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.0.tar.gz (49.2 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.0-py3-none-any.whl (61.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: introspection_sdk-0.4.0.tar.gz
  • Upload date:
  • Size: 49.2 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.0.tar.gz
Algorithm Hash digest
SHA256 eb943828c2ea4048ba7c554f148d04d5e8c81037e493b4652ed540c1f6fd3766
MD5 4c0d08d42272a97e7dfb0f05bbf3cd56
BLAKE2b-256 76dc070cb59119971f694878653a28178ff9f8a7f2fd936300a313f318cf709f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for introspection_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30715061c0a0afcf71ff9c42d2492c2da8ad54af57ebb7d8a5c3b877e067d8ae
MD5 2ebcdce5f7498cbb64b85315f676ae70
BLAKE2b-256 e89d204704fa304e51142cad245d381f24f6f74f0aa8870992765dfec17ae47f

See more details on using hashes here.

Provenance

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