Skip to content

Conversation

@masci
Copy link
Contributor

@masci masci commented Jun 6, 2025

Description

Follow up for resources documentation

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 6, 2025
return StopEvent(result="Messages put into memory")
```

The `Resource` wrapper acts as both a type declaration and an executor. At definition time, it specifies the expected type using `Annotated` - for example, a `Memory` object. At runtime, it invokes the associated factory function, such as `get_memory`, to produce the actual instance. The return type of this function must match the declared type, ensuring consistency between what’s expected and what’s provided during execution.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this bit because non technically true, Resource doesn't really declare a type.

is passed to every step where it's injected. It's important to master this concept because cached and non-cached
resources can lead to unexpected behaviour, let's see it in detail.

## Using Stateful Resources
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the biggest change in this PR. I don't believe we can link statefulness to caching behaviour, addded a paragraph explaining their relationship at the end


If we disable caching with `Annotated[Memory, Resource(get_memory, cache=False)]`, the function `get_memory` is going
to be called multiple times but the resource instance will be always the same. Such a resource should be considered
stateful not regarding its caching behaviour.
Copy link
Member

Choose a reason for hiding this comment

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

Yup, thanks a lot for bringing this up! When defining stateless VS stateful I didn't think of this, but yeah, this is definitely something that can happen!🙏

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 6, 2025
@AstraBert
Copy link
Member

It's good to go for me, but maybe it would be good if also @logan-markewich took a look at it before merging it :)

Copy link
Collaborator

@logan-markewich logan-markewich left a comment

Choose a reason for hiding this comment

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

Seems good!

@logan-markewich logan-markewich merged commit 2b7dbf3 into main Jun 6, 2025
10 checks passed
@logan-markewich logan-markewich deleted the massi/resources-docs branch June 6, 2025 17:09
@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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants