introspection-sdk 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. introspection_sdk-0.4.0/.gitignore +15 -0
  2. introspection_sdk-0.4.0/PKG-INFO +210 -0
  3. introspection_sdk-0.4.0/README.md +172 -0
  4. introspection_sdk-0.4.0/introspection_sdk/__init__.py +52 -0
  5. introspection_sdk-0.4.0/introspection_sdk/anthropic.py +628 -0
  6. introspection_sdk-0.4.0/introspection_sdk/client.py +696 -0
  7. introspection_sdk-0.4.0/introspection_sdk/config.py +95 -0
  8. introspection_sdk-0.4.0/introspection_sdk/converters/__init__.py +31 -0
  9. introspection_sdk-0.4.0/introspection_sdk/converters/genai_to_openinference.py +368 -0
  10. introspection_sdk-0.4.0/introspection_sdk/converters/logfire.py +377 -0
  11. introspection_sdk-0.4.0/introspection_sdk/converters/openai.py +388 -0
  12. introspection_sdk-0.4.0/introspection_sdk/converters/openinference.py +744 -0
  13. introspection_sdk-0.4.0/introspection_sdk/processors/__init__.py +21 -0
  14. introspection_sdk-0.4.0/introspection_sdk/processors/claude_tracing_processor.py +738 -0
  15. introspection_sdk-0.4.0/introspection_sdk/processors/langchain_callback_handler.py +713 -0
  16. introspection_sdk-0.4.0/introspection_sdk/processors/span_processor.py +420 -0
  17. introspection_sdk-0.4.0/introspection_sdk/processors/tracing_processor.py +600 -0
  18. introspection_sdk-0.4.0/introspection_sdk/schemas/__init__.py +23 -0
  19. introspection_sdk-0.4.0/introspection_sdk/schemas/genai.py +172 -0
  20. introspection_sdk-0.4.0/introspection_sdk/sessions.py +29 -0
  21. introspection_sdk-0.4.0/introspection_sdk/testing.py +95 -0
  22. introspection_sdk-0.4.0/introspection_sdk/types.py +309 -0
  23. introspection_sdk-0.4.0/introspection_sdk/utils.py +40 -0
  24. introspection_sdk-0.4.0/introspection_sdk/version.py +5 -0
  25. introspection_sdk-0.4.0/pyproject.toml +95 -0
@@ -0,0 +1,15 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+
12
+ .env
13
+
14
+ # Claude Code
15
+ .claude/
@@ -0,0 +1,210 @@
1
+ Metadata-Version: 2.4
2
+ Name: introspection-sdk
3
+ Version: 0.4.0
4
+ Summary: Python SDK for Introspection — continuously improve your AI systems with production feedback and frontier practices
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: openai>=2.30.0
7
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http<1.40.0,>=1.39.0
8
+ Requires-Dist: opentelemetry-sdk<1.40.0,>=1.39.0
9
+ Provides-Extra: arize
10
+ Requires-Dist: arize-phoenix>=8.0.0; extra == 'arize'
11
+ Requires-Dist: openinference-instrumentation-openai>=0.1.0; extra == 'arize'
12
+ Provides-Extra: braintrust
13
+ Requires-Dist: braintrust[otel]>=0.1.0; extra == 'braintrust'
14
+ Provides-Extra: dev
15
+ Requires-Dist: pre-commit>=3.5.0; extra == 'dev'
16
+ Requires-Dist: ruff==0.14.14; extra == 'dev'
17
+ Requires-Dist: ty>=0.0.7; extra == 'dev'
18
+ Provides-Extra: langfuse
19
+ Requires-Dist: langfuse>=3.0.0; extra == 'langfuse'
20
+ Provides-Extra: openai-agents
21
+ Requires-Dist: openai-agents>=0.12.2; extra == 'openai-agents'
22
+ Provides-Extra: test
23
+ Requires-Dist: anthropic>=0.85.0; extra == 'test'
24
+ Requires-Dist: claude-agent-sdk<=0.1.7,>=0.1.0; extra == 'test'
25
+ Requires-Dist: dirty-equals>=0.11.0; extra == 'test'
26
+ Requires-Dist: inline-snapshot>=0.31.0; extra == 'test'
27
+ Requires-Dist: openai-agents>=0.12.2; extra == 'test'
28
+ Requires-Dist: posthog>=7.9.0; extra == 'test'
29
+ Requires-Dist: pydantic-ai>=1.68.0; extra == 'test'
30
+ Requires-Dist: pydantic>=2.12.0; extra == 'test'
31
+ Requires-Dist: pytest-asyncio>=1.3.0; extra == 'test'
32
+ Requires-Dist: pytest-dotenv>=0.5.2; extra == 'test'
33
+ Requires-Dist: pytest-mock>=3.15.0; extra == 'test'
34
+ Requires-Dist: pytest-recording>=0.13.4; extra == 'test'
35
+ Requires-Dist: pytest>=9.0.0; extra == 'test'
36
+ Requires-Dist: responses>=0.25.8; extra == 'test'
37
+ Description-Content-Type: text/markdown
38
+
39
+ <div align="center">
40
+ <a href="https://introspection.dev">
41
+ <picture>
42
+ <source media="(prefers-color-scheme: dark)" srcset=".github/images/logo-dark.svg">
43
+ <source media="(prefers-color-scheme: light)" srcset=".github/images/logo-light.svg">
44
+ <img alt="Introspection" src=".github/images/logo-light.svg" width="30%">
45
+ </picture>
46
+ </a>
47
+ </div>
48
+
49
+ <h4 align="center">Build frontier AI systems that self-improve.</h4>
50
+
51
+ <div align="center">
52
+ <a href="https://introspection.dev"><img src="https://img.shields.io/badge/website-introspection.dev-blue" alt="Website"></a>
53
+ <a href="https://pypi.org/project/introspection-sdk/"><img src="https://img.shields.io/pypi/v/introspection-sdk?label=%20" alt="PyPI version"></a>
54
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-green" alt="License"></a>
55
+ <a href="https://x.com/IntrospectionAI"><img src="https://img.shields.io/twitter/follow/IntrospectionAI" alt="Follow on X"></a>
56
+ </div>
57
+
58
+ <br>
59
+
60
+ [Introspection](https://introspection.dev) continuously improves your AI systems with production feedback and frontier practices. This is the Python SDK.
61
+
62
+ ## Install
63
+
64
+ ```shell
65
+ uv add introspection-sdk
66
+ # or
67
+ pip install introspection-sdk
68
+ ```
69
+
70
+ ### Optional Extras
71
+
72
+ ```shell
73
+ pip install 'introspection-sdk[openai-agents]' # OpenAI Agents SDK
74
+ pip install 'introspection-sdk[langfuse]' # Langfuse
75
+ pip install 'introspection-sdk[braintrust]' # Braintrust
76
+ pip install 'introspection-sdk[arize]' # Arize Phoenix + OpenInference
77
+ ```
78
+
79
+ ## Environment Variables
80
+
81
+ ```shell
82
+ export INTROSPECTION_TOKEN="intro_xxx"
83
+ export INTROSPECTION_BASE_URL="https://otel.introspection.dev" # optional
84
+ ```
85
+
86
+ ## Quickstart
87
+
88
+ ### OpenTelemetry Span Processor
89
+
90
+ ```python
91
+ from introspection_sdk import IntrospectionSpanProcessor
92
+ import logfire
93
+
94
+ logfire.configure(
95
+ additional_span_processors=[IntrospectionSpanProcessor()],
96
+ )
97
+
98
+ logfire.instrument_openai()
99
+ ```
100
+
101
+ ### OpenAI Agents SDK
102
+
103
+ ```python
104
+ from agents import Agent, Runner, set_trace_processors, tool
105
+ from introspection_sdk import IntrospectionTracingProcessor
106
+
107
+ set_trace_processors([IntrospectionTracingProcessor()])
108
+
109
+ @tool
110
+ def get_weather(city: str) -> str:
111
+ """Get the current weather for a city."""
112
+ return f"Sunny, 72F in {city}"
113
+
114
+ agent = Agent(name="Weather Bot", tools=[get_weather])
115
+ result = await Runner.run(agent, "What's the weather in Tokyo?")
116
+ ```
117
+
118
+ #### Reasoning Model Support
119
+
120
+ Some models produce reasoning items that the OpenAI Conversations API rejects. `IntrospectionConversationsSession` strips those items transparently:
121
+
122
+ ```python
123
+ from introspection_sdk import IntrospectionConversationsSession
124
+
125
+ session = IntrospectionConversationsSession(conversation_id="conv_123")
126
+ result = await Runner.run(agent, "Hello!", session=session)
127
+ ```
128
+
129
+ ### Claude Agent SDK
130
+
131
+ ```python
132
+ from introspection_sdk import ClaudeTracingProcessor
133
+
134
+ processor = ClaudeTracingProcessor()
135
+ processor.configure()
136
+
137
+ # All ClaudeSDKClient instances are now automatically traced
138
+ ```
139
+
140
+ ### LangChain / LangGraph
141
+
142
+ ```python
143
+ from introspection_sdk import IntrospectionCallbackHandler
144
+
145
+ handler = IntrospectionCallbackHandler(service_name="my-app")
146
+ response = model.invoke("Hello!", config={"callbacks": [handler]})
147
+ ```
148
+
149
+ ### Anthropic SDK
150
+
151
+ ```python
152
+ from introspection_sdk.anthropic import AnthropicInstrumentor
153
+
154
+ instrumentor = AnthropicInstrumentor()
155
+ instrumentor.instrument(tracer_provider=provider)
156
+
157
+ # All client.messages.create calls are traced, including thinking blocks
158
+ ```
159
+
160
+ ### OpenInference (Arize, Langfuse, Braintrust)
161
+
162
+ ```python
163
+ from opentelemetry.sdk.trace import TracerProvider
164
+ from openinference.instrumentation.openai import OpenAIInstrumentor
165
+ from introspection_sdk import IntrospectionSpanProcessor
166
+
167
+ provider = TracerProvider()
168
+ provider.add_span_processor(IntrospectionSpanProcessor())
169
+ OpenAIInstrumentor().instrument(tracer_provider=provider)
170
+ ```
171
+
172
+ > See [examples/](./examples/) for complete integration patterns including dual-export with Arize, Langfuse, Braintrust, and LangSmith.
173
+
174
+ ## Client API
175
+
176
+ ```python
177
+ from introspection_sdk import IntrospectionClient
178
+
179
+ client = IntrospectionClient()
180
+
181
+ with client.set_user_id("user_123"):
182
+ with client.set_conversation("conv_456", previous_response_id="msg_123"):
183
+ client.feedback("thumbs_up", comments="Great response!")
184
+
185
+ client.shutdown()
186
+ ```
187
+
188
+ ### Methods
189
+
190
+ | Method | Description |
191
+ | ------ | ----------- |
192
+ | `feedback(type, **kwargs)` | Track feedback on AI responses |
193
+ | `identify(user_id, traits=)` | Associate a user with traits (context manager) |
194
+ | `track(event, properties=)` | Track any user action |
195
+ | `flush(timeout_ms=30000)` | Flush pending events |
196
+ | `shutdown()` | Shutdown and flush |
197
+
198
+ ### Context Managers
199
+
200
+ | Method | Description |
201
+ | ------ | ----------- |
202
+ | `set_user_id(id)` | Set user context |
203
+ | `set_conversation(id?, response_id?)` | Set conversation context |
204
+ | `set_agent(name, id?)` | Set agent context |
205
+ | `set_anonymous_id(id)` | Set anonymous ID |
206
+ | `set_baggage(**values)` | Set arbitrary baggage values |
207
+
208
+ ## Documentation
209
+
210
+ Full documentation is available at [docs.introspection.dev](https://docs.introspection.dev).
@@ -0,0 +1,172 @@
1
+ <div align="center">
2
+ <a href="https://introspection.dev">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset=".github/images/logo-dark.svg">
5
+ <source media="(prefers-color-scheme: light)" srcset=".github/images/logo-light.svg">
6
+ <img alt="Introspection" src=".github/images/logo-light.svg" width="30%">
7
+ </picture>
8
+ </a>
9
+ </div>
10
+
11
+ <h4 align="center">Build frontier AI systems that self-improve.</h4>
12
+
13
+ <div align="center">
14
+ <a href="https://introspection.dev"><img src="https://img.shields.io/badge/website-introspection.dev-blue" alt="Website"></a>
15
+ <a href="https://pypi.org/project/introspection-sdk/"><img src="https://img.shields.io/pypi/v/introspection-sdk?label=%20" alt="PyPI version"></a>
16
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-green" alt="License"></a>
17
+ <a href="https://x.com/IntrospectionAI"><img src="https://img.shields.io/twitter/follow/IntrospectionAI" alt="Follow on X"></a>
18
+ </div>
19
+
20
+ <br>
21
+
22
+ [Introspection](https://introspection.dev) continuously improves your AI systems with production feedback and frontier practices. This is the Python SDK.
23
+
24
+ ## Install
25
+
26
+ ```shell
27
+ uv add introspection-sdk
28
+ # or
29
+ pip install introspection-sdk
30
+ ```
31
+
32
+ ### Optional Extras
33
+
34
+ ```shell
35
+ pip install 'introspection-sdk[openai-agents]' # OpenAI Agents SDK
36
+ pip install 'introspection-sdk[langfuse]' # Langfuse
37
+ pip install 'introspection-sdk[braintrust]' # Braintrust
38
+ pip install 'introspection-sdk[arize]' # Arize Phoenix + OpenInference
39
+ ```
40
+
41
+ ## Environment Variables
42
+
43
+ ```shell
44
+ export INTROSPECTION_TOKEN="intro_xxx"
45
+ export INTROSPECTION_BASE_URL="https://otel.introspection.dev" # optional
46
+ ```
47
+
48
+ ## Quickstart
49
+
50
+ ### OpenTelemetry Span Processor
51
+
52
+ ```python
53
+ from introspection_sdk import IntrospectionSpanProcessor
54
+ import logfire
55
+
56
+ logfire.configure(
57
+ additional_span_processors=[IntrospectionSpanProcessor()],
58
+ )
59
+
60
+ logfire.instrument_openai()
61
+ ```
62
+
63
+ ### OpenAI Agents SDK
64
+
65
+ ```python
66
+ from agents import Agent, Runner, set_trace_processors, tool
67
+ from introspection_sdk import IntrospectionTracingProcessor
68
+
69
+ set_trace_processors([IntrospectionTracingProcessor()])
70
+
71
+ @tool
72
+ def get_weather(city: str) -> str:
73
+ """Get the current weather for a city."""
74
+ return f"Sunny, 72F in {city}"
75
+
76
+ agent = Agent(name="Weather Bot", tools=[get_weather])
77
+ result = await Runner.run(agent, "What's the weather in Tokyo?")
78
+ ```
79
+
80
+ #### Reasoning Model Support
81
+
82
+ Some models produce reasoning items that the OpenAI Conversations API rejects. `IntrospectionConversationsSession` strips those items transparently:
83
+
84
+ ```python
85
+ from introspection_sdk import IntrospectionConversationsSession
86
+
87
+ session = IntrospectionConversationsSession(conversation_id="conv_123")
88
+ result = await Runner.run(agent, "Hello!", session=session)
89
+ ```
90
+
91
+ ### Claude Agent SDK
92
+
93
+ ```python
94
+ from introspection_sdk import ClaudeTracingProcessor
95
+
96
+ processor = ClaudeTracingProcessor()
97
+ processor.configure()
98
+
99
+ # All ClaudeSDKClient instances are now automatically traced
100
+ ```
101
+
102
+ ### LangChain / LangGraph
103
+
104
+ ```python
105
+ from introspection_sdk import IntrospectionCallbackHandler
106
+
107
+ handler = IntrospectionCallbackHandler(service_name="my-app")
108
+ response = model.invoke("Hello!", config={"callbacks": [handler]})
109
+ ```
110
+
111
+ ### Anthropic SDK
112
+
113
+ ```python
114
+ from introspection_sdk.anthropic import AnthropicInstrumentor
115
+
116
+ instrumentor = AnthropicInstrumentor()
117
+ instrumentor.instrument(tracer_provider=provider)
118
+
119
+ # All client.messages.create calls are traced, including thinking blocks
120
+ ```
121
+
122
+ ### OpenInference (Arize, Langfuse, Braintrust)
123
+
124
+ ```python
125
+ from opentelemetry.sdk.trace import TracerProvider
126
+ from openinference.instrumentation.openai import OpenAIInstrumentor
127
+ from introspection_sdk import IntrospectionSpanProcessor
128
+
129
+ provider = TracerProvider()
130
+ provider.add_span_processor(IntrospectionSpanProcessor())
131
+ OpenAIInstrumentor().instrument(tracer_provider=provider)
132
+ ```
133
+
134
+ > See [examples/](./examples/) for complete integration patterns including dual-export with Arize, Langfuse, Braintrust, and LangSmith.
135
+
136
+ ## Client API
137
+
138
+ ```python
139
+ from introspection_sdk import IntrospectionClient
140
+
141
+ client = IntrospectionClient()
142
+
143
+ with client.set_user_id("user_123"):
144
+ with client.set_conversation("conv_456", previous_response_id="msg_123"):
145
+ client.feedback("thumbs_up", comments="Great response!")
146
+
147
+ client.shutdown()
148
+ ```
149
+
150
+ ### Methods
151
+
152
+ | Method | Description |
153
+ | ------ | ----------- |
154
+ | `feedback(type, **kwargs)` | Track feedback on AI responses |
155
+ | `identify(user_id, traits=)` | Associate a user with traits (context manager) |
156
+ | `track(event, properties=)` | Track any user action |
157
+ | `flush(timeout_ms=30000)` | Flush pending events |
158
+ | `shutdown()` | Shutdown and flush |
159
+
160
+ ### Context Managers
161
+
162
+ | Method | Description |
163
+ | ------ | ----------- |
164
+ | `set_user_id(id)` | Set user context |
165
+ | `set_conversation(id?, response_id?)` | Set conversation context |
166
+ | `set_agent(name, id?)` | Set agent context |
167
+ | `set_anonymous_id(id)` | Set anonymous ID |
168
+ | `set_baggage(**values)` | Set arbitrary baggage values |
169
+
170
+ ## Documentation
171
+
172
+ Full documentation is available at [docs.introspection.dev](https://docs.introspection.dev).
@@ -0,0 +1,52 @@
1
+ """Introspection Python SDK."""
2
+
3
+ from introspection_sdk.anthropic import (
4
+ REDACTED_THINKING_CONTENT,
5
+ AnthropicInstrumentor,
6
+ )
7
+ from introspection_sdk.client import IntrospectionClient
8
+ from introspection_sdk.config import AdvancedOptions
9
+ from introspection_sdk.processors.claude_tracing_processor import (
10
+ ClaudeTracingProcessor,
11
+ )
12
+ from introspection_sdk.processors.langchain_callback_handler import (
13
+ IntrospectionCallbackHandler,
14
+ )
15
+ from introspection_sdk.processors.span_processor import (
16
+ IntrospectionSpanProcessor,
17
+ )
18
+ from introspection_sdk.processors.tracing_processor import (
19
+ IntrospectionTracingProcessor,
20
+ )
21
+ from introspection_sdk.types import (
22
+ Attr,
23
+ Baggage,
24
+ EventName,
25
+ FeedbackProperties,
26
+ )
27
+
28
+ __all__ = [
29
+ "AdvancedOptions",
30
+ "AnthropicInstrumentor",
31
+ "REDACTED_THINKING_CONTENT",
32
+ "Attr",
33
+ "Baggage",
34
+ "ClaudeTracingProcessor",
35
+ "IntrospectionCallbackHandler",
36
+ "EventName",
37
+ "FeedbackProperties",
38
+ "IntrospectionClient",
39
+ "IntrospectionConversationsSession",
40
+ "IntrospectionSpanProcessor",
41
+ "IntrospectionTracingProcessor",
42
+ ]
43
+
44
+
45
+ def __getattr__(name: str) -> object:
46
+ if name == "IntrospectionConversationsSession":
47
+ from introspection_sdk.sessions import (
48
+ IntrospectionConversationsSession,
49
+ )
50
+
51
+ return IntrospectionConversationsSession
52
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")