Files
agents/sdk/python/tests/test_result_cache.py
zeekayandGitHub 5b5cf9e9db feat: merge AgentField control plane + SDKs as Hanzo Agents (#1)
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.
2026-02-09 18:53:09 -08:00

62 lines
1.8 KiB
Python

import time
from hanzo_agents.result_cache import ResultCache
from hanzo_agents.async_config import AsyncConfig
import asyncio
def test_cache_set_get_and_metrics():
cfg = AsyncConfig(enable_result_caching=True, result_cache_ttl=5.0)
cache = ResultCache(cfg)
assert cache.get("k1") is None
cache.set("k1", 123)
assert cache.get("k1") == 123
stats = cache.get_stats()
assert stats["hits"] >= 1
assert stats["misses"] >= 1
def test_cache_ttl_expiration():
cfg = AsyncConfig(enable_result_caching=True, result_cache_ttl=0.1)
cache = ResultCache(cfg)
cache.set("k", "v")
assert cache.get("k") == "v"
time.sleep(0.15)
assert cache.get("k") is None
# expirations metric should increase
stats = cache.get_stats()
assert stats["expirations"] >= 1
def test_cache_lru_eviction():
cfg = AsyncConfig(
enable_result_caching=True, result_cache_ttl=5.0, result_cache_max_size=2
)
cache = ResultCache(cfg)
cache.set("a", 1)
cache.set("b", 2)
# Access 'a' so 'b' becomes LRU
assert cache.get("a") == 1
cache.set("c", 3) # should evict LRU ('b')
assert cache.get("a") == 1
assert cache.get("b") is None
assert cache.get("c") == 3
def test_cache_async_context_and_cleanup_loop():
# Use very small TTL and cleanup interval
cfg = AsyncConfig(
enable_result_caching=True, result_cache_ttl=0.05, cleanup_interval=0.02
)
cache = ResultCache(cfg)
async def run():
async with cache:
cache.set("z", 9)
assert cache.get("z") == 9
await asyncio.sleep(0.1) # allow ttl to expire and cleanup to run
# Accessing should return None after cleanup removes it
return cache.get("z")
out = asyncio.run(run())
assert out is None