diff --git a/mellea/stdlib/functional.py b/mellea/stdlib/functional.py index f4bdb2371..d23866a7e 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.view_for_generation(), 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..cb893a900 100644 --- a/test/plugins/test_hook_call_sites.py +++ b/test/plugins/test_hook_call_sites.py @@ -264,6 +264,29 @@ 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_has_context_view(self) -> None: + """COMPONENT_PRE_EXECUTE payload.context_view is populated.""" + from mellea.stdlib.components import Instruction + from mellea.stdlib.context import ChatContext + 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 = ChatContext().add(CBlock("previous turn")) + action = Instruction("Context check") + + await aact(action, ctx, backend, strategy=None) + assert observed[0].context_view is not None + assert len(observed[0].context_view) == 1 + assert observed[0].context_view[0].value == "previous turn" + 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