The storage of the workflow cannot be persisted in the arun method, but it can be persisted in the run method

The cache not work in Workflow.arun.
I’m not sure whether this is a bug or an issue on my end.

import asyncio
from typing import AsyncIterator
from agno.agent import RunResponse
from agno.storage.sqlite import SqliteStorage
from agno.utils.log import logger
from agno.workflow import Workflow


class CacheWorkflow(Workflow):
    # Purely descriptive, not used by the workflow
    description: str = "A workflow that caches previous outputs"

    async def arun(self, message: str) -> AsyncIterator[RunResponse]:
        logger.info(f"Checking cache for '{message}'")
        # Check if the output is already cached
        if self.session_state.get(message):
            logger.info(f"Cache hit for '{message}'")
            yield RunResponse(run_id=self.run_id, content=self.session_state.get(message))
            return

        logger.info(f"Cache miss for '{message}'")
        # Cache the output after response is yielded
        self.session_state[message] = "HAHA..."

async def main():
    workflow = CacheWorkflow(
        session_id="my-session-id",
        storage=SqliteStorage(
            table_name="workflow_sessions",
            db_file="tmp/workflows.db",
        ),
    )

    async for item in workflow.arun(message="Tell me a joke."):
        print(item.content)

    workflow1 = CacheWorkflow(
        session_id="my-session-id",
        storage=SqliteStorage(
            table_name="workflow_sessions",
            db_file="tmp/workflows.db",
        ),
    )

    async for item in workflow1.arun(message="Tell me a joke."):
        print(item.content)

if __name__ == "__main__":
    asyncio.run(main())

output

INFO Checking cache for 'Tell me a joke.'                                      
INFO Cache miss for 'Tell me a joke.'                                          
INFO Checking cache for 'Tell me a joke.'                                      
INFO Cache miss for 'Tell me a joke.'                                          

agno version: agno==1.6.4

Hey @dqli, thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.If it’s urgent, please let us know. We appreciate your patience!