|
12 | 12 | import asyncio |
13 | 13 | import sys |
14 | 14 | import os |
| 15 | +from typing import Optional |
15 | 16 |
|
16 | 17 | # Disable LangSmith tracing for tests |
17 | 18 | os.environ["LANGCHAIN_TRACING_V2"] = "false" |
|
30 | 31 | "performance": "What is my system status? Give me CPU and memory metrics.", |
31 | 32 | "discovery": "Give me an overview of available system services.", |
32 | 33 | "browse": "Show me services in the QSYS2 schema.", |
33 | | - "search": "Search for services related to system status." |
| 34 | + "search": "Search for services related to system status.", |
| 35 | + "security": "Check for user profiles vulnerable to impersonation attacks." |
34 | 36 | } |
35 | 37 |
|
36 | | -async def test_single_agent(agent_type: str, model_id: str = "gpt-oss:20b"): |
| 38 | +async def test_single_agent(agent_type: str, model_id: str = "gpt-oss:20b", category: Optional[str] = None): |
37 | 39 | """Test a single agent with a sample query.""" |
38 | 40 | print(f"\n{'='*80}") |
39 | 41 | print(f"Testing {agent_type.upper()} Agent") |
| 42 | + if category: |
| 43 | + print(f"Category Filter: {category}") |
40 | 44 | print(f"{'='*80}\n") |
41 | 45 |
|
42 | 46 | try: |
43 | 47 | # Create agent context |
44 | 48 | print(f"🔧 Creating {agent_type} agent with model {model_id}...") |
45 | | - ctx = await create_ibmi_agent(agent_type, model_id=model_id) |
| 49 | + if category: |
| 50 | + print(f" Filtering by category: {category}") |
| 51 | + |
| 52 | + # Pass category parameter if provided (only for security agent) |
| 53 | + kwargs = {"model_id": model_id} |
| 54 | + if category and agent_type == "security": |
| 55 | + kwargs["category"] = category |
| 56 | + |
| 57 | + ctx = await create_ibmi_agent(agent_type, **kwargs) |
46 | 58 |
|
47 | 59 | async with ctx as (agent, session): |
48 | 60 | print(f"✅ Agent created: {agent.name}\n") |
@@ -111,16 +123,27 @@ async def test_all_agents(model_id: str = "gpt-oss:20b"): |
111 | 123 |
|
112 | 124 | return all(results.values()) |
113 | 125 |
|
114 | | -async def interactive_mode(agent_type: str, model_id: str = "gpt-oss:20b"): |
| 126 | +async def interactive_mode(agent_type: str, model_id: str = "gpt-oss:20b", category: Optional[str] = None): |
115 | 127 | """Interactive chat mode with a specific agent.""" |
116 | 128 | print(f"\n{'='*80}") |
117 | 129 | print(f"Interactive Mode - {agent_type.upper()} Agent") |
| 130 | + if category: |
| 131 | + print(f"Category Filter: {category}") |
118 | 132 | print(f"{'='*80}\n") |
119 | 133 |
|
120 | 134 | try: |
121 | 135 | # Create agent context |
122 | | - print(f"🔧 Initializing {agent_type} agent with {model_id}...\n") |
123 | | - ctx = await create_ibmi_agent(agent_type, model_id=model_id) |
| 136 | + print(f"🔧 Initializing {agent_type} agent with {model_id}...") |
| 137 | + if category: |
| 138 | + print(f" Filtering by category: {category}") |
| 139 | + print() |
| 140 | + |
| 141 | + # Pass category parameter if provided (only for security agent) |
| 142 | + kwargs = {"model_id": model_id} |
| 143 | + if category and agent_type == "security": |
| 144 | + kwargs["category"] = category |
| 145 | + |
| 146 | + ctx = await create_ibmi_agent(agent_type, **kwargs) |
124 | 147 |
|
125 | 148 | async with ctx as (agent, session): |
126 | 149 | print(f"✅ {agent.name} ready!\n") |
@@ -171,19 +194,32 @@ async def interactive_mode(agent_type: str, model_id: str = "gpt-oss:20b"): |
171 | 194 | import traceback |
172 | 195 | traceback.print_exc() |
173 | 196 |
|
174 | | -async def quick_test(model_id: str = "gpt-oss:20b"): |
| 197 | +async def quick_test(model_id: str = "gpt-oss:20b", category: Optional[str] = None, agent_filter: Optional[str] = None): |
175 | 198 | """Quick test - just verify all agents can be created.""" |
176 | 199 | print("\n" + "="*80) |
177 | 200 | print("Quick Agent Creation Test") |
178 | 201 | print("="*80) |
179 | | - print(f"Model: {model_id}\n") |
| 202 | + print(f"Model: {model_id}") |
| 203 | + if category: |
| 204 | + print(f"Category Filter: {category}") |
| 205 | + print() |
180 | 206 |
|
181 | 207 | results = {} |
182 | 208 |
|
183 | | - for agent_type in AVAILABLE_AGENTS.keys(): |
| 209 | + # Filter to specific agent if requested |
| 210 | + agents_to_test = [agent_filter] if agent_filter else list(AVAILABLE_AGENTS.keys()) |
| 211 | + |
| 212 | + for agent_type in agents_to_test: |
184 | 213 | try: |
185 | 214 | print(f"Creating {agent_type} agent...", end=" ") |
186 | | - ctx = await create_ibmi_agent(agent_type, model_id=model_id) |
| 215 | + |
| 216 | + # Pass category parameter if provided (only for security agent) |
| 217 | + kwargs = {"model_id": model_id} |
| 218 | + if category and agent_type == "security": |
| 219 | + kwargs["category"] = category |
| 220 | + print(f"(category: {category})...", end=" ") |
| 221 | + |
| 222 | + ctx = await create_ibmi_agent(agent_type, **kwargs) |
187 | 223 | async with ctx as (agent, session): |
188 | 224 | print(f"✅ {agent.name}") |
189 | 225 | results[agent_type] = True |
@@ -235,6 +271,12 @@ def main(): |
235 | 271 | help="Test specific agent type" |
236 | 272 | ) |
237 | 273 |
|
| 274 | + parser.add_argument( |
| 275 | + "--category", |
| 276 | + choices=["vulnerability-assessment", "audit", "remediation", "user-management"], |
| 277 | + help="Filter security agent tools by category (only applies to security agent)" |
| 278 | + ) |
| 279 | + |
238 | 280 | parser.add_argument( |
239 | 281 | "--interactive", |
240 | 282 | action="store_true", |
@@ -278,15 +320,21 @@ def main(): |
278 | 320 | if args.interactive and not args.agent: |
279 | 321 | parser.error("--interactive requires --agent to be specified") |
280 | 322 |
|
| 323 | + if args.category and not args.agent: |
| 324 | + parser.error("--category requires --agent to be specified") |
| 325 | + |
| 326 | + if args.category and args.agent != "security": |
| 327 | + parser.error("--category can only be used with --agent security") |
| 328 | + |
281 | 329 | # Run appropriate test mode |
282 | 330 | try: |
283 | 331 | if args.quick: |
284 | | - success = asyncio.run(quick_test(args.model)) |
| 332 | + success = asyncio.run(quick_test(args.model, args.category, args.agent)) |
285 | 333 | elif args.interactive: |
286 | | - asyncio.run(interactive_mode(args.agent, args.model)) |
| 334 | + asyncio.run(interactive_mode(args.agent, args.model, args.category)) |
287 | 335 | success = True |
288 | 336 | elif args.agent: |
289 | | - success = asyncio.run(test_single_agent(args.agent, args.model)) |
| 337 | + success = asyncio.run(test_single_agent(args.agent, args.model, args.category)) |
290 | 338 | else: |
291 | 339 | success = asyncio.run(test_all_agents(args.model)) |
292 | 340 |
|
|
0 commit comments