Skip to content

Commit 5da16f3

Browse files
committed
Fix a2a_wrapper imports and add clean usage example
- Remove top-level imports from fuzzforge_ai/__init__.py to avoid dependency issues - Fix config_bridge.py exception handling (remove undefined exc variable) - Add examples/test_a2a_simple.py demonstrating clean a2a_wrapper usage - Update package to use explicit imports: from fuzzforge_ai.a2a_wrapper import send_agent_task All functionality preserved, imports are now explicit and modular.
1 parent baace0e commit 5da16f3

File tree

4 files changed

+189
-8
lines changed

4 files changed

+189
-8
lines changed

ai/src/fuzzforge_ai/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
44
This module integrates the fuzzforge_ai components into FuzzForge,
55
providing intelligent AI agent capabilities for security analysis.
6+
7+
Usage:
8+
from fuzzforge_ai.a2a_wrapper import send_agent_task
9+
from fuzzforge_ai.agent import FuzzForgeAgent
10+
from fuzzforge_ai.config_manager import ConfigManager
611
"""
712
# Copyright (c) 2025 FuzzingLabs
813
#
@@ -16,9 +21,4 @@
1621
# Additional attribution and requirements are provided in the NOTICE file.
1722

1823

19-
__version__ = "0.6.0"
20-
21-
from .agent import FuzzForgeAgent
22-
from .config_manager import ConfigManager
23-
24-
__all__ = ['FuzzForgeAgent', 'ConfigManager']
24+
__version__ = "0.6.0"

ai/src/fuzzforge_ai/config_bridge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def __init__(self, *args, **kwargs):
2121
raise ImportError(
2222
"ProjectConfigManager is unavailable. Install the FuzzForge CLI "
2323
"package or supply a compatible configuration object."
24-
) from exc
24+
)
2525

2626
def __getattr__(name): # pragma: no cover - defensive
27-
raise ImportError("ProjectConfigManager unavailable") from exc
27+
raise ImportError("ProjectConfigManager unavailable")
2828

2929
ProjectConfigManager = _ProjectConfigManager
3030

examples/test_a2a_simple.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Simple example of using the A2A wrapper
4+
Run from project root: python examples/test_a2a_simple.py
5+
"""
6+
import asyncio
7+
8+
9+
async def main():
10+
# Clean import!
11+
from fuzzforge_ai.a2a_wrapper import send_agent_task
12+
13+
print("Sending task to agent at http://127.0.0.1:10900...")
14+
15+
result = await send_agent_task(
16+
url="http://127.0.0.1:10900/a2a/litellm_agent",
17+
model="gpt-4o-mini",
18+
provider="openai",
19+
prompt="You are concise.",
20+
message="Give me a simple Python function that adds two numbers.",
21+
context="test_session",
22+
timeout=120
23+
)
24+
25+
print(f"\nContext ID: {result.context_id}")
26+
print(f"\nResponse:\n{result.text}")
27+
28+
29+
if __name__ == "__main__":
30+
asyncio.run(main())

test_a2a_wrapper.py

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Test script for A2A wrapper module
4+
Sends tasks to the task-agent to verify functionality
5+
"""
6+
import asyncio
7+
import sys
8+
from pathlib import Path
9+
10+
# Add ai module to path
11+
ai_src = Path(__file__).parent / "ai" / "src"
12+
sys.path.insert(0, str(ai_src))
13+
14+
from fuzzforge_ai.a2a_wrapper import send_agent_task, get_agent_config
15+
16+
17+
async def test_basic_task():
18+
"""Test sending a basic task to the agent"""
19+
print("=" * 80)
20+
print("Test 1: Basic task without model specification")
21+
print("=" * 80)
22+
23+
result = await send_agent_task(
24+
url="http://127.0.0.1:10900/a2a/litellm_agent",
25+
message="What is 2+2? Answer in one sentence.",
26+
timeout=30
27+
)
28+
29+
print(f"Context ID: {result.context_id}")
30+
print(f"Response:\n{result.text}")
31+
print()
32+
return result.context_id
33+
34+
35+
async def test_with_model_and_prompt():
36+
"""Test sending a task with custom model and prompt"""
37+
print("=" * 80)
38+
print("Test 2: Task with model and prompt specification")
39+
print("=" * 80)
40+
41+
result = await send_agent_task(
42+
url="http://127.0.0.1:10900/a2a/litellm_agent",
43+
model="gpt-4o-mini",
44+
provider="openai",
45+
prompt="You are a concise Python expert. Answer in 2 sentences max.",
46+
message="Write a simple Python function that checks if a number is prime.",
47+
context="python_test",
48+
timeout=60
49+
)
50+
51+
print(f"Context ID: {result.context_id}")
52+
print(f"Response:\n{result.text}")
53+
print()
54+
return result.context_id
55+
56+
57+
async def test_fuzzing_task():
58+
"""Test a fuzzing-related task"""
59+
print("=" * 80)
60+
print("Test 3: Fuzzing harness generation task")
61+
print("=" * 80)
62+
63+
result = await send_agent_task(
64+
url="http://127.0.0.1:10900/a2a/litellm_agent",
65+
model="gpt-4o-mini",
66+
provider="openai",
67+
prompt="You are a security testing expert. Provide practical, working code.",
68+
message="Generate a simple fuzzing harness for a C function that parses JSON strings. Include only the essential code.",
69+
context="fuzzing_session",
70+
timeout=90
71+
)
72+
73+
print(f"Context ID: {result.context_id}")
74+
print(f"Response:\n{result.text}")
75+
print()
76+
77+
78+
async def test_get_config():
79+
"""Test getting agent configuration"""
80+
print("=" * 80)
81+
print("Test 4: Get agent configuration")
82+
print("=" * 80)
83+
84+
config = await get_agent_config(
85+
url="http://127.0.0.1:10900/a2a/litellm_agent",
86+
timeout=30
87+
)
88+
89+
print(f"Agent Config:\n{config}")
90+
print()
91+
92+
93+
async def test_multi_turn():
94+
"""Test multi-turn conversation with same context"""
95+
print("=" * 80)
96+
print("Test 5: Multi-turn conversation")
97+
print("=" * 80)
98+
99+
# First message
100+
result1 = await send_agent_task(
101+
url="http://127.0.0.1:10900/a2a/litellm_agent",
102+
message="What is the capital of France?",
103+
context="geography_quiz",
104+
timeout=30
105+
)
106+
print(f"Q1: What is the capital of France?")
107+
print(f"A1: {result1.text}")
108+
print()
109+
110+
# Follow-up in same context
111+
result2 = await send_agent_task(
112+
url="http://127.0.0.1:10900/a2a/litellm_agent",
113+
message="What is the population of that city?",
114+
context="geography_quiz", # Same context
115+
timeout=30
116+
)
117+
print(f"Q2: What is the population of that city?")
118+
print(f"A2: {result2.text}")
119+
print()
120+
121+
122+
async def main():
123+
"""Run all tests"""
124+
print("\n" + "=" * 80)
125+
print("FuzzForge A2A Wrapper Test Suite")
126+
print("=" * 80 + "\n")
127+
128+
try:
129+
# Run tests
130+
await test_basic_task()
131+
await test_with_model_and_prompt()
132+
await test_fuzzing_task()
133+
await test_get_config()
134+
await test_multi_turn()
135+
136+
print("=" * 80)
137+
print("✅ All tests completed successfully!")
138+
print("=" * 80)
139+
140+
except Exception as e:
141+
print(f"\n❌ Test failed with error: {e}")
142+
import traceback
143+
traceback.print_exc()
144+
return 1
145+
146+
return 0
147+
148+
149+
if __name__ == "__main__":
150+
exit_code = asyncio.run(main())
151+
sys.exit(exit_code)

0 commit comments

Comments
 (0)