Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mellea/stdlib/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
43 changes: 43 additions & 0 deletions test/plugins/test_hook_call_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading