[Bug] Free-function steps are broken #13

Closed
opened 2026-02-16 02:16:04 -05:00 by yindo · 2 comments
Owner

Originally created by @logan-markewich on GitHub (Aug 7, 2025).

Since adding the custom stop/start event classes, I believe adding free-functions to workflows has been broken.

For example, this section in the docs doesn't work: https://docs.llamaindex.ai/en/stable/module_guides/workflow/#decorating-non-class-functions

I think probably we can make the start/stop event properties lazy?

(This was reported by a user on discord)

Originally created by @logan-markewich on GitHub (Aug 7, 2025). Since adding the custom stop/start event classes, I believe adding free-functions to workflows has been broken. For example, this section in the docs doesn't work: https://docs.llamaindex.ai/en/stable/module_guides/workflow/#decorating-non-class-functions I think probably we can make the start/stop event properties lazy? (This was reported by a user on discord)
yindo added the bug label 2026-02-16 02:16:04 -05:00
yindo closed this issue 2026-02-16 02:16:05 -05:00
Author
Owner

@masci commented on GitHub (Aug 8, 2025):

I think the example is wrong? The class of a Workflow, not the instance should be passed to the step decorator - for this to work, all the steps have to be there before creating the instance.

Example should be:

from llama_index.core.workflow import (
    Event,
    StartEvent,
    StopEvent,
    Workflow,
    step,
)
from llama_index.llms.openai import OpenAI


class JokeEvent(Event):
    joke: str

class JokeFlow(Workflow):
    pass

@step(workflow=JokeFlow)
async def generate_joke(ev: StartEvent) -> JokeEvent:
    topic = ev.topic

    prompt = f"Write your best joke about {topic}."

    llm = OpenAI()
    response = await llm.acomplete(prompt)
    return JokeEvent(joke=str(response))


@step(workflow=JokeFlow)
async def critique_joke(ev: JokeEvent) -> StopEvent:
    joke = ev.joke

    prompt = (
        f"Give a thorough analysis and critique of the following joke: {joke}"
    )
    response = await llm.acomplete(prompt)
    return StopEvent(result=str(response))


joke_flow = JokeFlow(timeout=60, verbose=True)

@masci commented on GitHub (Aug 8, 2025): I think the example is wrong? The class of a Workflow, not the instance should be passed to the `step` decorator - for this to work, all the steps have to be there before creating the instance. Example should be: ```py from llama_index.core.workflow import ( Event, StartEvent, StopEvent, Workflow, step, ) from llama_index.llms.openai import OpenAI class JokeEvent(Event): joke: str class JokeFlow(Workflow): pass @step(workflow=JokeFlow) async def generate_joke(ev: StartEvent) -> JokeEvent: topic = ev.topic prompt = f"Write your best joke about {topic}." llm = OpenAI() response = await llm.acomplete(prompt) return JokeEvent(joke=str(response)) @step(workflow=JokeFlow) async def critique_joke(ev: JokeEvent) -> StopEvent: joke = ev.joke prompt = ( f"Give a thorough analysis and critique of the following joke: {joke}" ) response = await llm.acomplete(prompt) return StopEvent(result=str(response)) joke_flow = JokeFlow(timeout=60, verbose=True) ```
Author
Owner

@logan-markewich commented on GitHub (Aug 8, 2025):

@masci oh weird, that does make more sense

@logan-markewich commented on GitHub (Aug 8, 2025): @masci oh weird, that does make more sense
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/workflows-py#13