Skip to content
Merged
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 @@ -601,6 +601,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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ switch = [
backends = ["mellea[watsonx,hf,litellm]"]

hooks = [
"cpex>=0.1.0.dev12; python_version >= '3.11'",
"cpex>=0.1.0",
"grpcio>=1.78.0",
]

Expand Down
42 changes: 42 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,48 @@ 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 mirrors view_for_generation()."""
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 observed[0].context_view == ctx.view_for_generation()

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
Loading