feat(fase2): thread tools + budget middleware through fresh_workflow onto agents

This commit is contained in:
Kjell Tore Guttormsen 2026-06-26 00:36:06 +02:00
commit 434ecb92c9
2 changed files with 80 additions and 13 deletions

View file

@ -57,3 +57,46 @@ def test_layer1_hitl_option_builds() -> None:
wf = fresh_workflow(factory, max_rounds=2, enable_layer1_hitl=True)
assert wf is not None
def test_tools_and_middleware_threaded_to_each_agent(monkeypatch) -> None:
"""Construction-spy: every agent is built WITH the provided tools + middleware (F7 + F2
wiring). `.tools` is not a public attr on a built Agent, so assert at the construction
boundary, not by reading the agent back."""
from portfolio_optimiser import workflow as wf_mod
recorded: list[dict[str, object]] = []
class _RecordingAgent:
def __init__(self, *args: object, **kwargs: object) -> None:
recorded.append(kwargs)
monkeypatch.setattr(wf_mod, "Agent", _RecordingAgent)
sentinel_tool = object()
sentinel_mw = object()
def factory(role: str) -> BaseChatClient:
return FakeChatClient(default_reply="ok")
wf_mod.maker_checker_agents(factory, tools=[sentinel_tool], middleware=[sentinel_mw])
assert len(recorded) == 2 # proposer + checker
for kwargs in recorded:
assert kwargs["tools"] == [sentinel_tool]
assert kwargs["middleware"] == [sentinel_mw]
async def test_output_from_surfaces_the_proposer_output() -> None:
"""Behavioral: the debate surfaces the PROPOSER's converged output via output_from=[proposer]
without it, get_outputs() yields only the orchestrator's 'reached max rounds' notice
(verified). Step 4's F1 fix consumes this."""
marker = "PROPOSER_MARKER_7f3a"
def factory(role: str) -> BaseChatClient:
return FakeChatClient(default_reply=marker if role == "proposer" else "checker view")
wf = fresh_workflow(factory, max_rounds=2)
result = await wf.run("Find a cost-saving measure for FV42.")
texts = [getattr(o, "text", "") or "" for o in result.get_outputs()]
assert any(marker in t for t in texts), f"proposer output not surfaced; got {texts!r}"