Files
Multi_Swarm_Coevolutive/tests/unit/test_genome_hypothesis.py
T
Adriano 42a95a52b5 feat(genome): HypothesisAgentGenome with deterministic id and serde
Dataclass per genoma agente ipotesi con campi prompt/feature/temperature/
top_p/model_tier/lookback/style + parent_ids/generation. Id sha1[:16]
deterministico su contenuto canonico (feature_access ordinate, float
arrotondati). to_dict/from_dict per persistenza.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 19:45:07 +02:00

51 lines
1.6 KiB
Python

from multi_swarm.genome.hypothesis import HypothesisAgentGenome, ModelTier
def test_genome_creation_defaults():
g = HypothesisAgentGenome(
system_prompt="Pensa come un fisico.",
feature_access=["close", "volume"],
temperature=0.9,
top_p=0.95,
model_tier=ModelTier.C,
lookback_window=200,
cognitive_style="physicist",
)
assert g.id is not None
assert g.parent_ids == []
assert g.generation == 0
def test_genome_serialization_roundtrip():
g = HypothesisAgentGenome(
system_prompt="Pensa come un biologo.",
feature_access=["close", "high", "low"],
temperature=1.1,
top_p=0.9,
model_tier=ModelTier.C,
lookback_window=300,
cognitive_style="biologist",
parent_ids=["abc"],
generation=5,
)
payload = g.to_dict()
g2 = HypothesisAgentGenome.from_dict(payload)
assert g2.system_prompt == g.system_prompt
assert g2.feature_access == g.feature_access
assert g2.temperature == g.temperature
assert g2.parent_ids == g.parent_ids
assert g2.generation == g.generation
assert g2.id == g.id
def test_genome_id_is_deterministic_on_content():
g1 = HypothesisAgentGenome(
system_prompt="X", feature_access=["close"], temperature=0.5,
top_p=0.9, model_tier=ModelTier.C, lookback_window=100, cognitive_style="x",
)
g2 = HypothesisAgentGenome(
system_prompt="X", feature_access=["close"], temperature=0.5,
top_p=0.9, model_tier=ModelTier.C, lookback_window=100, cognitive_style="x",
)
assert g1.id == g2.id