mirror of
https://github.com/hanzoai/agents.git
synced 2026-10-30 18:48:36 +00:00
Transforms hanzoai/agents from a marketplace config repo into a full agent orchestration platform by merging the AgentField infrastructure: - Go control plane (K8s-like agent orchestration, service mesh, DAG workflows) - Python SDK (FastAPI-based agent framework, LiteLLM, memory, DID/VC) - TypeScript SDK (@hanzo/agents - Vercel AI SDK, MCP, workflows) - Go SDK (idiomatic agent builder + client) - React 19 embedded dashboard (XyFlow DAGs, Recharts, Radix UI) - Docker/K8s/Helm deployment configs - Examples: hello world, deep research, RAG, simulation, benchmarks - Functional test suite across Python/Go/TypeScript All references rebranded: AgentField → Hanzo Agents - Module: github.com/hanzoai/agents/control-plane - Python: hanzo_agents - TypeScript: @hanzo/agents - Go: github.com/hanzoai/agents/sdk/go - Env vars: HANZO_AGENTS_* - Config: hanzo-agents.yaml Previous marketplace configs moved to config/ directory.
99 lines
2.9 KiB
Python
99 lines
2.9 KiB
Python
from types import MethodType, SimpleNamespace
|
|
|
|
import pytest
|
|
|
|
from hanzo_agents.agent import Agent
|
|
from hanzo_agents.agent_registry import set_current_agent, clear_current_agent
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_call_local_reasoner_argument_mapping():
|
|
agent = object.__new__(Agent)
|
|
agent.node_id = "node"
|
|
agent.hanzo_agents_connected = True
|
|
agent.dev_mode = False
|
|
agent.async_config = SimpleNamespace(
|
|
enable_async_execution=False, fallback_to_sync=False
|
|
)
|
|
agent._async_execution_manager = None
|
|
agent._current_execution_context = None
|
|
|
|
recorded = {}
|
|
|
|
async def fake_execute(target, input_data, headers):
|
|
recorded["target"] = target
|
|
recorded["input_data"] = input_data
|
|
recorded["headers"] = headers
|
|
return {"result": {"ok": True}}
|
|
|
|
agent.client = SimpleNamespace(execute=fake_execute)
|
|
|
|
async def local_reasoner(self, a, b, execution_context=None, extra=None):
|
|
return a + b
|
|
|
|
agent.local_reasoner = MethodType(local_reasoner, agent)
|
|
|
|
set_current_agent(agent)
|
|
try:
|
|
result = await agent.call("node.local_reasoner", 2, 3, extra=4)
|
|
finally:
|
|
clear_current_agent()
|
|
|
|
assert result == {"ok": True}
|
|
assert recorded["target"] == "node.local_reasoner"
|
|
assert recorded["input_data"] == {"a": 2, "b": 3, "extra": 4}
|
|
assert "X-Execution-ID" in recorded["headers"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_call_remote_target_uses_generic_arg_names():
|
|
agent = object.__new__(Agent)
|
|
agent.node_id = "node"
|
|
agent.hanzo_agents_connected = True
|
|
agent.dev_mode = False
|
|
agent.async_config = SimpleNamespace(
|
|
enable_async_execution=False, fallback_to_sync=False
|
|
)
|
|
agent._async_execution_manager = None
|
|
agent._current_execution_context = None
|
|
|
|
recorded = {}
|
|
|
|
async def fake_execute(target, input_data, headers):
|
|
recorded["target"] = target
|
|
recorded["input_data"] = input_data
|
|
return {"result": {"value": 10}}
|
|
|
|
agent.client = SimpleNamespace(execute=fake_execute)
|
|
|
|
set_current_agent(agent)
|
|
try:
|
|
result = await agent.call("other.remote_reasoner", 5, 6)
|
|
finally:
|
|
clear_current_agent()
|
|
|
|
assert result == {"value": 10}
|
|
assert recorded["target"] == "other.remote_reasoner"
|
|
assert recorded["input_data"] == {"arg_0": 5, "arg_1": 6}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_call_raises_when_hanzo_agents_disconnected():
|
|
agent = object.__new__(Agent)
|
|
agent.node_id = "node"
|
|
agent.hanzo_agents_connected = False
|
|
agent.dev_mode = False
|
|
agent.async_config = SimpleNamespace(
|
|
enable_async_execution=False, fallback_to_sync=False
|
|
)
|
|
agent._async_execution_manager = None
|
|
agent._current_execution_context = None
|
|
agent.client = SimpleNamespace()
|
|
|
|
set_current_agent(agent)
|
|
try:
|
|
with pytest.raises(Exception):
|
|
await agent.call("other.reasoner", 1)
|
|
finally:
|
|
clear_current_agent()
|