-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_helpers_demo.py
More file actions
executable file
Β·258 lines (209 loc) Β· 8.02 KB
/
test_helpers_demo.py
File metadata and controls
executable file
Β·258 lines (209 loc) Β· 8.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env python3
"""Test Helpers Demo - Using Pre-configured Test Agents.
This example shows how to use the built-in test helpers for quick testing and examples.
"""
from __future__ import annotations
import asyncio
from adcp.client import ADCPMultiAgentClient
from adcp.testing import (
create_test_agent,
test_agent,
test_agent_a2a,
test_agent_client,
test_agent_no_auth,
)
from adcp.types._generated import GetProductsRequest, ListCreativeFormatsRequest
async def simplest_example() -> None:
"""Example 1: Simplest Possible Usage.
Use the pre-configured test agent directly - no setup needed!
"""
print("π― Example 1: Simplest Usage with test_agent")
print("=" * 43)
print()
try:
# Just import and use - that's it!
result = await test_agent.get_products(
GetProductsRequest(
brief="Premium coffee subscription service",
promoted_offering="Artisan coffee deliveries",
)
)
if result.success and result.data:
print(f"β
Success! Found {len(result.data.products)} products")
print(" Protocol: MCP")
print()
else:
print(f"β Error: {result.error}")
print()
except Exception as e:
print(f"β Network error: {e}")
print()
async def protocol_comparison() -> None:
"""Example 2: Testing Both Protocols.
Use both A2A and MCP test agents to compare behavior.
"""
print("π Example 2: Protocol Comparison (A2A vs MCP)")
print("=" * 46)
print()
request = GetProductsRequest(
brief="Sustainable fashion brands",
promoted_offering="Eco-friendly clothing",
)
try:
print("Testing MCP protocol...")
mcp_result = await test_agent.get_products(request)
print(f" MCP: {'β
' if mcp_result.success else 'β'}")
print("Testing A2A protocol...")
a2a_result = await test_agent_a2a.get_products(request)
print(f" A2A: {'β
' if a2a_result.success else 'β'}")
print()
except Exception as e:
print(f"β Error: {e}")
print()
async def multi_agent_example() -> None:
"""Example 3: Multi-Agent Testing.
Use the test_agent_client for parallel operations.
"""
print("π Example 3: Multi-Agent Operations")
print("=" * 36)
print()
try:
print(f"Testing with {len(test_agent_client.agent_ids)} agents in parallel...")
# Run the same query on both agents in parallel
results = await test_agent_client.get_products(
GetProductsRequest(
brief="Tech gadgets for remote work",
promoted_offering="Ergonomic workspace solutions",
)
)
print("\nResults:")
for i, result in enumerate(results, 1):
print(f" {i}. {'β
' if result.success else 'β'}")
print()
except Exception as e:
print(f"β Error: {e}")
print()
async def custom_test_agent() -> None:
"""Example 4: Custom Test Agent Configuration.
Create a custom test agent with modifications.
"""
print("βοΈ Example 4: Custom Test Agent Configuration")
print("=" * 46)
print()
# Create a custom config with your own ID
custom_config = create_test_agent(
id="my-custom-test",
timeout=60.0,
)
print("Created custom config:")
print(f" ID: {custom_config.id}")
print(f" Protocol: {custom_config.protocol}")
print(f" URI: {custom_config.agent_uri}")
print(f" Timeout: {custom_config.timeout}s")
print()
# Use it with a client
client = ADCPMultiAgentClient([custom_config])
agent = client.agent("my-custom-test")
try:
result = await agent.get_products(
GetProductsRequest(
brief="Travel packages",
promoted_offering="European vacations",
)
)
print(f"Result: {'β
Success' if result.success else 'β Failed'}")
print()
except Exception as e:
print(f"β Error: {e}")
print()
finally:
await client.close()
async def auth_vs_no_auth_comparison() -> None:
"""Example 5: Authenticated vs Unauthenticated Requests.
Compare behavior between authenticated and unauthenticated test agents.
Useful for testing how agents handle different authentication states.
"""
print("π Example 5: Authentication Comparison")
print("=" * 39)
print()
request = GetProductsRequest(
brief="Coffee subscription service",
promoted_offering="Premium coffee",
)
try:
# Test with authentication
print("Testing WITH authentication (MCP)...")
auth_result = await test_agent.get_products(request)
auth_success = "β
" if auth_result.success else "β"
auth_count = len(auth_result.data.products) if auth_result.data else 0
print(f" {auth_success} With Auth: {auth_count} products")
# Test without authentication
print("Testing WITHOUT authentication (MCP)...")
no_auth_result = await test_agent_no_auth.get_products(request)
no_auth_success = "β
" if no_auth_result.success else "β"
no_auth_count = len(no_auth_result.data.products) if no_auth_result.data else 0
print(f" {no_auth_success} No Auth: {no_auth_count} products")
# Compare results
print()
if auth_count != no_auth_count:
print(" π‘ Note: Different results with/without auth!")
print(f" Auth returned {auth_count} products")
print(f" No auth returned {no_auth_count} products")
else:
print(" π‘ Note: Same results with/without auth")
print()
except Exception as e:
print(f"β Error: {e}")
print()
async def various_operations() -> None:
"""Example 6: Testing Different Operations.
Show various ADCP operations with test agents.
"""
print("π¬ Example 6: Various ADCP Operations")
print("=" * 37)
print()
try:
# Get products
print("1. Getting products...")
products = await test_agent.get_products(
GetProductsRequest(
brief="Coffee brands",
promoted_offering="Premium coffee",
)
)
success = "β
" if products.success else "β"
count = len(products.data.products) if products.data else 0
print(f" {success} Products: {count}")
# List creative formats
print("2. Listing creative formats...")
formats = await test_agent.list_creative_formats(ListCreativeFormatsRequest())
success = "β
" if formats.success else "β"
count = len(formats.data.formats) if formats.data else 0
print(f" {success} Formats: {count}")
print()
except Exception as e:
print(f"β Error: {e}")
print()
async def main() -> None:
"""Main function - run all examples."""
print("\nπ ADCP Test Helpers - Demo Examples")
print("=" * 37)
print("These examples show how to use pre-configured test agents\n")
await simplest_example()
await protocol_comparison()
await multi_agent_example()
await custom_test_agent()
await auth_vs_no_auth_comparison()
await various_operations()
print("π‘ Key Takeaways:")
print(" β’ test_agent = Pre-configured MCP test agent with auth")
print(" β’ test_agent_a2a = Pre-configured A2A test agent with auth")
print(" β’ test_agent_no_auth = Pre-configured MCP test agent WITHOUT auth")
print(" β’ test_agent_a2a_no_auth = Pre-configured A2A test agent WITHOUT auth")
print(" β’ test_agent_client = Multi-agent client with both protocols")
print(" β’ create_test_agent() = Create custom test configurations")
print(" β’ Perfect for examples, docs, and quick testing")
print("\nβ οΈ Remember: Test agents are rate-limited and for testing only!")
print(" DO NOT use in production applications.\n")
if __name__ == "__main__":
asyncio.run(main())