|
1 | | -# Pydantic AI Sentry Integration Tests |
| 1 | +# Pydantic AI Testing Suite |
2 | 2 |
|
3 | | -Clean, focused tests for the Sentry Pydantic AI integration. |
| 3 | +Comprehensive testing suite for Pydantic AI integration with Sentry. |
4 | 4 |
|
5 | | -## Prerequisites |
| 5 | +## Agent Types |
6 | 6 |
|
7 | | -You need to have Python and `curl` installed. |
| 7 | +1. **Customer Support Agent** - Single tool with structured context data |
| 8 | +2. **Math Agent** - Multiple calculation tools |
| 9 | +3. **MCP Agent** - Connects to MCP server via stdio transport |
8 | 10 |
|
9 | | -## Configure |
| 11 | +## Models Tested |
10 | 12 |
|
11 | | -Set the following environment variables: |
12 | | -- `SENTRY_DSN` |
13 | | -- `OPENAI_API_KEY` |
14 | | -- `ANTHROPIC_API_KEY` (for Anthropic provider tests) |
15 | | - |
16 | | -## Run Tests |
17 | | - |
18 | | -### Synchronous Tests |
19 | | -```bash |
20 | | -./run.sh |
21 | | -``` |
22 | | - |
23 | | -### Asynchronous Tests |
24 | | -```bash |
25 | | -./run_async.sh |
26 | | -``` |
27 | | - |
28 | | -## Test Structure |
29 | | - |
30 | | -The tests are organized into three main scenarios, each tested in both sync/async and streaming/non-streaming modes: |
31 | | - |
32 | | -### 1. **Simple Agent** |
33 | | -- Basic agent without tools |
34 | | -- Tests fundamental agent functionality |
35 | | -- Demonstrates simple Q&A interactions |
36 | | - |
37 | | -### 2. **Agent with Tools** |
38 | | -- Mathematical agent with calculation tools |
39 | | -- Tools: `add()`, `multiply()`, `calculate_percentage()` |
40 | | -- Tests tool integration and structured output |
41 | | -- Returns `CalculationResult` with explanation |
42 | | - |
43 | | -### 3. **Two-Agent Workflow** |
44 | | -- **Data Collector Agent**: Extracts and organizes data |
45 | | -- **Data Analyzer Agent**: Analyzes data and provides insights |
46 | | -- Demonstrates agent handoff and workflow patterns |
47 | | -- Returns `AnalysisResult` with findings and recommendations |
48 | | - |
49 | | -### 4. **Anthropic Provider Tests** |
50 | | -- **Anthropic Simple Agent**: Basic Claude agent without tools |
51 | | -- **Anthropic Math Agent**: Claude agent with calculation tools |
52 | | -- Tests both OpenAI and Anthropic providers for comparison |
53 | | -- Uses `anthropic:claude-3-5-haiku-20241022` model |
| 13 | +- OpenAI: `gpt-4o-mini` |
| 14 | +- Anthropic: `claude-3-5-haiku-20241022` |
54 | 15 |
|
55 | | -## Test Modes |
| 16 | +## Methods Tested |
56 | 17 |
|
57 | | -Each scenario is tested in four different modes: |
| 18 | +- `run_sync()` - Synchronous execution |
| 19 | +- `run()` - Async execution |
| 20 | +- `run_stream()` - Streaming responses |
| 21 | +- `iter()` - Structured streaming |
| 22 | +- `run_stream_events()` - Event streaming |
58 | 23 |
|
59 | | -| Mode | Sync/Async | Streaming | Description | |
60 | | -|------|------------|-----------|-------------| |
61 | | -| 1 | Sync | No | `agent.run_sync()` | |
62 | | -| 2 | Sync | Yes | `agent.run_stream_sync()` | |
63 | | -| 3 | Async | No | `await agent.run()` | |
64 | | -| 4 | Async | Yes | `async with agent.run_stream()` | |
65 | | - |
66 | | -## Additional Features |
67 | | - |
68 | | -### Parallel Processing (Async Only) |
69 | | -- Demonstrates running multiple agents concurrently |
70 | | -- Uses `asyncio.gather()` for parallel execution |
71 | | -- Shows scalable multi-agent patterns |
72 | | - |
73 | | -### Model Settings |
74 | | -All agents use optimized model settings: |
75 | | -- **Simple Agent**: Balanced settings (temp: 0.3) |
76 | | -- **Math Agent**: Low temperature for precision (temp: 0.1) |
77 | | -- **Data Collector**: Focused extraction (temp: 0.2) |
78 | | -- **Data Analyzer**: Creative analysis (temp: 0.4) |
79 | | -- **Anthropic Simple Agent**: Balanced settings (temp: 0.3) |
80 | | -- **Anthropic Math Agent**: Low temperature for precision (temp: 0.1) |
81 | | - |
82 | | -## Sentry Integration |
83 | | - |
84 | | -The integration automatically creates Sentry spans for: |
85 | | -- `gen_ai.pipeline` - Agent workflow execution (root span) |
86 | | -- `gen_ai.invoke_agent` - Individual agent invocations |
87 | | -- `gen_ai.chat` - Model requests (AI client calls) |
88 | | -- `gen_ai.execute_tool` - Tool executions |
89 | | - |
90 | | -## File Structure |
91 | | - |
92 | | -``` |
93 | | -test-pydantic-ai/ |
94 | | -├── agents.py # Agent definitions and tools |
95 | | -├── main.py # Synchronous tests |
96 | | -├── main_async.py # Asynchronous tests |
97 | | -├── run.sh # Run sync tests |
98 | | -├── run_async.sh # Run async tests |
99 | | -├── pyproject.toml # Dependencies |
100 | | -└── README.md # This file |
101 | | -``` |
102 | | - |
103 | | -## Output Example |
| 24 | +## Running Tests |
104 | 25 |
|
| 26 | +```bash |
| 27 | +./run.sh |
105 | 28 | ``` |
106 | | -🚀 Running Pydantic AI Synchronous Tests |
107 | | -================================================== |
108 | 29 |
|
109 | | -=== SIMPLE AGENT (Non-Streaming) === |
110 | | -Question: What is the capital of France? |
111 | | -Answer: The capital of France is Paris. |
112 | | -
|
113 | | -=== SIMPLE AGENT (Streaming) === |
114 | | -Question: Tell me a short story about a robot. |
115 | | -Answer (streaming): Once upon a time, a curious robot named Zara discovered... |
| 30 | +Set these environment variables: |
| 31 | +- `SENTRY_DSN` |
| 32 | +- `OPENAI_API_KEY` |
| 33 | +- `ANTHROPIC_API_KEY` |
116 | 34 |
|
117 | | -=== AGENT WITH TOOLS (Non-Streaming) === |
118 | | -Task: Multi-step calculation |
119 | | -Result: CalculationResult(result=126, operation='multi-step', explanation='...') |
| 35 | +## Test Matrix |
120 | 36 |
|
121 | | -=== TWO-AGENT WORKFLOW (Non-Streaming) === |
122 | | -Step 1: Data Collection |
123 | | -Data Collector Result: Extracted sales data: [150, 200, 175, 225] |
| 37 | +The test suite runs all combinations: |
| 38 | +- 3 agent types × 2 models × 5 methods = 30 tests |
124 | 39 |
|
125 | | -Step 2: Data Analysis |
126 | | -Data Analyzer Result: AnalysisResult(summary='...', key_findings=[...], recommendation='...') |
| 40 | +Each agent is created with a unique name like `openai_customer_support_run_sync` or `anthropic_mcp_agent_run` for easy identification in Sentry spans. |
127 | 41 |
|
128 | | -================================================== |
129 | | -✅ All synchronous tests completed! |
130 | | -``` |
| 42 | +## MCP Server |
131 | 43 |
|
132 | | -This clean structure focuses on the core functionality while thoroughly testing all aspects of the Pydantic AI integration with Sentry. |
| 44 | +The MCP agent connects to a simple MCP server (`mcp_server.py`) that runs via stdio transport and provides basic calculation and text analysis tools. |
0 commit comments