|
|
""" |
|
|
Simple test for InklyAI AgentAI integration without Flask API. |
|
|
""" |
|
|
|
|
|
import sys |
|
|
import os |
|
|
sys.path.append('src') |
|
|
|
|
|
from agentai_integration import AgentAISignatureManager, AgentAISignatureAPI |
|
|
from src.models.siamese_network import SignatureVerifier |
|
|
from src.data.preprocessing import SignaturePreprocessor |
|
|
|
|
|
|
|
|
def test_agentai_integration(): |
|
|
"""Test the AgentAI integration directly.""" |
|
|
print("π§ͺ Testing InklyAI AgentAI Integration (Direct)") |
|
|
print("=" * 60) |
|
|
|
|
|
|
|
|
print("\n1. Initializing signature manager...") |
|
|
signature_manager = AgentAISignatureManager( |
|
|
threshold=0.75, |
|
|
device='auto' |
|
|
) |
|
|
print(" β
Signature manager initialized") |
|
|
|
|
|
|
|
|
if not os.path.exists('data/samples/john_doe_1.png'): |
|
|
print("\nβ οΈ Sample data not found. Creating sample signatures...") |
|
|
from demo import create_sample_signatures |
|
|
create_sample_signatures() |
|
|
print(" β
Sample signatures created") |
|
|
|
|
|
|
|
|
print("\n2. Registering test agents...") |
|
|
agents = [ |
|
|
("agent_001", "data/samples/john_doe_1.png"), |
|
|
("agent_002", "data/samples/jane_smith_1.png"), |
|
|
("agent_003", "data/samples/bob_wilson_1.png") |
|
|
] |
|
|
|
|
|
for agent_id, signature_template in agents: |
|
|
success = signature_manager.register_agent_signature(agent_id, signature_template) |
|
|
if success: |
|
|
print(f" β
Registered {agent_id}") |
|
|
else: |
|
|
print(f" β Failed to register {agent_id}") |
|
|
|
|
|
|
|
|
print("\n3. Testing signature verification...") |
|
|
|
|
|
test_cases = [ |
|
|
("agent_001", "data/samples/john_doe_2.png", "Genuine signature"), |
|
|
("agent_002", "data/samples/jane_smith_2.png", "Genuine signature"), |
|
|
("agent_001", "data/samples/jane_smith_1.png", "Forged signature"), |
|
|
("agent_002", "data/samples/bob_wilson_1.png", "Forged signature") |
|
|
] |
|
|
|
|
|
for agent_id, signature_image, expected in test_cases: |
|
|
try: |
|
|
result = signature_manager.verify_agent_signature(agent_id, signature_image) |
|
|
print(f" {agent_id} vs {signature_image.split('/')[-1]}: " |
|
|
f"Verified={result.is_verified}, Similarity={result.similarity_score:.3f}, " |
|
|
f"Confidence={result.confidence:.3f}") |
|
|
except Exception as e: |
|
|
print(f" β Error verifying {agent_id}: {e}") |
|
|
|
|
|
|
|
|
print("\n4. Testing agent statistics...") |
|
|
for agent_id, _ in agents: |
|
|
try: |
|
|
stats = signature_manager.get_agent_verification_stats(agent_id) |
|
|
print(f" {agent_id}: {stats['total_verifications']} verifications, " |
|
|
f"success rate: {stats['success_rate']:.2%}") |
|
|
except Exception as e: |
|
|
print(f" β Error getting stats for {agent_id}: {e}") |
|
|
|
|
|
|
|
|
print("\n5. Testing agent deactivation/reactivation...") |
|
|
|
|
|
|
|
|
deactivated = signature_manager.deactivate_agent("agent_001") |
|
|
print(f" Deactivated agent_001: {deactivated}") |
|
|
|
|
|
|
|
|
result = signature_manager.verify_agent_signature("agent_001", "data/samples/john_doe_2.png") |
|
|
print(f" Deactivated agent verification: {result.is_verified} (should be False)") |
|
|
|
|
|
|
|
|
reactivated = signature_manager.reactivate_agent("agent_001") |
|
|
print(f" Reactivated agent_001: {reactivated}") |
|
|
|
|
|
|
|
|
print("\n6. Testing batch verification...") |
|
|
|
|
|
batch_requests = [ |
|
|
{ |
|
|
"agent_id": "agent_001", |
|
|
"signature_image": "data/samples/john_doe_2.png", |
|
|
"context": {"test": True} |
|
|
}, |
|
|
{ |
|
|
"agent_id": "agent_002", |
|
|
"signature_image": "data/samples/jane_smith_2.png", |
|
|
"context": {"test": True} |
|
|
} |
|
|
] |
|
|
|
|
|
try: |
|
|
batch_results = signature_manager.batch_verify_agents(batch_requests) |
|
|
print(f" β
Batch verification processed {len(batch_results)} requests") |
|
|
for result in batch_results: |
|
|
print(f" - {result.agent_id}: Verified={result.is_verified}, " |
|
|
f"Similarity={result.similarity_score:.3f}") |
|
|
except Exception as e: |
|
|
print(f" β Batch verification failed: {e}") |
|
|
|
|
|
|
|
|
print("\n7. Testing API wrapper...") |
|
|
api = AgentAISignatureAPI(signature_manager) |
|
|
|
|
|
|
|
|
api_result = api.verify_signature_endpoint({ |
|
|
"agent_id": "agent_001", |
|
|
"signature_image": "data/samples/john_doe_2.png", |
|
|
"context": {"api_test": True} |
|
|
}) |
|
|
|
|
|
if api_result['success']: |
|
|
print(f" β
API verification: {api_result['is_verified']}, " |
|
|
f"Similarity: {api_result['similarity_score']:.3f}") |
|
|
else: |
|
|
print(f" β API verification failed: {api_result.get('error')}") |
|
|
|
|
|
print("\nπ AgentAI Integration Test Completed!") |
|
|
print("\nKey Features Demonstrated:") |
|
|
print("β
Agent registration and management") |
|
|
print("β
Signature verification with confidence scoring") |
|
|
print("β
Agent statistics and monitoring") |
|
|
print("β
Agent activation/deactivation") |
|
|
print("β
Batch processing") |
|
|
print("β
API wrapper functionality") |
|
|
print("β
Error handling and logging") |
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
def demonstrate_agentai_use_cases(): |
|
|
"""Demonstrate real-world AgentAI use cases.""" |
|
|
print("\n" + "=" * 60) |
|
|
print("π’ AgentAI Use Case Demonstrations") |
|
|
print("=" * 60) |
|
|
|
|
|
|
|
|
signature_manager = AgentAISignatureManager(threshold=0.75) |
|
|
|
|
|
|
|
|
use_cases = [ |
|
|
("financial_agent", "data/samples/john_doe_1.png", "Financial AI Agent"), |
|
|
("healthcare_agent", "data/samples/jane_smith_1.png", "Healthcare AI Agent"), |
|
|
("legal_agent", "data/samples/bob_wilson_1.png", "Legal AI Agent") |
|
|
] |
|
|
|
|
|
print("\n1. Multi-Agent System Authentication") |
|
|
print("-" * 40) |
|
|
|
|
|
for agent_id, signature_template, description in use_cases: |
|
|
if os.path.exists(signature_template): |
|
|
signature_manager.register_agent_signature(agent_id, signature_template) |
|
|
print(f" β
{description} registered") |
|
|
|
|
|
|
|
|
print("\n2. Simulating Agent Communication") |
|
|
print("-" * 40) |
|
|
|
|
|
|
|
|
if "healthcare_agent" in signature_manager.agent_signatures: |
|
|
result = signature_manager.verify_agent_signature( |
|
|
"healthcare_agent", |
|
|
"data/samples/jane_smith_2.png" |
|
|
) |
|
|
print(f" Financial Agent verifying Healthcare Agent: {result.is_verified}") |
|
|
|
|
|
|
|
|
if "financial_agent" in signature_manager.agent_signatures: |
|
|
result = signature_manager.verify_agent_signature( |
|
|
"financial_agent", |
|
|
"data/samples/john_doe_2.png" |
|
|
) |
|
|
print(f" Legal Agent verifying Financial Agent: {result.is_verified}") |
|
|
|
|
|
print("\n3. Audit Trail and Compliance") |
|
|
print("-" * 40) |
|
|
|
|
|
|
|
|
print(f" Total verifications logged: {len(signature_manager.verification_history)}") |
|
|
for result in signature_manager.verification_history[-3:]: |
|
|
print(f" - {result.agent_id}: {result.is_verified} at {result.timestamp}") |
|
|
|
|
|
print("\n4. Security and Access Control") |
|
|
print("-" * 40) |
|
|
|
|
|
|
|
|
signature_manager.deactivate_agent("financial_agent") |
|
|
result = signature_manager.verify_agent_signature("financial_agent", "data/samples/john_doe_2.png") |
|
|
print(f" Deactivated agent verification: {result.is_verified} (should be False)") |
|
|
|
|
|
|
|
|
signature_manager.reactivate_agent("financial_agent") |
|
|
result = signature_manager.verify_agent_signature("financial_agent", "data/samples/john_doe_2.png") |
|
|
print(f" Reactivated agent verification: {result.is_verified}") |
|
|
|
|
|
print("\nβ
AgentAI Use Case Demonstrations Completed!") |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
print("InklyAI AgentAI Integration - Direct Testing") |
|
|
print("=" * 60) |
|
|
|
|
|
try: |
|
|
|
|
|
test_agentai_integration() |
|
|
|
|
|
|
|
|
demonstrate_agentai_use_cases() |
|
|
|
|
|
print("\n" + "=" * 60) |
|
|
print("π― Integration Summary") |
|
|
print("=" * 60) |
|
|
print("InklyAI successfully integrates with AgentAI systems to provide:") |
|
|
print("β’ Biometric authentication for AI agents") |
|
|
print("β’ Secure multi-agent communication") |
|
|
print("β’ Audit trails for compliance") |
|
|
print("β’ Scalable signature verification") |
|
|
print("β’ Real-time fraud detection") |
|
|
print("\nReady for production deployment! π") |
|
|
|
|
|
except Exception as e: |
|
|
print(f"\nβ Test failed with error: {e}") |
|
|
import traceback |
|
|
traceback.print_exc() |
|
|
|