Files
python-sdk/pkg/hanzo-network/examples/test_distributed.py
T
zeekay bbeaaa3dd2 fix: resolve all I001 import sorting errors across monorepo
Auto-fix 75 import sorting violations detected by ruff check
across hanzo-mcp, hanzo-network, hanzo-tools-*, and other packages.
Verified clean with both ruff 0.14.6 and 0.14.14 (CI version).
2026-03-07 00:01:43 -08:00

64 lines
1.7 KiB
Python

#!/usr/bin/env python
"""Test distributed network functionality."""
import asyncio
from hanzo_network import create_agent, create_distributed_network, create_tool
async def echo_tool(message: str) -> str:
"""Echo back the message."""
return f"Echo: {message}"
async def main():
"""Test distributed network."""
print("Testing Hanzo Distributed Network")
print("=" * 50)
# Create a simple agent
agent = create_agent(
name="test_agent",
description="Test agent",
system="You are a test agent.",
tools=[create_tool(echo_tool, "Echo a message")],
)
# Create distributed network
network = create_distributed_network(
agents=[agent],
name="test-network",
node_id="test-node-1",
listen_port=15690,
broadcast_port=15690,
)
print("Starting network...")
await network.start(wait_for_peers=0)
# Get status
status = network.get_network_status()
print("\nNetwork Status:")
print(f" Node ID: {status['node_id']}")
print(f" Running: {status['is_running']}")
print(f" Device: {status['device_capabilities']['model']}")
print(f" Chip: {status['device_capabilities']['chip']}")
print(f" Memory: {status['device_capabilities']['memory']} MB")
print(f" Local agents: {status['local_agents']}")
# Wait a bit for any peers
print("\nWaiting for peer discovery...")
await asyncio.sleep(2)
# Check peers
status = network.get_network_status()
print(f" Discovered peers: {status['peer_count']}")
print("\nStopping network...")
await network.stop()
print("Done!")
if __name__ == "__main__":
asyncio.run(main())