agent0-sdk 0.31__py3-none-any.whl → 1.0.0__py3-none-any.whl

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.
tests/test_sdk.py DELETED
@@ -1,240 +0,0 @@
1
- """
2
- Tests for SDK class.
3
- """
4
-
5
- import pytest
6
- from unittest.mock import Mock, patch
7
-
8
- from agent0_sdk.core.sdk import SDK
9
- from agent0_sdk.core.models import EndpointType, TrustModel
10
-
11
-
12
- class TestSDK:
13
- """Test SDK class."""
14
-
15
- def test_sdk_initialization(self):
16
- """Test SDK initialization."""
17
- with patch('agent0_sdk.core.sdk.Web3Client') as mock_web3:
18
- mock_web3.return_value.chain_id = 11155111
19
-
20
- sdk = SDK(
21
- chainId=11155111,
22
- signer="0x1234567890abcdef",
23
- rpcUrl="https://eth-sepolia.g.alchemy.com/v2/test"
24
- )
25
-
26
- assert sdk.chainId == 11155111
27
- assert sdk.rpcUrl == "https://eth-sepolia.g.alchemy.com/v2/test"
28
- mock_web3.assert_called_once()
29
-
30
- def test_create_agent(self):
31
- """Test agent creation."""
32
- with patch('agent0_sdk.core.sdk.Web3Client') as mock_web3:
33
- mock_web3.return_value.chain_id = 11155111
34
-
35
- sdk = SDK(
36
- chainId=11155111,
37
- signer="0x1234567890abcdef",
38
- rpcUrl="https://eth-sepolia.g.alchemy.com/v2/test"
39
- )
40
-
41
- agent = sdk.createAgent(
42
- name="Test Agent",
43
- description="A test agent",
44
- image="https://example.com/image.png"
45
- )
46
-
47
- assert agent.name == "Test Agent"
48
- assert agent.description == "A test agent"
49
- assert agent.image == "https://example.com/image.png"
50
- assert agent.sdk == sdk
51
-
52
- def test_registries(self):
53
- """Test registry resolution."""
54
- with patch('agent0_sdk.core.sdk.Web3Client') as mock_web3:
55
- mock_web3.return_value.chain_id = 11155111
56
-
57
- sdk = SDK(
58
- chainId=11155111,
59
- signer="0x1234567890abcdef",
60
- rpcUrl="https://eth-sepolia.g.alchemy.com/v2/test"
61
- )
62
-
63
- registries = sdk.registries()
64
- assert "IDENTITY" in registries
65
- assert "REPUTATION" in registries
66
- assert "VALIDATION" in registries
67
-
68
- def test_set_chain(self):
69
- """Test chain switching."""
70
- with patch('agent0_sdk.core.sdk.Web3Client') as mock_web3:
71
- mock_web3.return_value.chain_id = 11155111
72
-
73
- sdk = SDK(
74
- chainId=11155111,
75
- signer="0x1234567890abcdef",
76
- rpcUrl="https://eth-sepolia.g.alchemy.com/v2/test"
77
- )
78
-
79
- sdk.set_chain(84532) # Switch to Base Sepolia
80
- assert sdk.chainId == 84532
81
- assert sdk._registries["IDENTITY"] is not None # Should have Base Sepolia registry
82
-
83
-
84
- class TestAgent:
85
- """Test Agent class."""
86
-
87
- def test_agent_endpoint_management(self):
88
- """Test agent endpoint management."""
89
- with patch('agent0_sdk.core.sdk.Web3Client') as mock_web3:
90
- mock_web3.return_value.chain_id = 11155111
91
-
92
- sdk = SDK(
93
- chainId=11155111,
94
- signer="0x1234567890abcdef",
95
- rpcUrl="https://eth-sepolia.g.alchemy.com/v2/test"
96
- )
97
-
98
- agent = sdk.createAgent("Test Agent", "A test agent")
99
-
100
- # Add MCP endpoint
101
- agent.setMCP("https://mcp.example.com/")
102
- assert len(agent.endpoints) == 1
103
- assert agent.endpoints[0].type == EndpointType.MCP
104
- assert agent.endpoints[0].value == "https://mcp.example.com/"
105
- assert agent.endpoints[0].meta["version"] == "2025-06-18"
106
-
107
- # Add A2A endpoint
108
- agent.setA2A("https://a2a.example.com/", "1.0")
109
- assert len(agent.endpoints) == 2
110
-
111
- # Add ENS endpoint
112
- agent.setENS("test-agent.eth")
113
- assert len(agent.endpoints) == 3
114
- ens_endpoint = next(ep for ep in agent.endpoints if ep.type == EndpointType.ENS)
115
- assert ens_endpoint.value == "test-agent.eth"
116
- assert ens_endpoint.meta["version"] == "1.0"
117
-
118
- # Remove specific endpoint
119
- agent.removeEndpoint(EndpointType.MCP, "https://mcp.example.com/")
120
- assert len(agent.endpoints) == 2
121
- assert agent.endpoints[0].type == EndpointType.A2A
122
-
123
- # Remove all endpoints
124
- agent.removeEndpoints()
125
- assert len(agent.endpoints) == 0
126
-
127
- def test_agent_trust_models(self):
128
- """Test agent trust model management."""
129
- with patch('agent0_sdk.core.sdk.Web3Client') as mock_web3:
130
- mock_web3.return_value.chain_id = 11155111
131
-
132
- sdk = SDK(
133
- chainId=11155111,
134
- signer="0x1234567890abcdef",
135
- rpcUrl="https://eth-sepolia.g.alchemy.com/v2/test"
136
- )
137
-
138
- agent = sdk.createAgent("Test Agent", "A test agent")
139
-
140
- # Set trust models using new method
141
- agent.setTrust(reputation=True, cryptoEconomic=True)
142
- # Access trustModels through registration_file since property is shadowed by method
143
- assert len(agent.registration_file.trustModels) == 2
144
- assert TrustModel.REPUTATION in agent.registration_file.trustModels
145
- assert TrustModel.CRYPTO_ECONOMIC in agent.registration_file.trustModels
146
-
147
- # Set trust models using direct assignment (since trustModels is a property, not callable)
148
- agent.registration_file.trustModels = [TrustModel.REPUTATION, "custom_trust"]
149
- assert len(agent.registration_file.trustModels) == 2
150
- assert TrustModel.REPUTATION in agent.registration_file.trustModels
151
- assert "custom_trust" in agent.registration_file.trustModels
152
-
153
- def test_agent_metadata_management(self):
154
- """Test agent metadata management."""
155
- with patch('agent0_sdk.core.sdk.Web3Client') as mock_web3:
156
- mock_web3.return_value.chain_id = 11155111
157
-
158
- sdk = SDK(
159
- chainId=11155111,
160
- signer="0x1234567890abcdef",
161
- rpcUrl="https://eth-sepolia.g.alchemy.com/v2/test"
162
- )
163
-
164
- agent = sdk.createAgent("Test Agent", "A test agent")
165
-
166
- # Set metadata
167
- agent.setMetadata({"key1": "value1", "key2": "value2"})
168
- assert agent.getMetadata() == {"key1": "value1", "key2": "value2"}
169
-
170
- # Set single key using setMetadata
171
- agent.setMetadata({"key3": "value3"})
172
- assert agent.getMetadata() == {"key1": "value1", "key2": "value2", "key3": "value3"}
173
-
174
- # Delete key
175
- agent.delMetadata("key2")
176
- assert agent.getMetadata() == {"key1": "value1", "key3": "value3"}
177
-
178
- def test_agent_info_update(self):
179
- """Test agent info updates."""
180
- with patch('agent0_sdk.core.sdk.Web3Client') as mock_web3:
181
- mock_web3.return_value.chain_id = 11155111
182
-
183
- sdk = SDK(
184
- chainId=11155111,
185
- signer="0x1234567890abcdef",
186
- rpcUrl="https://eth-sepolia.g.alchemy.com/v2/test"
187
- )
188
-
189
- agent = sdk.createAgent("Test Agent", "A test agent")
190
-
191
- # Update info
192
- agent.updateInfo(
193
- name="Updated Agent",
194
- description="An updated agent",
195
- image="https://example.com/new-image.png"
196
- )
197
-
198
- assert agent.name == "Updated Agent"
199
- assert agent.description == "An updated agent"
200
- assert agent.image == "https://example.com/new-image.png"
201
-
202
- # Set wallet address (must be valid 42-character Ethereum address)
203
- valid_address = "0x1234567890abcdef1234567890abcdef12345678"
204
- agent.setAgentWallet(valid_address)
205
- assert agent.walletAddress == valid_address
206
-
207
- def test_agent_json_serialization(self):
208
- """Test agent JSON serialization."""
209
- with patch('agent0_sdk.core.sdk.Web3Client') as mock_web3:
210
- mock_web3.return_value.chain_id = 11155111
211
-
212
- sdk = SDK(
213
- chainId=11155111,
214
- signer="0x1234567890abcdef",
215
- rpcUrl="https://eth-sepolia.g.alchemy.com/v2/test"
216
- )
217
-
218
- agent = sdk.createAgent("Test Agent", "A test agent")
219
- agent.setMCP("https://mcp.example.com/")
220
- agent.setTrust(reputation=True)
221
-
222
- json_data = agent.toJson()
223
- assert isinstance(json_data, str)
224
- assert "Test Agent" in json_data
225
- assert "MCP" in json_data
226
- assert "reputation" in json_data
227
-
228
- # Test x402 support
229
- agent.setX402Support(True)
230
- assert agent.x402support is True
231
-
232
- json_data_with_x402 = agent.toJson()
233
- assert "x402support" in json_data_with_x402
234
-
235
- # Test active status
236
- agent.setActive(True)
237
- assert agent.active is True
238
-
239
- agent.setActive(False)
240
- assert agent.active is False
tests/test_search.py DELETED
@@ -1,415 +0,0 @@
1
- """
2
- Test for Agent Search and Discovery using Subgraph
3
- Tests various search and filtering capabilities for discovering agents and their reputation.
4
-
5
- Flow:
6
- 1. Get a specific agent by ID
7
- 2. Search agents by name (partial match)
8
- 3. Search agents by capabilities (MCP tools)
9
- 4. Search agents by skills (A2A)
10
- 5. Search agents by ENS domain
11
- 6. Search agents by active status
12
- 7. Combine multiple filters (capabilities + skills)
13
- 8. Search agents by reputation with minimum average score
14
- 9. Search agents by reputation with specific tags
15
- 10. Search agents by reputation with capability filtering
16
- 11. Advanced: Find top-rated agents with specific skills
17
- 12. Advanced: Find agents with multiple requirements
18
- 13. Pagination test
19
- 14. Sort by activity test
20
- 15. Search agents by single owner address
21
- 16. Search agents by multiple owner addresses
22
- 17. Search agents by operator addresses
23
- 18. Combined search: owner + active status
24
- 19. Combined search: owner + name filter
25
- """
26
-
27
- import logging
28
- import time
29
- import random
30
- import sys
31
-
32
- # Configure logging: root logger at WARNING to suppress noisy dependencies
33
- logging.basicConfig(
34
- level=logging.WARNING,
35
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
36
- datefmt='%Y-%m-%d %H:%M:%S',
37
- handlers=[logging.StreamHandler(sys.stdout)]
38
- )
39
-
40
- # Set debug level ONLY for agent0_sdk
41
- logging.getLogger('agent0_sdk').setLevel(logging.DEBUG)
42
- logging.getLogger('agent0_sdk.core').setLevel(logging.DEBUG)
43
-
44
- from agent0_sdk import SDK, SearchParams
45
- from config import CHAIN_ID, RPC_URL, AGENT_PRIVATE_KEY, SUBGRAPH_URL, AGENT_ID, print_config
46
-
47
-
48
- def main():
49
- print("🔍 Testing Agent Search and Discovery")
50
- print_config()
51
- print("=" * 60)
52
-
53
- # Initialize SDK without signer (read-only operations)
54
- sdk = SDK(
55
- chainId=CHAIN_ID,
56
- rpcUrl=RPC_URL
57
- )
58
-
59
- print(f"\n📍 Step 1: Get Agent by ID")
60
- print("-" * 60)
61
- try:
62
- agent = sdk.getAgent(AGENT_ID)
63
- print(f"✅ Agent found: {agent.name}")
64
- print(f" Description: {agent.description[:80] if agent.description else 'N/A'}...")
65
- print(f" Chain ID: {agent.chainId}")
66
- print(f" Active: {agent.active}")
67
- print(f" ENS: {agent.ens}")
68
- print(f" Agent ID: {agent.agentId}")
69
- # MCP and A2A support determined by endpoint presence
70
- if hasattr(agent, 'mcpEndpoint') and agent.mcpEndpoint:
71
- print(f" MCP: {agent.mcpEndpoint}")
72
- if hasattr(agent, 'a2aEndpoint') and agent.a2aEndpoint:
73
- print(f" A2A: {agent.a2aEndpoint}")
74
- except Exception as e:
75
- print(f"❌ Failed to get agent: {e}")
76
-
77
- print(f"\n📍 Step 2: Search Agents by Name (Partial Match)")
78
- print("-" * 60)
79
- try:
80
- results = sdk.searchAgents(name="Test")
81
- agents = results.get('items', [])
82
- print(f"✅ Found {len(agents)} agent(s) with name matching 'Test'")
83
- for i, agent in enumerate(agents[:3], 1):
84
- agent_id = agent.get('agentId', agent.get('id', 'N/A'))
85
- print(f" {i}. {agent['name']} (ID: {agent_id})")
86
- if agent.get('description'):
87
- print(f" {agent['description'][:60]}...")
88
- except Exception as e:
89
- print(f"❌ Failed to search by name: {e}")
90
-
91
- print(f"\n📍 Step 3: Search Agents by MCP Tools (Capabilities)")
92
- print("-" * 60)
93
- try:
94
- # Using capabilities from test_feedback.py: data_analysis, code_generation, natural_language_understanding, problem_solving, communication
95
- results = sdk.searchAgents(mcpTools=["data_analysis"])
96
- agents = results.get('items', [])
97
- print(f"✅ Found {len(agents)} agent(s) with 'data_analysis' capability")
98
- for i, agent in enumerate(agents[:3], 1):
99
- print(f" {i}. {agent['name']}")
100
- if agent.get('mcpTools'):
101
- print(f" Tools: {', '.join(agent['mcpTools'][:3])}...")
102
- except Exception as e:
103
- print(f"❌ Failed to search by capabilities: {e}")
104
-
105
- print(f"\n📍 Step 4: Search Agents by A2A Skills")
106
- print("-" * 60)
107
- try:
108
- # Using skills from test_feedback.py: python, javascript, machine_learning, web_development, cloud_computing
109
- results = sdk.searchAgents(a2aSkills=["javascript"])
110
- agents = results.get('items', [])
111
- print(f"✅ Found {len(agents)} agent(s) with 'javascript' skill")
112
- for i, agent in enumerate(agents[:3], 1):
113
- print(f" {i}. {agent['name']}")
114
- if agent.get('a2aSkills'):
115
- print(f" Skills: {', '.join(agent['a2aSkills'][:3])}...")
116
- except Exception as e:
117
- print(f"❌ Failed to search by skills: {e}")
118
-
119
- print(f"\n📍 Step 5: Search Agents by ENS Domain")
120
- print("-" * 60)
121
- try:
122
- results = sdk.searchAgents(ens="test")
123
- agents = results.get('items', [])
124
- print(f"✅ Found {len(agents)} agent(s) with ENS matching 'test'")
125
- for i, agent in enumerate(agents[:3], 1):
126
- print(f" {i}. {agent['name']}")
127
- if agent.get('ens'):
128
- print(f" ENS: {agent['ens']}")
129
- except Exception as e:
130
- print(f"❌ Failed to search by ENS: {e}")
131
-
132
- print(f"\n📍 Step 6: Search Only Active Agents")
133
- print("-" * 60)
134
- try:
135
- results = sdk.searchAgents(active=True, page_size=10)
136
- agents = results.get('items', [])
137
- print(f"✅ Found {len(agents)} active agent(s)")
138
- for i, agent in enumerate(agents[:3], 1):
139
- print(f" {i}. {agent['name']} - {agent.get('totalFeedback', 0)} feedback")
140
- except Exception as e:
141
- print(f"❌ Failed to search active agents: {e}")
142
-
143
- print(f"\n📍 Step 7: Search Agents with Multiple Filters (Capabilities + Skills)")
144
- print("-" * 60)
145
- try:
146
- # Using capabilities and skills from test_feedback.py:
147
- # Capabilities: data_analysis, code_generation, natural_language_understanding, problem_solving, communication
148
- # Skills: python, javascript, machine_learning, web_development, cloud_computing
149
- results = sdk.searchAgents(
150
- mcpTools=["communication"],
151
- a2aSkills=["python"]
152
- )
153
- agents = results.get('items', [])
154
- print(f"✅ Found {len(agents)} agent(s) with 'communication' capability AND 'python' skill")
155
- for i, agent in enumerate(agents[:3], 1):
156
- print(f" {i}. {agent['name']}")
157
- except Exception as e:
158
- print(f"❌ Failed to search with multiple filters: {e}")
159
-
160
- print(f"\n📍 Step 8: Search Agents by Reputation (Minimum Average Score)")
161
- print("-" * 60)
162
- try:
163
- results = sdk.searchAgentsByReputation(minAverageScore=80)
164
- agents = results.get('items', [])
165
- print(f"✅ Found {len(agents)} agent(s) with average score >= 80")
166
- for i, agent in enumerate(agents[:3], 1):
167
- # AgentSummary object - use attributes, not dict.get()
168
- avg_score = agent.extras.get('averageScore', 'N/A') if agent.extras else 'N/A'
169
- print(f" {i}. {agent.name}")
170
- print(f" Average Score: {avg_score}")
171
- print(f" Agent ID: {agent.agentId}")
172
- except Exception as e:
173
- print(f"❌ Failed to search by reputation score: {e}")
174
-
175
- print(f"\n📍 Step 9: Search Agents by Reputation with Specific Tags")
176
- print("-" * 60)
177
- try:
178
- # Using tags that actually exist in feedback: "enterprise" appears frequently
179
- # Note: GraphQL query has known issue with mixing filters, so using includeRevoked=True as workaround
180
- # which may affect results, but at least the query will execute
181
- results = sdk.searchAgentsByReputation(
182
- tags=["enterprise"],
183
- minAverageScore=0, # No threshold to see any results
184
- includeRevoked=True # Workaround for GraphQL query builder issue
185
- )
186
- agents = results.get('items', [])
187
- print(f"✅ Found {len(agents)} agent(s) with 'enterprise' tag")
188
- for i, agent in enumerate(agents[:3], 1):
189
- # AgentSummary object - use attributes
190
- avg_score = agent.extras.get('averageScore', 'N/A') if agent.extras else 'N/A'
191
- print(f" {i}. {agent.name} - Avg: {avg_score}")
192
- except Exception as e:
193
- print(f"❌ Failed to search by reputation tags: {e}")
194
-
195
- print(f"\n📍 Step 10: Search Agents by Reputation with Capability Filtering")
196
- print("-" * 60)
197
- try:
198
- # Using capabilities that actually exist in feedback: code_generation, problem_solving, data_analysis
199
- results = sdk.searchAgentsByReputation(
200
- capabilities=["code_generation"],
201
- minAverageScore=0 # No threshold to see any results
202
- )
203
- agents = results.get('items', [])
204
- print(f"✅ Found {len(agents)} agent(s) with 'code_generation' capability")
205
- for i, agent in enumerate(agents[:3], 1):
206
- avg_score = agent.extras.get('averageScore', 'N/A') if hasattr(agent, 'extras') and agent.extras else 'N/A'
207
- print(f" {i}. {agent.name}")
208
- print(f" Avg Score: {avg_score}")
209
- except Exception as e:
210
- print(f"❌ Failed to search by reputation with capabilities: {e}")
211
-
212
- print(f"\n📍 Step 11: Advanced - Find Top-Rated Agents with Specific Skills")
213
- print("-" * 60)
214
- try:
215
- # Using skills that actually exist in feedback: python, machine_learning, cloud_computing, web_development
216
- results = sdk.searchAgentsByReputation(
217
- skills=["python"],
218
- minAverageScore=0 # No threshold to see any results
219
- )
220
- agents = results.get('items', [])
221
- print(f"✅ Found {len(agents)} agent(s) with 'python' skill")
222
- for i, agent in enumerate(agents[:3], 1):
223
- # AgentSummary object - use attributes
224
- avg_score = agent.extras.get('averageScore', 'N/A') if agent.extras else 'N/A'
225
- print(f" {i}. {agent.name}")
226
- print(f" Average Score: {avg_score}")
227
- if agent.a2aSkills:
228
- print(f" Skills: {', '.join(agent.a2aSkills[:3])}")
229
- except Exception as e:
230
- print(f"❌ Failed advanced skill search: {e}")
231
-
232
- print(f"\n📍 Step 12: Advanced - Complex Multi-Criteria Search")
233
- print("-" * 60)
234
- try:
235
- results = sdk.searchAgents(name="Test", active=True, page_size=10)
236
- agents = results.get('items', [])
237
- print(f"✅ Found {len(agents)} agent(s) matching multiple criteria")
238
- for i, agent in enumerate(agents[:3], 1):
239
- print(f" {i}. {agent['name']}")
240
- print(f" Active: {agent.get('active', False)}, Feedback: {agent.get('totalFeedback', 0)}")
241
- if agent.get('ens'):
242
- print(f" ENS: {agent['ens']}")
243
- except Exception as e:
244
- print(f"❌ Failed complex search: {e}")
245
-
246
- print(f"\n📍 Step 13: Pagination Test (First 5 Agents)")
247
- print("-" * 60)
248
- try:
249
- results = sdk.searchAgents(page_size=5)
250
- agents = results.get('items', [])
251
- print(f"✅ Retrieved first page: {len(agents)} agent(s)")
252
- for i, agent in enumerate(agents, 1):
253
- agent_id = agent.get('agentId', agent.get('id', 'N/A'))
254
- print(f" {i}. {agent['name']} (ID: {agent_id})")
255
- except Exception as e:
256
- print(f"❌ Failed pagination test: {e}")
257
-
258
- print(f"\n📍 Step 14: Sort by Activity (Most Recent)")
259
- print("-" * 60)
260
- try:
261
- results = sdk.searchAgents(page_size=10, sort=["updatedAt:desc"])
262
- agents = results.get('items', [])
263
- if agents:
264
- print(f"✅ Retrieved {len(agents)} agents")
265
- print(f" Most recent activity IDs:")
266
- for i, agent in enumerate(agents[:5], 1):
267
- agent_id = agent.get('agentId', agent.get('id', 'N/A'))
268
- print(f" {i}. ID {agent_id}: {agent['name']}")
269
- except Exception as e:
270
- print(f"❌ Failed activity sort: {e}")
271
-
272
- print(f"\n📍 Step 15: Search Agents by Single Owner Address")
273
- print("-" * 60)
274
- try:
275
- # First, get an agent to extract its owner address for testing
276
- test_agent = sdk.getAgent(AGENT_ID)
277
- if hasattr(test_agent, 'owner') and test_agent.owner:
278
- owner_address = test_agent.owner
279
- print(f" Testing with owner address: {owner_address}")
280
-
281
- results = sdk.searchAgents(owners=[owner_address])
282
- agents = results.get('items', [])
283
- print(f"✅ Found {len(agents)} agent(s) owned by {owner_address[:10]}...{owner_address[-8:]}")
284
-
285
- for i, agent in enumerate(agents[:3], 1):
286
- agent_id = agent.get('agentId', agent.get('id', 'N/A'))
287
- agent_owner = agent.get('owner', 'N/A')
288
- print(f" {i}. {agent['name']} (ID: {agent_id})")
289
- print(f" Owner: {agent_owner[:10]}...{agent_owner[-8:] if len(agent_owner) > 18 else agent_owner}")
290
- else:
291
- print("⚠️ Test agent doesn't have owner information")
292
- except Exception as e:
293
- print(f"❌ Failed to search by single owner: {e}")
294
-
295
- print(f"\n📍 Step 16: Search Agents by Multiple Owner Addresses")
296
- print("-" * 60)
297
- try:
298
- # Get multiple agents to collect different owner addresses
299
- results = sdk.searchAgents(page_size=5)
300
- agents = results.get('items', [])
301
- owner_addresses = []
302
-
303
- for agent in agents:
304
- if agent.get('owner') and agent['owner'] not in owner_addresses:
305
- owner_addresses.append(agent['owner'])
306
- if len(owner_addresses) >= 2:
307
- break
308
-
309
- if len(owner_addresses) >= 2:
310
- print(f" Testing with {len(owner_addresses)} owner addresses")
311
- results = sdk.searchAgents(owners=owner_addresses)
312
- agents = results.get('items', [])
313
- print(f"✅ Found {len(agents)} agent(s) owned by multiple addresses")
314
-
315
- for i, agent in enumerate(agents[:5], 1):
316
- agent_id = agent.get('agentId', agent.get('id', 'N/A'))
317
- agent_owner = agent.get('owner', 'N/A')
318
- print(f" {i}. {agent['name']} (Owner: {agent_owner[:10]}...{agent_owner[-8:] if len(agent_owner) > 18 else agent_owner})")
319
- else:
320
- print("⚠️ Not enough different owners found for multi-owner test")
321
- except Exception as e:
322
- print(f"❌ Failed to search by multiple owners: {e}")
323
-
324
- print(f"\n📍 Step 17: Search Agents by Operator Addresses")
325
- print("-" * 60)
326
- try:
327
- # First check if any agents have operators defined
328
- results = sdk.searchAgents(page_size=10)
329
- agents = results.get('items', [])
330
- test_operators = []
331
-
332
- for agent in agents:
333
- if agent.get('operators') and len(agent['operators']) > 0:
334
- test_operators = agent['operators'][:1] # Use first operator
335
- print(f" Testing with operator: {test_operators[0][:10]}...{test_operators[0][-8:]}")
336
- break
337
-
338
- if test_operators:
339
- results = sdk.searchAgents(operators=test_operators)
340
- found_agents = results.get('items', [])
341
- print(f"✅ Found {len(found_agents)} agent(s) with specified operator")
342
-
343
- for i, agent in enumerate(found_agents[:3], 1):
344
- agent_id = agent.get('agentId', agent.get('id', 'N/A'))
345
- agent_operators = agent.get('operators', [])
346
- print(f" {i}. {agent['name']} (ID: {agent_id})")
347
- if agent_operators:
348
- print(f" Operators: {len(agent_operators)} total")
349
- else:
350
- print("⚠️ No agents with operators found for testing")
351
- except Exception as e:
352
- print(f"❌ Failed to search by operators: {e}")
353
-
354
- print(f"\n📍 Step 18: Combined Search - Owner + Active Status")
355
- print("-" * 60)
356
- try:
357
- # Get an owner address from an active agent
358
- results = sdk.searchAgents(active=True, page_size=5)
359
- agents = results.get('items', [])
360
-
361
- if agents and agents[0].get('owner'):
362
- test_owner = agents[0]['owner']
363
- print(f" Testing owner {test_owner[:10]}...{test_owner[-8:]} + active=True")
364
-
365
- results = sdk.searchAgents(owners=[test_owner], active=True)
366
- found_agents = results.get('items', [])
367
- print(f"✅ Found {len(found_agents)} active agent(s) owned by specified address")
368
-
369
- for i, agent in enumerate(found_agents[:3], 1):
370
- agent_id = agent.get('agentId', agent.get('id', 'N/A'))
371
- print(f" {i}. {agent['name']} (ID: {agent_id})")
372
- print(f" Active: {agent.get('active', False)}, Owner: {agent.get('owner', 'N/A')[:10]}...")
373
- else:
374
- print("⚠️ No active agents with owner information found")
375
- except Exception as e:
376
- print(f"❌ Failed combined owner + active search: {e}")
377
-
378
- print(f"\n📍 Step 19: Combined Search - Owner + Name Filter")
379
- print("-" * 60)
380
- try:
381
- # Get agents and find one with both name and owner
382
- results = sdk.searchAgents(page_size=10)
383
- agents = results.get('items', [])
384
-
385
- test_agent = None
386
- for agent in agents:
387
- if agent.get('owner') and agent.get('name'):
388
- test_agent = agent
389
- break
390
-
391
- if test_agent:
392
- test_owner = test_agent['owner']
393
- # Use partial name for search
394
- name_part = test_agent['name'][:4] if len(test_agent['name']) > 4 else test_agent['name']
395
- print(f" Testing owner filter + name contains '{name_part}'")
396
-
397
- results = sdk.searchAgents(owners=[test_owner], name=name_part)
398
- found_agents = results.get('items', [])
399
- print(f"✅ Found {len(found_agents)} agent(s) matching both criteria")
400
-
401
- for i, agent in enumerate(found_agents[:3], 1):
402
- agent_id = agent.get('agentId', agent.get('id', 'N/A'))
403
- print(f" {i}. {agent['name']} (ID: {agent_id})")
404
- else:
405
- print("⚠️ No suitable test agent found")
406
- except Exception as e:
407
- print(f"❌ Failed combined owner + name search: {e}")
408
-
409
- print("\n" + "=" * 60)
410
- print("✅ Search Tests Completed!")
411
- print("=" * 60)
412
-
413
-
414
- if __name__ == "__main__":
415
- main()