Skip to content

Commit 092f7e9

Browse files
committed
fix: Populate in payload
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
1 parent 50b106c commit 092f7e9

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

mellea/stdlib/functional.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ async def aact(
589589
pre_exec_payload = ComponentPreExecutePayload(
590590
component_type=_component_type_name,
591591
action=action,
592+
context_view=context.as_list(),
592593
requirements=requirements or [],
593594
model_options=model_options or {},
594595
format=format,

test/plugins/test_hook_call_sites.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,49 @@ async def recorder(payload: Any, ctx: Any) -> Any:
264264
await aact(action, ctx, backend, strategy=None)
265265
assert observed[0].component_type == "Instruction"
266266

267+
async def test_component_pre_execute_payload_has_context_view(self) -> None:
268+
"""COMPONENT_PRE_EXECUTE payload.context_view contains the context snapshot."""
269+
from mellea.stdlib.components import Instruction
270+
from mellea.stdlib.functional import aact
271+
272+
observed: list[Any] = []
273+
274+
@hook("component_pre_execute")
275+
async def recorder(payload: Any, ctx: Any) -> Any:
276+
observed.append(payload)
277+
return None
278+
279+
register(recorder)
280+
backend = _MockBackend()
281+
ctx = SimpleContext.from_previous(SimpleContext(), CBlock("prior turn"))
282+
action = Instruction("Context view test")
283+
284+
await aact(action, ctx, backend, strategy=None)
285+
assert observed[0].context_view is not None
286+
assert len(observed[0].context_view) == 1
287+
assert isinstance(observed[0].context_view[0], CBlock)
288+
289+
async def test_component_pre_execute_empty_context_gives_empty_list(self) -> None:
290+
"""COMPONENT_PRE_EXECUTE on a fresh context gives an empty list, not None."""
291+
from mellea.stdlib.components import Instruction
292+
from mellea.stdlib.functional import aact
293+
294+
observed: list[Any] = []
295+
296+
@hook("component_pre_execute")
297+
async def recorder(payload: Any, ctx: Any) -> Any:
298+
observed.append(payload)
299+
return None
300+
301+
register(recorder)
302+
backend = _MockBackend()
303+
ctx = SimpleContext()
304+
action = Instruction("Fresh context")
305+
306+
await aact(action, ctx, backend, strategy=None)
307+
assert observed[0].context_view is not None
308+
assert observed[0].context_view == []
309+
267310
async def test_component_post_success_fires_in_aact(self) -> None:
268311
"""COMPONENT_POST_SUCCESS fires in aact() after successful generation."""
269312
from mellea.stdlib.components import Instruction

0 commit comments

Comments
 (0)