diff --git a/mellea/stdlib/functional.py b/mellea/stdlib/functional.py index f4bdb2371..216792aac 100644 --- a/mellea/stdlib/functional.py +++ b/mellea/stdlib/functional.py @@ -589,6 +589,7 @@ async def aact( pre_exec_payload = ComponentPreExecutePayload( component_type=_component_type_name, action=action, + context_view=context.as_list(), requirements=requirements or [], model_options=model_options or {}, format=format, diff --git a/test/plugins/test_hook_call_sites.py b/test/plugins/test_hook_call_sites.py index a8689380f..f8aaa668a 100644 --- a/test/plugins/test_hook_call_sites.py +++ b/test/plugins/test_hook_call_sites.py @@ -264,6 +264,49 @@ async def recorder(payload: Any, ctx: Any) -> Any: await aact(action, ctx, backend, strategy=None) assert observed[0].component_type == "Instruction" + async def test_component_pre_execute_payload_has_context_view(self) -> None: + """COMPONENT_PRE_EXECUTE payload.context_view contains the context snapshot.""" + from mellea.stdlib.components import Instruction + from mellea.stdlib.functional import aact + + observed: list[Any] = [] + + @hook("component_pre_execute") + async def recorder(payload: Any, ctx: Any) -> Any: + observed.append(payload) + return None + + register(recorder) + backend = _MockBackend() + ctx = SimpleContext.from_previous(SimpleContext(), CBlock("prior turn")) + action = Instruction("Context view test") + + await aact(action, ctx, backend, strategy=None) + assert observed[0].context_view is not None + assert len(observed[0].context_view) == 1 + assert isinstance(observed[0].context_view[0], CBlock) + + async def test_component_pre_execute_empty_context_gives_empty_list(self) -> None: + """COMPONENT_PRE_EXECUTE on a fresh context gives an empty list, not None.""" + from mellea.stdlib.components import Instruction + from mellea.stdlib.functional import aact + + observed: list[Any] = [] + + @hook("component_pre_execute") + async def recorder(payload: Any, ctx: Any) -> Any: + observed.append(payload) + return None + + register(recorder) + backend = _MockBackend() + ctx = SimpleContext() + action = Instruction("Fresh context") + + await aact(action, ctx, backend, strategy=None) + assert observed[0].context_view is not None + assert observed[0].context_view == [] + async def test_component_post_success_fires_in_aact(self) -> None: """COMPONENT_POST_SUCCESS fires in aact() after successful generation.""" from mellea.stdlib.components import Instruction