"""Which agent a request is for: what the caller named, else the only agent, else none.""" import pytest from orchestration.agents import Agent, load_agents from orchestration.routing import route PICNIC = Agent(work="picnic", url="http://picnic", description="Plans picnics.") PARTY = Agent(work="party", url="http://party", description="Plans parties.") def test_the_work_the_caller_names_settles_it(): decision = route({"work": "party"}, [PICNIC, PARTY]) assert decision.agent == PARTY def test_with_one_agent_and_nothing_named_that_agent_takes_it(): decision = route({}, [PICNIC]) assert decision.agent == PICNIC def test_with_several_agents_and_nothing_named_nothing_starts(): decision = route({}, [PICNIC, PARTY]) assert decision.agent is None assert "picnic" in decision.reason and "party" in decision.reason def test_work_no_agent_does_is_refused_by_name(): decision = route({"work": "wedding"}, [PICNIC, PARTY]) assert decision.agent is None assert "wedding" in decision.reason def test_agents_are_read_from_a_file(tmp_path): path = tmp_path / "agents.yaml" path.write_text( "agents:\n" " - work: picnic\n" " url: http://picnic/\n" " description: Plans picnics.\n", encoding="utf-8", ) assert load_agents(path) == [PICNIC] def test_two_agents_for_one_kind_of_work_are_refused(tmp_path): path = tmp_path / "agents.yaml" path.write_text( "agents:\n" " - {work: picnic, url: http://a}\n" " - {work: picnic, url: http://b}\n", encoding="utf-8", ) with pytest.raises(ValueError, match="picnic"): load_agents(path)