veris-ai 1.8.2__tar.gz → 1.10.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.

Potentially problematic release.


This version of veris-ai might be problematic. Click here for more details.

Files changed (41) hide show
  1. {veris_ai-1.8.2 → veris_ai-1.10.0}/CLAUDE.md +32 -10
  2. {veris_ai-1.8.2 → veris_ai-1.10.0}/PKG-INFO +142 -11
  3. {veris_ai-1.8.2 → veris_ai-1.10.0}/README.md +140 -10
  4. {veris_ai-1.8.2 → veris_ai-1.10.0}/examples/README.md +9 -6
  5. {veris_ai-1.8.2 → veris_ai-1.10.0}/examples/openai_agents_example.py +33 -26
  6. {veris_ai-1.8.2 → veris_ai-1.10.0}/pyproject.toml +2 -1
  7. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/README.md +12 -11
  8. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/__init__.py +19 -29
  9. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/agents_wrapper.py +69 -41
  10. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/models.py +1 -1
  11. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/observability.py +8 -25
  12. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/tool_mock.py +57 -8
  13. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/utils.py +19 -4
  14. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/README.md +2 -2
  15. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/test_agents_wrapper_simple.py +115 -136
  16. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/test_mcp_protocol_server_mocked.py +0 -2
  17. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/test_tool_mock.py +8 -2
  18. veris_ai-1.10.0/tests/test_veris_runner_tool_options.py +316 -0
  19. {veris_ai-1.8.2 → veris_ai-1.10.0}/uv.lock +12 -1
  20. veris_ai-1.8.2/src/veris_ai/logging.py +0 -46
  21. {veris_ai-1.8.2 → veris_ai-1.10.0}/.cursor/rules/documentation-management.mdc +0 -0
  22. {veris_ai-1.8.2 → veris_ai-1.10.0}/.github/workflows/release.yml +0 -0
  23. {veris_ai-1.8.2 → veris_ai-1.10.0}/.github/workflows/test.yml +0 -0
  24. {veris_ai-1.8.2 → veris_ai-1.10.0}/.gitignore +0 -0
  25. {veris_ai-1.8.2 → veris_ai-1.10.0}/.pre-commit-config.yaml +0 -0
  26. {veris_ai-1.8.2 → veris_ai-1.10.0}/CHANGELOG.md +0 -0
  27. {veris_ai-1.8.2 → veris_ai-1.10.0}/LICENSE +0 -0
  28. {veris_ai-1.8.2 → veris_ai-1.10.0}/examples/__init__.py +0 -0
  29. {veris_ai-1.8.2 → veris_ai-1.10.0}/examples/import_options.py +0 -0
  30. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/api_client.py +0 -0
  31. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/jaeger_interface/README.md +0 -0
  32. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/jaeger_interface/__init__.py +0 -0
  33. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/jaeger_interface/client.py +0 -0
  34. {veris_ai-1.8.2 → veris_ai-1.10.0}/src/veris_ai/jaeger_interface/models.py +0 -0
  35. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/__init__.py +0 -0
  36. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/conftest.py +0 -0
  37. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/fixtures/__init__.py +0 -0
  38. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/fixtures/http_server.py +0 -0
  39. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/fixtures/simple_app.py +0 -0
  40. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/test_agents_wrapper_extract.py +0 -0
  41. {veris_ai-1.8.2 → veris_ai-1.10.0}/tests/test_utils.py +0 -0
@@ -6,11 +6,12 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
6
6
 
7
7
  This is the Veris AI Python SDK - a package that provides simulation capabilities through decorator-based function mocking and FastAPI MCP (Model Context Protocol) integration. The core functionality revolves around:
8
8
  - `VerisSDK` class in `src/veris_ai/tool_mock.py:27` - enables environment-aware execution where functions can be mocked in simulation mode, spied on, or executed normally in production
9
- - Spy mode (`@veris.mock(mode="spy")`) - executes original functions while logging calls and responses to Redis via logging endpoints
9
+ - `@veris.spy()` decorator - executes original functions while logging calls and responses via logging endpoints
10
10
  - `convert_to_type()` function in `src/veris_ai/utils.py:5` - handles sophisticated type conversion from mock responses
11
11
  - `FastApiMCPParams` model in `src/veris_ai/models.py:1` - provides configuration for integrating FastAPI applications with the Model Context Protocol
12
12
  - `set_fastapi_mcp()` method in `src/veris_ai/tool_mock.py:54` - configures FastAPI MCP server with automatic OAuth2-based session management
13
13
  - Logging utilities in `src/veris_ai/logging.py` - provide async and sync functions for logging tool calls and responses to VERIS endpoints
14
+ - `SimulatorAPIClient` class in `src/veris_ai/api_client.py` - centralized client for making requests to VERIS simulation endpoints with automatic authentication
14
15
 
15
16
  ## Development Commands
16
17
 
@@ -18,12 +19,18 @@ This project uses `uv` as the package manager and follows modern Python tooling
18
19
 
19
20
  ### Setup
20
21
  ```bash
22
+ # Install base package
23
+ uv add veris-ai
24
+
21
25
  # Install with development dependencies
22
26
  uv add "veris-ai[dev]"
23
27
 
24
28
  # Install with FastAPI MCP integration
25
29
  uv add "veris-ai[fastapi]"
26
30
 
31
+ # Install with all extras
32
+ uv add "veris-ai[dev,fastapi,observability,agents]"
33
+
27
34
  # Set Python version (requires 3.11+)
28
35
  pyenv local 3.11.0
29
36
  ```
@@ -75,10 +82,12 @@ uv build
75
82
  - Main SDK class that provides decorator functionality:
76
83
  - `@veris.mock()`: Dynamic mocking that calls external endpoints for responses
77
84
  - `@veris.stub()`: Simple stubbing with fixed return values
78
- - Environment detection: Uses `ENV` environment variable to determine simulation vs production mode
85
+ - `@veris.spy()`: Logging decorator that executes original function and logs the call/response
86
+ - Session-based activation: Uses session ID presence to determine mocking behavior
79
87
  - HTTP communication with mock endpoints via `httpx` (for mock decorator)
80
88
  - Context extraction for session management via context variables
81
89
  - Delegates type conversion to the utils module
90
+ - Automatic API endpoint configuration with production defaults
82
91
 
83
92
  **API Surface** (`src/veris_ai/__init__.py:5`)
84
93
  - Exports single `veris` instance for public use
@@ -101,10 +110,18 @@ uv build
101
110
 
102
111
  ### Environment Configuration
103
112
 
104
- Required environment variables:
105
- - `VERIS_ENDPOINT_URL`: Base endpoint URL (required)
106
- - `VERIS_MOCK_TIMEOUT`: Request timeout in seconds (optional, default: 30.0)
107
- - `ENV`: Set to "simulation" to enable mocking, anything else runs original functions
113
+ Environment variables:
114
+ - `VERIS_API_KEY`: API authentication key for VERIS services (optional, but recommended for production)
115
+ - `VERIS_MOCK_TIMEOUT`: Request timeout in seconds (optional, default: 90.0)
116
+
117
+ **Note**: The SDK automatically connects to the production VERIS API endpoint (`https://simulation.api.veris.ai/`). Only override `VERIS_API_URL` if you need to use a custom endpoint (rarely needed).
118
+
119
+ ### Session-Based Activation
120
+
121
+ The SDK activates mocking based on session ID presence:
122
+ - **With session ID**: Routes calls to mock/simulator endpoint
123
+ - **Without session ID**: Executes original function
124
+ - Session IDs can be set manually via `veris.set_session_id()` or extracted automatically from OAuth2 tokens in FastAPI MCP integration
108
125
 
109
126
  ### Type System
110
127
 
@@ -123,8 +140,8 @@ The SDK handles sophisticated type conversion from mock responses:
123
140
 
124
141
  **Key Test Fixtures**:
125
142
  - `mock_context`: Provides mock context with session ID
126
- - `simulation_env`: Sets up simulation environment variables
127
- - `production_env`: Sets up production environment variables
143
+ - `simulation_env`: Sets up simulation mode with session ID
144
+ - `production_env`: Sets up production mode without session ID
128
145
 
129
146
  **Test Coverage Areas**:
130
147
  - Environment-based behavior switching
@@ -164,9 +181,14 @@ The SDK handles sophisticated type conversion from mock responses:
164
181
  ## Key Implementation Details
165
182
 
166
183
  - **Decorator Pattern**: Functions are wrapped to intercept calls in simulation mode
167
- - `mock()`: Sends function metadata to external endpoint for dynamic responses
168
- - `stub()`: Returns predetermined values without external calls
184
+ - `@veris.mock()`: Sends function metadata to external endpoint for dynamic responses
185
+ - `@veris.stub()`: Returns predetermined values without external calls
186
+ - `@veris.spy()`: Executes original function while logging calls and responses
169
187
  - **Session Management**: Extracts session ID from context for request correlation
188
+ - **API Client**: Centralized `SimulatorAPIClient` handles all API communication
189
+ - Automatic endpoint configuration with production defaults
190
+ - Built-in authentication via `VERIS_API_KEY` header
191
+ - Configurable timeout with `VERIS_MOCK_TIMEOUT`
170
192
  - **Error Handling**: Comprehensive HTTP and type conversion error handling
171
193
  - **Async Support**: Built with async/await pattern throughout
172
194
  - **Type Safety**: Full type hints and runtime type conversion validation
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: veris-ai
3
- Version: 1.8.2
3
+ Version: 1.10.0
4
4
  Summary: A Python package for Veris AI tools
5
5
  Project-URL: Homepage, https://github.com/veris-ai/veris-python-sdk
6
6
  Project-URL: Bug Tracker, https://github.com/veris-ai/veris-python-sdk/issues
@@ -20,6 +20,7 @@ Requires-Dist: opentelemetry-instrumentation>=0.55b1
20
20
  Requires-Dist: opentelemetry-sdk>=1.34.1
21
21
  Requires-Dist: pydantic>=2.0.0
22
22
  Requires-Dist: requests>=2.31.0
23
+ Requires-Dist: tenacity>=9.1.2
23
24
  Provides-Extra: agents
24
25
  Requires-Dist: openai-agents>=0.0.1; extra == 'agents'
25
26
  Provides-Extra: dev
@@ -47,7 +48,7 @@ A Python package for Veris AI tools with simulation capabilities and FastAPI MCP
47
48
  ## Quick Reference
48
49
 
49
50
  **Purpose**: Tool mocking, tracing, and FastAPI MCP integration for AI agent development
50
- **Core Components**: [`tool_mock`](#function-mocking) • [`api_client`](src/veris_ai/api_client.py) • [`observability`](#sdk-observability-helpers) • [`fastapi_mcp`](#fastapi-mcp-integration) • [`jaeger_interface`](#jaeger-trace-interface)
51
+ **Core Components**: [`tool_mock`](#function-mocking) • [`api_client`](src/veris_ai/api_client.py) • [`observability`](#sdk-observability-helpers) • [`agents_wrapper`](#openai-agents-integration) • [`fastapi_mcp`](#fastapi-mcp-integration) • [`jaeger_interface`](#jaeger-trace-interface)
51
52
  **Deep Dive**: [`Module Architecture`](src/veris_ai/README.md) • [`Testing Guide`](tests/README.md) • [`Usage Examples`](examples/README.md)
52
53
  **Source of Truth**: Implementation details in [`src/veris_ai/`](src/veris_ai/) source code
53
54
 
@@ -58,13 +59,14 @@ A Python package for Veris AI tools with simulation capabilities and FastAPI MCP
58
59
  uv add veris-ai
59
60
 
60
61
  # With optional extras
61
- uv add "veris-ai[dev,fastapi,instrument]"
62
+ uv add "veris-ai[dev,fastapi,observability,agents]"
62
63
  ```
63
64
 
64
65
  **Installation Profiles**:
65
66
  - `dev`: Development tools (ruff, pytest, mypy)
66
67
  - `fastapi`: FastAPI MCP integration
67
68
  - `observability`: OpenTelemetry tracing
69
+ - `agents`: OpenAI agents integration
68
70
 
69
71
  ## Import Patterns
70
72
 
@@ -75,10 +77,11 @@ uv add "veris-ai[dev,fastapi,instrument]"
75
77
  from veris_ai import veris, JaegerClient
76
78
 
77
79
  # Optional features (require extras)
78
- from veris_ai import init_observability, instrument_fastapi_app # Provided by SDK observability helpers
80
+ from veris_ai import init_observability, instrument_fastapi_app # Requires observability extras
81
+ from veris_ai import Runner, VerisConfig # Requires agents extras
79
82
  ```
80
83
 
81
- **Complete Import Strategies**: See [`examples/README.md`](examples/README.md) for five different import approaches, conditional features, and integration patterns.
84
+ **Complete Import Strategies**: See [`examples/README.md`](examples/README.md) for different import approaches, conditional features, and integration patterns.
82
85
 
83
86
  ## Configuration
84
87
 
@@ -88,7 +91,6 @@ from veris_ai import init_observability, instrument_fastapi_app # Provided by S
88
91
  |----------|---------|---------|
89
92
  | `VERIS_API_KEY` | API authentication key | None |
90
93
  | `VERIS_MOCK_TIMEOUT` | Request timeout (seconds) | `90.0` |
91
- | `ENV` | Set to `"simulation"` for mock mode | Production |
92
94
 
93
95
  **Advanced Configuration** (rarely needed):
94
96
  - `VERIS_API_URL`: Override default API endpoint (defaults to production)
@@ -156,32 +158,161 @@ End-to-end propagation with the simulator:
156
158
 
157
159
  **Semantic Tag**: `tool-mocking`
158
160
 
161
+ ### Session-Based Activation
162
+
163
+ The SDK uses session-based activation to determine when to enable mocking. Choose one of these methods to set a session ID:
164
+
165
+ **Option 1: Manual Setting**
166
+ ```python
167
+ from veris_ai import veris
168
+
169
+ # Explicitly set a session ID
170
+ veris.set_session_id("your-session-id")
171
+
172
+ # Now decorated functions will use mock responses
173
+ result = await your_mocked_function()
174
+
175
+ # Clear session to disable mocking
176
+ veris.clear_session_id()
177
+ ```
178
+
179
+ **Option 2: Automatic Extraction (FastAPI MCP)**
180
+ ```python
181
+ # When using FastAPI MCP integration, session IDs are
182
+ # automatically extracted from OAuth2 bearer tokens
183
+ veris.set_fastapi_mcp(...)
184
+ # No manual session management needed
185
+ ```
186
+
187
+ **How it works internally**: Regardless of which method you use, session IDs are stored in Python context variables (`contextvars`). This ensures proper isolation between concurrent requests and automatic propagation through the call stack.
188
+
159
189
  ### Core Decorators
160
190
 
161
191
  ```python
162
192
  from veris_ai import veris
163
193
 
164
- # Mock mode: Returns simulated responses in ENV=simulation
194
+ # Mock decorator: Returns simulated responses when session ID is set
165
195
  @veris.mock()
166
196
  async def your_function(param1: str, param2: int) -> dict:
167
197
  """Function documentation for LLM context."""
168
198
  return {"result": "actual implementation"}
169
199
 
170
- # Spy mode: Executes function but logs calls/responses
200
+ # Spy decorator: Executes function and logs calls/responses
171
201
  @veris.spy()
172
202
  async def monitored_function(data: str) -> dict:
173
203
  return process_data(data)
174
204
 
175
- # Stub mode: Returns fixed value in simulation
205
+ # Stub decorator: Returns fixed value in simulation
176
206
  @veris.stub(return_value={"status": "success"})
177
207
  async def get_data() -> dict:
178
208
  return await fetch_from_api()
179
209
  ```
180
210
 
181
- **Behavior**: In simulation mode, decorators intercept calls to mock endpoints. In production, functions execute normally.
211
+ **Behavior**: When a session ID is set, decorators activate their respective behaviors (mock responses, logging, or stubbed values). Without a session ID, functions execute normally.
182
212
 
183
213
  **Implementation**: See [`src/veris_ai/tool_mock.py`](src/veris_ai/tool_mock.py) for decorator logic and API integration.
184
214
 
215
+ ## OpenAI Agents Integration
216
+
217
+ **Semantic Tag**: `openai-agents`
218
+
219
+ The SDK provides seamless integration with [OpenAI's agents library](https://github.com/openai/agents) through the `Runner` class, which extends OpenAI's Runner to intercept tool calls and route them through Veris's mocking infrastructure.
220
+
221
+ ### Installation
222
+
223
+ ```bash
224
+ # Install with agents support
225
+ uv add "veris-ai[agents]"
226
+ ```
227
+
228
+ ### Basic Usage
229
+
230
+ ```python
231
+ from veris_ai import veris, Runner, VerisConfig
232
+ from agents import Agent, function_tool
233
+
234
+ # Define your tools
235
+ @function_tool
236
+ def calculator(x: int, y: int, operation: str = "add") -> int:
237
+ """Performs arithmetic operations."""
238
+ # ... implementation ...
239
+
240
+ # Create an agent with tools
241
+ agent = Agent(
242
+ name="Assistant",
243
+ model="gpt-4",
244
+ tools=[calculator],
245
+ instructions="You are a helpful assistant.",
246
+ )
247
+
248
+ # Use Veris Runner instead of OpenAI's Runner
249
+ result = await Runner.run(agent, "Calculate 10 + 5")
250
+
251
+ # Or with configuration
252
+ config = VerisConfig(include_tools=["calculator"])
253
+ result = await Runner.run(agent, "Calculate 10 + 5", veris_config=config)
254
+ ```
255
+
256
+ ### Selective Tool Interception
257
+
258
+ Control which tools are intercepted using VerisConfig:
259
+
260
+ ```python
261
+ from veris_ai import Runner, VerisConfig
262
+
263
+ # Only intercept specific tools
264
+ config = VerisConfig(include_tools=["calculator", "search_web"])
265
+ result = await Runner.run(agent, "Process this", veris_config=config)
266
+
267
+ # Or exclude specific tools from interception
268
+ config = VerisConfig(exclude_tools=["get_weather"])
269
+ result = await Runner.run(agent, "Check weather", veris_config=config)
270
+ ```
271
+
272
+ ### Advanced Tool Configuration
273
+
274
+ Fine-tune individual tool behavior using `ToolCallOptions`:
275
+
276
+ ```python
277
+ from veris_ai import Runner, VerisConfig, ResponseExpectation, ToolCallOptions
278
+
279
+ # Configure specific tool behaviors
280
+ config = VerisConfig(
281
+ tool_options={
282
+ "calculator": ToolCallOptions(
283
+ response_expectation=ResponseExpectation.REQUIRED, # Always expect response
284
+ cache_response=True, # Cache responses for identical calls
285
+ mode="tool" # Use tool mode (default)
286
+ ),
287
+ "search_web": ToolCallOptions(
288
+ response_expectation=ResponseExpectation.NONE, # Don't wait for response
289
+ cache_response=False,
290
+ mode="spy" # Log calls but execute normally
291
+ )
292
+ }
293
+ )
294
+
295
+ result = await Runner.run(agent, "Calculate and search", veris_config=config)
296
+ ```
297
+
298
+ **ToolCallOptions Parameters**:
299
+ - `response_expectation`: Control response behavior
300
+ - `AUTO` (default): Automatically determine based on context
301
+ - `REQUIRED`: Always wait for mock response
302
+ - `NONE`: Don't wait for response
303
+ - `cache_response`: Cache responses for identical tool calls
304
+ - `mode`: Tool execution mode
305
+ - `"tool"` (default): Standard tool execution
306
+ - `"function"`: Function mode
307
+
308
+ **Key Features**:
309
+ - **Drop-in replacement**: Use `Runner` from veris_ai instead of OpenAI's Runner
310
+ - **Extends OpenAI Runner**: Inherits all functionality while adding Veris capabilities
311
+ - **Automatic session management**: Integrates with Veris session IDs
312
+ - **Selective mocking**: Include or exclude specific tools from interception
313
+
314
+ **Implementation**: See [`src/veris_ai/agents_wrapper.py`](src/veris_ai/agents_wrapper.py) for the integration logic and [`examples/openai_agents_example.py`](examples/openai_agents_example.py) for complete examples.
315
+
185
316
  ## FastAPI MCP Integration
186
317
 
187
318
  **Semantic Tag**: `fastapi-mcp`
@@ -254,7 +385,7 @@ pytest --cov=veris_ai # Test with coverage
254
385
 
255
386
  **Semantic Tag**: `module-architecture`
256
387
 
257
- **Core Modules**: `tool_mock` (mocking), `api_client` (centralized API), `jaeger_interface` (trace queries), `utils` (schema conversion)
388
+ **Core Modules**: `tool_mock` (mocking), `api_client` (centralized API), `agents_wrapper` (OpenAI agents integration), `jaeger_interface` (trace queries), `utils` (schema conversion)
258
389
 
259
390
  **Complete Architecture**: See [`src/veris_ai/README.md`](src/veris_ai/README.md) for module overview, implementation flows, and configuration details.
260
391
 
@@ -5,7 +5,7 @@ A Python package for Veris AI tools with simulation capabilities and FastAPI MCP
5
5
  ## Quick Reference
6
6
 
7
7
  **Purpose**: Tool mocking, tracing, and FastAPI MCP integration for AI agent development
8
- **Core Components**: [`tool_mock`](#function-mocking) • [`api_client`](src/veris_ai/api_client.py) • [`observability`](#sdk-observability-helpers) • [`fastapi_mcp`](#fastapi-mcp-integration) • [`jaeger_interface`](#jaeger-trace-interface)
8
+ **Core Components**: [`tool_mock`](#function-mocking) • [`api_client`](src/veris_ai/api_client.py) • [`observability`](#sdk-observability-helpers) • [`agents_wrapper`](#openai-agents-integration) • [`fastapi_mcp`](#fastapi-mcp-integration) • [`jaeger_interface`](#jaeger-trace-interface)
9
9
  **Deep Dive**: [`Module Architecture`](src/veris_ai/README.md) • [`Testing Guide`](tests/README.md) • [`Usage Examples`](examples/README.md)
10
10
  **Source of Truth**: Implementation details in [`src/veris_ai/`](src/veris_ai/) source code
11
11
 
@@ -16,13 +16,14 @@ A Python package for Veris AI tools with simulation capabilities and FastAPI MCP
16
16
  uv add veris-ai
17
17
 
18
18
  # With optional extras
19
- uv add "veris-ai[dev,fastapi,instrument]"
19
+ uv add "veris-ai[dev,fastapi,observability,agents]"
20
20
  ```
21
21
 
22
22
  **Installation Profiles**:
23
23
  - `dev`: Development tools (ruff, pytest, mypy)
24
24
  - `fastapi`: FastAPI MCP integration
25
25
  - `observability`: OpenTelemetry tracing
26
+ - `agents`: OpenAI agents integration
26
27
 
27
28
  ## Import Patterns
28
29
 
@@ -33,10 +34,11 @@ uv add "veris-ai[dev,fastapi,instrument]"
33
34
  from veris_ai import veris, JaegerClient
34
35
 
35
36
  # Optional features (require extras)
36
- from veris_ai import init_observability, instrument_fastapi_app # Provided by SDK observability helpers
37
+ from veris_ai import init_observability, instrument_fastapi_app # Requires observability extras
38
+ from veris_ai import Runner, VerisConfig # Requires agents extras
37
39
  ```
38
40
 
39
- **Complete Import Strategies**: See [`examples/README.md`](examples/README.md) for five different import approaches, conditional features, and integration patterns.
41
+ **Complete Import Strategies**: See [`examples/README.md`](examples/README.md) for different import approaches, conditional features, and integration patterns.
40
42
 
41
43
  ## Configuration
42
44
 
@@ -46,7 +48,6 @@ from veris_ai import init_observability, instrument_fastapi_app # Provided by S
46
48
  |----------|---------|---------|
47
49
  | `VERIS_API_KEY` | API authentication key | None |
48
50
  | `VERIS_MOCK_TIMEOUT` | Request timeout (seconds) | `90.0` |
49
- | `ENV` | Set to `"simulation"` for mock mode | Production |
50
51
 
51
52
  **Advanced Configuration** (rarely needed):
52
53
  - `VERIS_API_URL`: Override default API endpoint (defaults to production)
@@ -114,32 +115,161 @@ End-to-end propagation with the simulator:
114
115
 
115
116
  **Semantic Tag**: `tool-mocking`
116
117
 
118
+ ### Session-Based Activation
119
+
120
+ The SDK uses session-based activation to determine when to enable mocking. Choose one of these methods to set a session ID:
121
+
122
+ **Option 1: Manual Setting**
123
+ ```python
124
+ from veris_ai import veris
125
+
126
+ # Explicitly set a session ID
127
+ veris.set_session_id("your-session-id")
128
+
129
+ # Now decorated functions will use mock responses
130
+ result = await your_mocked_function()
131
+
132
+ # Clear session to disable mocking
133
+ veris.clear_session_id()
134
+ ```
135
+
136
+ **Option 2: Automatic Extraction (FastAPI MCP)**
137
+ ```python
138
+ # When using FastAPI MCP integration, session IDs are
139
+ # automatically extracted from OAuth2 bearer tokens
140
+ veris.set_fastapi_mcp(...)
141
+ # No manual session management needed
142
+ ```
143
+
144
+ **How it works internally**: Regardless of which method you use, session IDs are stored in Python context variables (`contextvars`). This ensures proper isolation between concurrent requests and automatic propagation through the call stack.
145
+
117
146
  ### Core Decorators
118
147
 
119
148
  ```python
120
149
  from veris_ai import veris
121
150
 
122
- # Mock mode: Returns simulated responses in ENV=simulation
151
+ # Mock decorator: Returns simulated responses when session ID is set
123
152
  @veris.mock()
124
153
  async def your_function(param1: str, param2: int) -> dict:
125
154
  """Function documentation for LLM context."""
126
155
  return {"result": "actual implementation"}
127
156
 
128
- # Spy mode: Executes function but logs calls/responses
157
+ # Spy decorator: Executes function and logs calls/responses
129
158
  @veris.spy()
130
159
  async def monitored_function(data: str) -> dict:
131
160
  return process_data(data)
132
161
 
133
- # Stub mode: Returns fixed value in simulation
162
+ # Stub decorator: Returns fixed value in simulation
134
163
  @veris.stub(return_value={"status": "success"})
135
164
  async def get_data() -> dict:
136
165
  return await fetch_from_api()
137
166
  ```
138
167
 
139
- **Behavior**: In simulation mode, decorators intercept calls to mock endpoints. In production, functions execute normally.
168
+ **Behavior**: When a session ID is set, decorators activate their respective behaviors (mock responses, logging, or stubbed values). Without a session ID, functions execute normally.
140
169
 
141
170
  **Implementation**: See [`src/veris_ai/tool_mock.py`](src/veris_ai/tool_mock.py) for decorator logic and API integration.
142
171
 
172
+ ## OpenAI Agents Integration
173
+
174
+ **Semantic Tag**: `openai-agents`
175
+
176
+ The SDK provides seamless integration with [OpenAI's agents library](https://github.com/openai/agents) through the `Runner` class, which extends OpenAI's Runner to intercept tool calls and route them through Veris's mocking infrastructure.
177
+
178
+ ### Installation
179
+
180
+ ```bash
181
+ # Install with agents support
182
+ uv add "veris-ai[agents]"
183
+ ```
184
+
185
+ ### Basic Usage
186
+
187
+ ```python
188
+ from veris_ai import veris, Runner, VerisConfig
189
+ from agents import Agent, function_tool
190
+
191
+ # Define your tools
192
+ @function_tool
193
+ def calculator(x: int, y: int, operation: str = "add") -> int:
194
+ """Performs arithmetic operations."""
195
+ # ... implementation ...
196
+
197
+ # Create an agent with tools
198
+ agent = Agent(
199
+ name="Assistant",
200
+ model="gpt-4",
201
+ tools=[calculator],
202
+ instructions="You are a helpful assistant.",
203
+ )
204
+
205
+ # Use Veris Runner instead of OpenAI's Runner
206
+ result = await Runner.run(agent, "Calculate 10 + 5")
207
+
208
+ # Or with configuration
209
+ config = VerisConfig(include_tools=["calculator"])
210
+ result = await Runner.run(agent, "Calculate 10 + 5", veris_config=config)
211
+ ```
212
+
213
+ ### Selective Tool Interception
214
+
215
+ Control which tools are intercepted using VerisConfig:
216
+
217
+ ```python
218
+ from veris_ai import Runner, VerisConfig
219
+
220
+ # Only intercept specific tools
221
+ config = VerisConfig(include_tools=["calculator", "search_web"])
222
+ result = await Runner.run(agent, "Process this", veris_config=config)
223
+
224
+ # Or exclude specific tools from interception
225
+ config = VerisConfig(exclude_tools=["get_weather"])
226
+ result = await Runner.run(agent, "Check weather", veris_config=config)
227
+ ```
228
+
229
+ ### Advanced Tool Configuration
230
+
231
+ Fine-tune individual tool behavior using `ToolCallOptions`:
232
+
233
+ ```python
234
+ from veris_ai import Runner, VerisConfig, ResponseExpectation, ToolCallOptions
235
+
236
+ # Configure specific tool behaviors
237
+ config = VerisConfig(
238
+ tool_options={
239
+ "calculator": ToolCallOptions(
240
+ response_expectation=ResponseExpectation.REQUIRED, # Always expect response
241
+ cache_response=True, # Cache responses for identical calls
242
+ mode="tool" # Use tool mode (default)
243
+ ),
244
+ "search_web": ToolCallOptions(
245
+ response_expectation=ResponseExpectation.NONE, # Don't wait for response
246
+ cache_response=False,
247
+ mode="spy" # Log calls but execute normally
248
+ )
249
+ }
250
+ )
251
+
252
+ result = await Runner.run(agent, "Calculate and search", veris_config=config)
253
+ ```
254
+
255
+ **ToolCallOptions Parameters**:
256
+ - `response_expectation`: Control response behavior
257
+ - `AUTO` (default): Automatically determine based on context
258
+ - `REQUIRED`: Always wait for mock response
259
+ - `NONE`: Don't wait for response
260
+ - `cache_response`: Cache responses for identical tool calls
261
+ - `mode`: Tool execution mode
262
+ - `"tool"` (default): Standard tool execution
263
+ - `"function"`: Function mode
264
+
265
+ **Key Features**:
266
+ - **Drop-in replacement**: Use `Runner` from veris_ai instead of OpenAI's Runner
267
+ - **Extends OpenAI Runner**: Inherits all functionality while adding Veris capabilities
268
+ - **Automatic session management**: Integrates with Veris session IDs
269
+ - **Selective mocking**: Include or exclude specific tools from interception
270
+
271
+ **Implementation**: See [`src/veris_ai/agents_wrapper.py`](src/veris_ai/agents_wrapper.py) for the integration logic and [`examples/openai_agents_example.py`](examples/openai_agents_example.py) for complete examples.
272
+
143
273
  ## FastAPI MCP Integration
144
274
 
145
275
  **Semantic Tag**: `fastapi-mcp`
@@ -212,7 +342,7 @@ pytest --cov=veris_ai # Test with coverage
212
342
 
213
343
  **Semantic Tag**: `module-architecture`
214
344
 
215
- **Core Modules**: `tool_mock` (mocking), `api_client` (centralized API), `jaeger_interface` (trace queries), `utils` (schema conversion)
345
+ **Core Modules**: `tool_mock` (mocking), `api_client` (centralized API), `agents_wrapper` (OpenAI agents integration), `jaeger_interface` (trace queries), `utils` (schema conversion)
216
346
 
217
347
  **Complete Architecture**: See [`src/veris_ai/README.md`](src/veris_ai/README.md) for module overview, implementation flows, and configuration details.
218
348
 
@@ -63,9 +63,9 @@ if os.getenv("USE_FASTAPI") == "true":
63
63
  **Semantic Tag**: `integration-patterns`
64
64
 
65
65
  ### Decorator Usage
66
- - **Function Mocking**: `@veris.mock()` for simulation mode
67
- - **Spy Mode**: `@veris.spy()` for logging
68
- - **Stub Mode**: `@veris.stub(return_value={})` for fixed responses
66
+ - **Mock Decorator**: `@veris.mock()` for simulation mode
67
+ - **Spy Decorator**: `@veris.spy()` for logging calls and responses
68
+ - **Stub Decorator**: `@veris.stub(return_value={})` for fixed responses
69
69
 
70
70
  ### Error Handling
71
71
  - **Graceful Import Failures**: Try/catch blocks for optional features
@@ -73,7 +73,8 @@ if os.getenv("USE_FASTAPI") == "true":
73
73
  - **Feature Detection**: Runtime capability checking
74
74
 
75
75
  ### Configuration Management
76
- - **Environment Variables**: `VERIS_ENDPOINT_URL`, `ENV=simulation`
76
+ - **Environment Variables**: `VERIS_API_KEY` for authentication, `VERIS_MOCK_TIMEOUT` for request timeout
77
+ - **Session Management**: Use `veris.set_session_id()` to enable mocking
77
78
  - **Conditional Setup**: Feature flags for optional components
78
79
  - **Service Configuration**: Dynamic service naming and endpoints
79
80
 
@@ -86,13 +87,15 @@ if os.getenv("USE_FASTAPI") == "true":
86
87
  cd examples/
87
88
  python import_options.py
88
89
 
89
- # With specific environment setup
90
- ENV=simulation VERIS_ENDPOINT_URL=http://localhost:8000 python import_options.py
90
+ # With API key for production
91
+ VERIS_API_KEY=your-api-key python import_options.py
91
92
 
92
93
  # Testing with different feature flags
93
94
  ENABLE_TRACING=true USE_FASTAPI=true python import_options.py
94
95
  ```
95
96
 
97
+ **Note**: To enable mocking in your code, call `veris.set_session_id("your-session-id")`.
98
+
96
99
  w### Observability Environment (optional)
97
100
 
98
101
  If you want traces exported while running examples, set the following before execution: