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]})

For LangGraph, pass the app's session id as thread_id. The callback handler maps that internal LangGraph thread id to gen_ai.conversation.id.

thread_id = "user-session-123"
response = graph.invoke(
    {"messages": [{"role": "user", "content": "Hello!"}]},
    config={"callbacks": [handler], "configurable": {"thread_id": thread_id}},
)

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.2.tar.gz (53.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.2-py3-none-any.whl (66.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: introspection_sdk-0.4.2.tar.gz
  • Upload date:
  • Size: 53.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.2.tar.gz
Algorithm Hash digest
SHA256 5d985a7866fcd9d2aa1e6c3bdb998938400dc591784446c95cfeca020b13d52e
MD5 7b70a7098e66aafe8849057ed1894447
BLAKE2b-256 e5f77fb62205e46e5ac5725ef82f226a25b5ef97116882fb3fd3921dc6fcf41c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for introspection_sdk-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1d7d0acdc46027c17bf1ae302f30892b391445f30ba170f485be767772c0c352
MD5 bde607ca7650653602f4adc746bc5c91
BLAKE2b-256 601910d53a9f2aadfce5e0a76025270e7182ef42058d7ca521719ca4178f35d7

See more details on using hashes here.

Provenance

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