01_TestConnect.py 664 B

12345678910111213141516171819202122232425
  1. from hello_agents.tools import MCPTool, A2ATool, ANPTool
  2. # 1. MCP:访问工具
  3. mcp_tool = MCPTool()
  4. result = mcp_tool.run({
  5. "action": "call_tool",
  6. "tool_name": "add",
  7. "arguments": {"a": 10, "b": 20}
  8. })
  9. print(f"MCP计算结果: {result}") # 输出: 30.0
  10. # 2. ANP:服务发现
  11. anp_tool = ANPTool()
  12. anp_tool.run({
  13. "action": "register_service",
  14. "service_id": "calculator",
  15. "service_type": "math",
  16. "endpoint": "http://localhost:8080"
  17. })
  18. services = anp_tool.run({"action": "discover_services"})
  19. print(f"发现的服务: {services}")
  20. # 3. A2A:智能体通信
  21. a2a_tool = A2ATool("http://localhost:5000")
  22. print("A2A工具创建成功")