Skip to main content
Let’s work through a slightly more complex example of a news report generator. We want full control over the workflow, including the ability to stream the output. We also want to cache the results of the web search and the scrape. In this workflow, we will generate a comprehensive news report on a given topic.
  1. First we will search the web for articles on the topic:
    • Use cached search results if available and use_search_cache is True.
    • Otherwise, perform a new web search.
  2. Next we will scrape the content of each article:
    • Use cached scraped articles if available and use_scrape_cache is True.
    • Scrape new articles that aren’t in the cache.
  3. Finally we will generate the final report using the scraped article contents.
The caching mechanism is implemented using the session_state which is a dictionary that is persisted across workflow runs. This really helps with performance and cost.

Full Code

news_report_generator.py

Run the workflow

Install dependencies
Run the workflow
Test if the results are cached, run the workflow again with the same parameters.

Video

Checkout the recording of the workflow running and see how the results are cached in the 2nd run.