Skip to content

Conversation

@AstraBert
Copy link
Member

Description

Adding docs for Workflow resources.

@dosubot dosubot bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jun 5, 2025
@AstraBert AstraBert changed the title Clelia/resources docs Adding Docs for resources Jun 5, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XXL This PR changes 1000+ lines, ignoring generated files. labels Jun 5, 2025
@AstraBert
Copy link
Member Author

Oops, pushed also ElevenLabs to this branch, I reverted it :)

Copy link
Contributor

@masci masci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a first pass

A simple example can be:

```python
from llama_index.core.workflows.resource import Resource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from llama_index.core.workflows.resource import Resource
from llama_index.core.workflow.resource import Resource

return Memory.from_defaults("user_id_123", token_limit=60000)


class CustomStartEvent(StartEvent):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use a standard StartEvent to reduce the size of the example?

```
## Resources

Resources are external dependencies that you can equip the steps of your workflows with.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use something like "Resources are external dependencies you can inject into steps of a workflow" to convey the "dependency injection" concept.

return StopEvent(result="Messages put into memory")
```

`Resource` here acts like an executor for the function: once you run the steps, if they have resources declared with them, the factory function declared within `Resource` gets executed and turned into the component that it is supposed to represent as specified in the type annotation (in the example above, a Memory object).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simplify, something along these lines:

The type of a resource must be declared with Annotated, and Resource is responsible for providing the actual instance at runtime by invoking the factory function get_memory. The return type of get_memory must be consistent with the one declared in the annotation, a Memory object in the example above.


`Resource` here acts like an executor for the function: once you run the steps, if they have resources declared with them, the factory function declared within `Resource` gets executed and turned into the component that it is supposed to represent as specified in the type annotation (in the example above, a Memory object).

If you run the workflow, you will also notice that the resource is shared among steps: this behavior can be changed by passing `Resource(..., cache=False)`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be more direct:

"Resources are shared among steps of a workflow, and Resource will invoke the factory function only once. In case this is not the desired behaviour, passing cache=False to Resource will inject different resource objects in different steps, inoking the factory function as many times.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 6, 2025
@AstraBert AstraBert merged commit 3093dab into main Jun 6, 2025
10 checks passed
@AstraBert AstraBert deleted the clelia/resources-docs branch June 6, 2025 10:36
@colca colca mentioned this pull request Jun 9, 2025
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants