[PR #75] [CLOSED] feat: add gather in step decorator #94

Closed
opened 2026-02-16 02:16:33 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/run-llama/workflows-py/pull/75
Author: @AstraBert
Created: 8/25/2025
Status: Closed

Base: mainHead: clelia/gather-in-step-decorator


📝 Commits (3)

  • 6733448 feat: add gather in step decorator
  • f643158 fix: use gather_events and not collect_events; ci: tests
  • 782ee20 fix: check returned events from gather_events

📊 Changes

4 files changed (+97 additions, -80 deletions)

View changed files

📝 src/workflows/context/context.py (+90 -75)
📝 src/workflows/decorators.py (+4 -0)
📝 tests/test_decorator.py (+2 -1)
📝 tests/test_workflow_send_gather.py (+1 -4)

📄 Description

We add a gather property in StepConfig which then, in _step_worker, will trigger the collection of events before the execution of the step

Example usage:

class TestWf(Workflow):
    @step
    async def step_one(self, ev: StartEvent, ctx: Context[WfState]) -> SomeEvent | None:
        print("Received message " + ev.message)
        ctx.send_events([SomeEvent(data="hello"), SomeEvent(data="ciao")])
    
    @step
    async def step_process(self, ev: SomeEvent, counter: Annotated[Counter, Resource(get_counter)]) -> SecondEvent:
        counter.update()
        print("Processing message " + ev.data)
        time.sleep(1)
        return SecondEvent(greeting=ev.data)

    @step(gather=[SomeEvent])
    async def step_two(self, ev: SecondEvent, counter: Annotated[Counter, Resource(get_counter)]) -> StopEvent:
        print(ev.greeting)
        time.sleep(1)
        return StopEvent(result=f"Processed {counter.messages} messages")

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/run-llama/workflows-py/pull/75 **Author:** [@AstraBert](https://github.com/AstraBert) **Created:** 8/25/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `clelia/gather-in-step-decorator` --- ### 📝 Commits (3) - [`6733448`](https://github.com/run-llama/workflows-py/commit/67334483b1d4343269e36c3f56d4fc2396bdb2b6) feat: add gather in step decorator - [`f643158`](https://github.com/run-llama/workflows-py/commit/f6431588b53cd1e1bd31c8d42840445befea43ac) fix: use gather_events and not collect_events; ci: tests - [`782ee20`](https://github.com/run-llama/workflows-py/commit/782ee2013c6f52861e11a33585ba8f9df2d20bf6) fix: check returned events from gather_events ### 📊 Changes **4 files changed** (+97 additions, -80 deletions) <details> <summary>View changed files</summary> 📝 `src/workflows/context/context.py` (+90 -75) 📝 `src/workflows/decorators.py` (+4 -0) 📝 `tests/test_decorator.py` (+2 -1) 📝 `tests/test_workflow_send_gather.py` (+1 -4) </details> ### 📄 Description We add a `gather` property in `StepConfig` which then, in `_step_worker`, will trigger the collection of events before the execution of the step Example usage: ```python class TestWf(Workflow): @step async def step_one(self, ev: StartEvent, ctx: Context[WfState]) -> SomeEvent | None: print("Received message " + ev.message) ctx.send_events([SomeEvent(data="hello"), SomeEvent(data="ciao")]) @step async def step_process(self, ev: SomeEvent, counter: Annotated[Counter, Resource(get_counter)]) -> SecondEvent: counter.update() print("Processing message " + ev.data) time.sleep(1) return SecondEvent(greeting=ev.data) @step(gather=[SomeEvent]) async def step_two(self, ev: SecondEvent, counter: Annotated[Counter, Resource(get_counter)]) -> StopEvent: print(ev.greeting) time.sleep(1) return StopEvent(result=f"Processed {counter.messages} messages") ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 02:16:33 -05:00
yindo closed this issue 2026-02-16 02:16:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/workflows-py#94