<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[DAGWorks’s Substack]]></title><description><![CDATA[Thought posts, updates on Hamilton & Burr, and what's happening at DAGWorks.]]></description><link>https://blog.dagworks.io</link><image><url>https://substackcdn.com/image/fetch/$s_!PigY!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png</url><title>DAGWorks’s Substack</title><link>https://blog.dagworks.io</link></image><generator>Substack</generator><lastBuildDate>Mon, 20 Apr 2026 22:16:36 GMT</lastBuildDate><atom:link href="https://blog.dagworks.io/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[DAGWorks Inc.]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[dagworks@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[dagworks@substack.com]]></itunes:email><itunes:name><![CDATA[DAGWorks Inc.]]></itunes:name></itunes:owner><itunes:author><![CDATA[DAGWorks Inc.]]></itunes:author><googleplay:owner><![CDATA[dagworks@substack.com]]></googleplay:owner><googleplay:email><![CDATA[dagworks@substack.com]]></googleplay:email><googleplay:author><![CDATA[DAGWorks Inc.]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Chat with your webpage with Scrapegraph, Burr and Lancedb ]]></title><description><![CDATA[In this post we are going to walk through the example of using the scrapegraph SDK with LanceDB and Burr. While Scrapegraph and Burr already have an integration layer, this is a very powerful, simple approach using the scrapegraph SDK.]]></description><link>https://blog.dagworks.io/p/chat-with-your-webpage-with-scrapegraph</link><guid isPermaLink="false">https://blog.dagworks.io/p/chat-with-your-webpage-with-scrapegraph</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Thu, 16 Jan 2025 00:22:32 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!9yTu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9yTu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9yTu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png 424w, https://substackcdn.com/image/fetch/$s_!9yTu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png 848w, https://substackcdn.com/image/fetch/$s_!9yTu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png 1272w, https://substackcdn.com/image/fetch/$s_!9yTu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9yTu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png" width="1456" height="410" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:410,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;image.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="image.png" title="image.png" srcset="https://substackcdn.com/image/fetch/$s_!9yTu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png 424w, https://substackcdn.com/image/fetch/$s_!9yTu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png 848w, https://substackcdn.com/image/fetch/$s_!9yTu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png 1272w, https://substackcdn.com/image/fetch/$s_!9yTu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa2717fc8-aaac-4a50-b940-1c4476dd5bd8_2831x798.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">What we&#8217;re building in this post &#8212; a simple web-scraper + indexer to ask natural-language queries of a web page!</figcaption></figure></div><p>In this post we are going to walk through the example of using the <a href="https://github.com/ScrapeGraphAI/scrapegraph-sdk/blob/main/cookbook/chat-webpage-simple-rag/scrapegraph_burr_lancedb.ipynb">scrapegraph</a> SDK with <a href="https://lancedb.com/">LanceDB</a> and <a href="https://github.com/dagworks-inc/burr">Burr</a>. While Scrapegraph and Burr already have an <a href="https://scrapegraph-ai.readthedocs.io/en/latest/scrapers/graph_config.html#burr">integration layer</a>, this is a very powerful, simple approach using the scrapegraph SDK. </p><p>This is written in collaboration with Scrapegraph, and adapted from the <a href="https://github.com/ScrapeGraphAI/scrapegraph-sdk/blob/main/cookbook/chat-webpage-simple-rag/scrapegraph_burr_lancedb.ipynb">example</a> on their repository. </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe to get updates on the latest posts.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>First we will go over the tools &#8212; Burr, Scrapegraph, and LanceDB. We will next walk through the code, show how it looks in production, and provide some further reading.</p><h1>The tools</h1><h2>ScrapeGraph</h2><p><a href="https://github.com/ScrapeGraphAI/Scrapegraph-ai">ScrapeGraphAI</a> is a Python library for web scraping that leverages LLMs and direct graph logic to build efficient scraping pipelines for websites and local documents, including XML, HTML, JSON, and Markdown files. With over 16k stars on GitHub and an active Discord community, it has become a popular tool for developers. The library also offers a hosted API, enabling access to its most advanced scraping services, including: </p><ul><li><p><em>SmartScraper</em>: extracts structured content from any webpage given a URL, a prompt, and optionally, an output schema.</p></li><li><p><em>LocalScraper</em>: works similarly to SmartScraper but is tailored for offline HTML files.</p></li></ul><p>The API is production-ready and includes features such as automatic proxy rotation, anti-bot solutions, and fixed output response verification. In the example below, we&#8217;ll demonstrate how to use the Markdownify service from the hosted API. While the service includes a free tier, you can always opt for the OS version.</p><h2>Burr</h2><p><a href="https://github.com/DAGWorks-Inc/burr/">Burr</a> is a lightweight Python library you use to build applications as state machines. You construct your application out of a series of <em>actions</em> (these can be either decorated functions or objects), which declare inputs from <em>state</em>, as well as <em>inputs</em> from the user. These specify custom logic (delegating to any framework), as well as instructions on how to update state. State is immutable, which allows you to inspect it at any given point. Burr handles orchestration, monitoring, persistence, etc&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aVVt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" width="723" height="65" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:65,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30725,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Hello world counter action. Gist <a href="https://gist.github.com/elijahbenizzy/c295c2578685867996577733b8005f59">here</a></figcaption></figure></div><p>You run your Burr actions as part of an application &#8211; this allows you to string them together with a series of (optionally) conditional transitions from action to action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ejRj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" width="1444" height="568" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:568,&quot;width&quot;:1444,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:119779,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Using the application builder. Gist <a href="http://238196b05d123353999b9263c3c1a76f/">here</a></figcaption></figure></div><p>Burr comes with a user-interface that enables monitoring/telemetry, as well as hooks to persist state/execute arbitrary code during execution.</p><p>You can visualize this as a flow chart, i.e. graph / state machine:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lYVz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" width="216" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;State Machine&quot;,&quot;title&quot;:&quot;State Machine&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="State Machine" title="State Machine" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>And monitor it using the local telemetry debugger:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yfZx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" width="724" height="372.93956043956047" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:750,&quot;width&quot;:1456,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:194056,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>While the above example is a simple illustration, Burr is commonly used for AI assistants (like in this example), RAG applications, and human-in-the-loop AI interfaces. See the repository <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples">examples</a> for a (more exhaustive) set of use-cases.</p><h2>LanceDB</h2><p>(From the <a href="https://github.com/lancedb/lancedb">LanceDB github</a>) LanceDB is an open-source database for vector-search built with persistent storage, which greatly simplifies retrieval, filtering and management of embeddings.</p><p>The key features of LanceDB include:</p><ul><li><p>Production-scale vector search with no servers to manage.</p></li><li><p>Store, query and filter vectors, metadata and multi-modal data (text, images, videos, point clouds, and more).</p></li><li><p>Support for vector similarity search, full-text search and SQL.</p></li><li><p>Native Python and Javascript/Typescript support.</p></li><li><p>Zero-copy, automatic versioning, manage versions of your data without needing extra infrastructure.</p></li><li><p>GPU support in building vector indices.</p></li><li><p>Ecosystem integrations with <a href="https://python.langchain.com/docs/integrations/vectorstores/lancedb/">LangChain</a>, <a href="https://gpt-index.readthedocs.io/en/latest/examples/vector_stores/LanceDBIndexDemo.html">LlamaIndex</a>, Apache-Arrow, Pandas, Polars, DuckDB and more on the way.</p></li></ul><p>LanceDB's core is written in Rust and is built using <a href="https://github.com/lancedb/lance">Lance</a>, an open-source columnar format designed for performant ML workloads. We won&#8217;t be leveraging the full extent of its capabilities in this post (scale/multi-modality) &#8212; but it makes an ideal candidate for tutorial as it is open-source and easy to get started with.</p><h1>Chat with your Webpage</h1><p>Now that we&#8217;ve gone over our tools, let&#8217;s talk about how we&#8217;ll use them! Our goal is to define a flow (Burr application) that:</p><ol><li><p>Fetches markdown from webpages (<a href="https://scrapegraphai.com/">scrapegraph</a>)</p></li><li><p>Chunks the content and stores it in a vector store (<a href="https://lancedb.com/">lancedb</a>)</p></li><li><p>Allows to query the db and generate an answer using a LLM</p></li></ol><p>We can see all of this as <em>Nodes</em> connected together in a <em>Graph</em>, where the <em>Nodes</em> are the <code>actions</code> we want to perform.</p><p>First, we will instantiate a scrapegraph client/set the logging level:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iw1f!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iw1f!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png 424w, https://substackcdn.com/image/fetch/$s_!iw1f!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png 848w, https://substackcdn.com/image/fetch/$s_!iw1f!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png 1272w, https://substackcdn.com/image/fetch/$s_!iw1f!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iw1f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png" width="718" height="153" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:153,&quot;width&quot;:718,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27122,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iw1f!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png 424w, https://substackcdn.com/image/fetch/$s_!iw1f!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png 848w, https://substackcdn.com/image/fetch/$s_!iw1f!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png 1272w, https://substackcdn.com/image/fetch/$s_!iw1f!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350deb55-27ae-4d4c-9e9c-bcdf15e84bcd_718x153.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/f7798270c55159fdaeff4ca8e66c9d82">gist</a></figcaption></figure></div><p>We will then use Burr&#8217;s functional API to define some actions. Let&#8217;s start by scraping a webpage:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G_Sh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G_Sh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png 424w, https://substackcdn.com/image/fetch/$s_!G_Sh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png 848w, https://substackcdn.com/image/fetch/$s_!G_Sh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png 1272w, https://substackcdn.com/image/fetch/$s_!G_Sh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G_Sh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png" width="716" height="262" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:262,&quot;width&quot;:716,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59773,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!G_Sh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png 424w, https://substackcdn.com/image/fetch/$s_!G_Sh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png 848w, https://substackcdn.com/image/fetch/$s_!G_Sh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png 1272w, https://substackcdn.com/image/fetch/$s_!G_Sh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a815d8a-f266-4b90-9bb5-cdeb3c08ac65_716x262.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/63b0446cd9ef3d934f69a974e9c88eb9">gist</a></figcaption></figure></div><p>Then, let&#8217;s define some helper functions/data models to hold chunks from our page in the lancedb vector store, as well as some tokenizing utility functions to parse our text:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!D24r!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!D24r!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png 424w, https://substackcdn.com/image/fetch/$s_!D24r!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png 848w, https://substackcdn.com/image/fetch/$s_!D24r!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png 1272w, https://substackcdn.com/image/fetch/$s_!D24r!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!D24r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png" width="719" height="1035" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1035,&quot;width&quot;:719,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:149562,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!D24r!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png 424w, https://substackcdn.com/image/fetch/$s_!D24r!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png 848w, https://substackcdn.com/image/fetch/$s_!D24r!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png 1272w, https://substackcdn.com/image/fetch/$s_!D24r!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fba82b8d4-a3b4-4581-8bb8-4b923153180c_719x1035.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/d7801374f21eb31717d2ec4b2ec4950f">gist</a></figcaption></figure></div><p><br>Now, let&#8217;s define our action &#8212; it creates a local vector store if it can&#8217;t find one, and adds the chunks to the chunks table. Note that this is parameterized &#8212; the user provides the URL for a webpage, which gets used for scraping:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SuFm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SuFm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png 424w, https://substackcdn.com/image/fetch/$s_!SuFm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png 848w, https://substackcdn.com/image/fetch/$s_!SuFm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png 1272w, https://substackcdn.com/image/fetch/$s_!SuFm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SuFm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png" width="719" height="355" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:355,&quot;width&quot;:719,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:60610,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SuFm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png 424w, https://substackcdn.com/image/fetch/$s_!SuFm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png 848w, https://substackcdn.com/image/fetch/$s_!SuFm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png 1272w, https://substackcdn.com/image/fetch/$s_!SuFm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc19a9b07-38c0-4d0d-87df-666b0e820e00_719x355.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/e087c4717b1a285a4970280325d0d50c#file-embed_and_store-py">gist</a></figcaption></figure></div><p>Our last action will be asking a question of the page &#8212; taking in a user query and outputting the response. This is simple &#8212; it passes the context into the OpenAI API, and returns the contents of the response.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RhyX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RhyX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png 424w, https://substackcdn.com/image/fetch/$s_!RhyX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png 848w, https://substackcdn.com/image/fetch/$s_!RhyX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png 1272w, https://substackcdn.com/image/fetch/$s_!RhyX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RhyX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png" width="719" height="659" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8b465f20-609e-4e15-9778-af841cf50686_719x659.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:659,&quot;width&quot;:719,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:107570,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!RhyX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png 424w, https://substackcdn.com/image/fetch/$s_!RhyX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png 848w, https://substackcdn.com/image/fetch/$s_!RhyX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png 1272w, https://substackcdn.com/image/fetch/$s_!RhyX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8b465f20-609e-4e15-9778-af841cf50686_719x659.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/e8203d48946e2c92a8cc49942b420c29">gist</a></figcaption></figure></div><p>To ensure visibility, we turn on opentelemetry logging (so Burr can pick up traces), and wire together our actions in an application!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!I7gN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!I7gN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png 424w, https://substackcdn.com/image/fetch/$s_!I7gN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png 848w, https://substackcdn.com/image/fetch/$s_!I7gN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png 1272w, https://substackcdn.com/image/fetch/$s_!I7gN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!I7gN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png" width="700" height="441" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/893380d4-55ab-49f7-9aad-188263aa8404_700x441.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:441,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:63744,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!I7gN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png 424w, https://substackcdn.com/image/fetch/$s_!I7gN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png 848w, https://substackcdn.com/image/fetch/$s_!I7gN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png 1272w, https://substackcdn.com/image/fetch/$s_!I7gN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F893380d4-55ab-49f7-9aad-188263aa8404_700x441.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/068ac74ae42220015298fa0e1e29001d">gist</a></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wyp4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wyp4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png 424w, https://substackcdn.com/image/fetch/$s_!wyp4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png 848w, https://substackcdn.com/image/fetch/$s_!wyp4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png 1272w, https://substackcdn.com/image/fetch/$s_!wyp4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wyp4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png" width="378" height="317" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:317,&quot;width&quot;:378,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:19485,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wyp4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png 424w, https://substackcdn.com/image/fetch/$s_!wyp4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png 848w, https://substackcdn.com/image/fetch/$s_!wyp4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png 1272w, https://substackcdn.com/image/fetch/$s_!wyp4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf26534-1ae0-4905-84e0-2078a296e4a3_378x317.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding graph generated with Burr &#8212; if you run in a jupyter notebook, this will display when the app object is the last in a cell.</figcaption></figure></div><p>Finally, we can run it, passing the query and the webpage URL: </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WJcw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WJcw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png 424w, https://substackcdn.com/image/fetch/$s_!WJcw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png 848w, https://substackcdn.com/image/fetch/$s_!WJcw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png 1272w, https://substackcdn.com/image/fetch/$s_!WJcw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WJcw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png" width="723" height="220" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:220,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27943,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WJcw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png 424w, https://substackcdn.com/image/fetch/$s_!WJcw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png 848w, https://substackcdn.com/image/fetch/$s_!WJcw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png 1272w, https://substackcdn.com/image/fetch/$s_!WJcw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91d12612-a9e2-41d7-947d-73a1c3a05011_723x220.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/4d17cbd285949d0fafe7442b4e469483">gist</a></figcaption></figure></div><p>As you can see, it is completely correct:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZsNU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZsNU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png 424w, https://substackcdn.com/image/fetch/$s_!ZsNU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png 848w, https://substackcdn.com/image/fetch/$s_!ZsNU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png 1272w, https://substackcdn.com/image/fetch/$s_!ZsNU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZsNU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png" width="726" height="222" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:222,&quot;width&quot;:726,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:35106,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZsNU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png 424w, https://substackcdn.com/image/fetch/$s_!ZsNU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png 848w, https://substackcdn.com/image/fetch/$s_!ZsNU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png 1272w, https://substackcdn.com/image/fetch/$s_!ZsNU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F965dffe4-de35-4eb4-ae3d-6df95dc73977_726x222.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/391c6b09810eea69d79177034acb3526#file-results-md">gist</a></figcaption></figure></div><p>To debug, we can examine the trace in the <a href="https://blog.dagworks.io/p/burr-ui">Burr UI</a> &#8212; you can see every step of the process, as well as attributes/traces for the lance/OpenAI queries:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!N_2L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!N_2L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png 424w, https://substackcdn.com/image/fetch/$s_!N_2L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png 848w, https://substackcdn.com/image/fetch/$s_!N_2L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png 1272w, https://substackcdn.com/image/fetch/$s_!N_2L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!N_2L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png" width="1620" height="862" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:862,&quot;width&quot;:1620,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:111254,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!N_2L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png 424w, https://substackcdn.com/image/fetch/$s_!N_2L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png 848w, https://substackcdn.com/image/fetch/$s_!N_2L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png 1272w, https://substackcdn.com/image/fetch/$s_!N_2L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5caf4a2-0692-4d49-90dd-c761010703f5_1620x862.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Examining the high-level workflow in the Burr UI</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-13B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-13B!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png 424w, https://substackcdn.com/image/fetch/$s_!-13B!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png 848w, https://substackcdn.com/image/fetch/$s_!-13B!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png 1272w, https://substackcdn.com/image/fetch/$s_!-13B!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-13B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png" width="1456" height="777" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:777,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:100746,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-13B!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png 424w, https://substackcdn.com/image/fetch/$s_!-13B!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png 848w, https://substackcdn.com/image/fetch/$s_!-13B!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png 1272w, https://substackcdn.com/image/fetch/$s_!-13B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94b92f55-6c49-4c3d-9094-5a0b5f49f8cd_1624x867.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Attributes logged through Burr&#8217;s <a href="https://github.com/DAGWorks-Inc/burr">OpenTelemetry integration</a></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uFj2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uFj2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png 424w, https://substackcdn.com/image/fetch/$s_!uFj2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png 848w, https://substackcdn.com/image/fetch/$s_!uFj2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png 1272w, https://substackcdn.com/image/fetch/$s_!uFj2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uFj2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png" width="1456" height="799" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f95b850b-5a4f-427e-b975-2378d822925f_1630x894.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:799,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:117945,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uFj2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png 424w, https://substackcdn.com/image/fetch/$s_!uFj2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png 848w, https://substackcdn.com/image/fetch/$s_!uFj2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png 1272w, https://substackcdn.com/image/fetch/$s_!uFj2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff95b850b-5a4f-427e-b975-2378d822925f_1630x894.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Examining the application state at any given point in time</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nqXv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nqXv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png 424w, https://substackcdn.com/image/fetch/$s_!nqXv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png 848w, https://substackcdn.com/image/fetch/$s_!nqXv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png 1272w, https://substackcdn.com/image/fetch/$s_!nqXv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nqXv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png" width="1456" height="811" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:811,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:85351,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nqXv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png 424w, https://substackcdn.com/image/fetch/$s_!nqXv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png 848w, https://substackcdn.com/image/fetch/$s_!nqXv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png 1272w, https://substackcdn.com/image/fetch/$s_!nqXv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95b85cf2-b2a4-4cf7-9260-66c0b90e616a_1629x907.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Burr&#8217;s <em>insights</em> capability to view token cost across a workflow</figcaption></figure></div><h1>Wrapping Up</h1><p>While we went over a fairly simple example, there&#8217;s a lot more we can do. In particular, we can:</p><ol><li><p>Bypass loading the page if we already have loaded it</p></li><li><p>Provide more interactive query tooling &#8212; ask multiple questions of the same page</p></li><li><p>Log to a Burr cloud instance to get persistence telemetry</p></li><li><p>Additionally, log to any opentelemetry provider</p></li><li><p>Use SmartScraper to extract a summary and some keywords for each chunks to use as metadata in the vector store, to improve retrieval</p></li><li><p>Semantic crawling to fetch multiple webpages from the same domain and chat with the whole website</p></li></ol><p>If you&#8217;re interested in reading more, or want to get started on these, don&#8217;t hesitate to reach out! Here are some more resources to get you started:</p><ul><li><p>&#128640; Get your API Key: <a href="https://dashboard.scrapegraphai.com/">ScrapeGraphAI Dashboard</a></p></li><li><p>&#128025; GitHub: <a href="https://github.com/scrapegraphai">ScrapeGraphAI GitHub</a></p></li><li><p>&#9193; Burr: <a href="https://github.com/DAGWorks-Inc/burr">Github</a></p></li><li><p>&#128738;&#65039; LanceDB: <a href="https://github.com/lancedb/lancedb">Github</a></p></li></ul><p></p><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Parallel Fault-Tolerant Agents with Burr/Ray]]></title><description><![CDATA[Leverage Burr's new parallelism capabilities to build fault-tolerant, distributed multi-agent systems]]></description><link>https://blog.dagworks.io/p/parallel-fault-tolerant-agents-with</link><guid isPermaLink="false">https://blog.dagworks.io/p/parallel-fault-tolerant-agents-with</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Thu, 02 Jan 2025 16:18:34 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/fb1196c8-655f-422b-908e-5c3b16c2bed3_876x566.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Note: This is a continuation of our <a href="https://blog.dagworks.io/p/parallel-multi-agent-workflows-with">previous post</a> on parallel agents. While we conduct a brief overview, we recommend reading it for more context. If you have read it, skip to the <em>Parallelism Improvements </em>section<em>.</em></p><h1>Introduction</h1><p>Many AI applications start off simple &#8211; you query some hosted model, do a little bit of prompt engineering, process/store/index the result, and stream it back to the user. You model this as a simple <a href="https://blog.dagworks.io/p/burr-develop-stateful-ai-applications">ping-pong application</a> &#8211; (AI &#8594; Human &#8594; AI, etc&#8230;). Inevitably, as you hit some success, you will need more from your application. The natural next step is to enable it to <a href="https://blog.dagworks.io/p/agentic-design-pattern-1-tool-calling">call tools</a>, or dive into a more complicated research question (E.G. with chain of thought prompting). This is when it turns into an <em>agent</em> &#8211; an AI system that <em><a href="https://www.anthropic.com/research/building-effective-agents">dynamically directs their own processes and tool-usage</a></em>, either with or without human input. An agent is often modeled by a graph with state &#8211; it has a set of capabilities and needs to dynamically decide the order.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack. Subscribe to receive the latest updates!</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>As your agent&#8217;s capabilities grow in complexity, you likely start to realize that it needs to execute multiple tasks at once &#8211; generate several candidates for user/LLM selection, leverage various tools simultaneously, etc&#8230; While you will still model this as a graph, you end up being in multiple states at once, and have to worry about distributing the computation and coordinating state between tasks. Furthermore, you have to now deal with a host of additional challenges &#8212; what happens if one or more of your agents fails, or disconnects from the parent processes? How do you provision specific resources and orchestrate execution in a distributed system?</p><p>In this post we show how the Burr library helps you solve these problems. In particular, we will be executing parallel sub-agents/workflows on Ray and persisting the state to enable easy restart from failure. We will:</p><ol><li><p>Dig into Burr/why we built it</p></li><li><p>Briefly walk through one of Burr&#8217;s Parallelism APIs and show an example of generating poems</p></li><li><p>Show how to improve the implementation of parallelism in two ways</p><ol><li><p>Improve reliability through checkpointing</p></li><li><p>Distributed agent calls on Ray</p></li></ol></li><li><p>Wrap up &#8211; talk through other applications/directions for future work.</p></li></ol><h1>Burr</h1><p><a href="https://github.com/DAGWorks-Inc/burr/">Burr</a> is a lightweight Python library you use to build applications as state machines. You construct your application out of a series of <em>actions</em> (these can be either decorated functions or objects), which declare inputs from <em>state</em>, as well as <em>inputs</em> from the user. These specify custom logic (delegating to any framework), as well as instructions on how to update state. State is immutable, which allows you to inspect it at any given point. Burr handles orchestration, monitoring, persistence, etc&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aVVt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" width="723" height="65" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:65,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30725,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Hello world counter action. Gist <a href="https://gist.github.com/elijahbenizzy/c295c2578685867996577733b8005f59">here</a></figcaption></figure></div><p>You run your Burr actions as part of an application &#8211; this allows you to string them together with a series of (optionally) conditional transitions from action to action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ejRj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" width="1444" height="568" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:568,&quot;width&quot;:1444,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:119779,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Using the application builder. Gist <a href="http://238196b05d123353999b9263c3c1a76f/">here</a></figcaption></figure></div><p>Burr comes with a user-interface that enables monitoring/telemetry, as well as hooks to persist state/execute arbitrary code during execution.</p><p>You can visualize this as a flow chart, i.e. graph / state machine:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lYVz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" width="216" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;State Machine&quot;,&quot;title&quot;:&quot;State Machine&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="State Machine" title="State Machine" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>And monitor it using the local telemetry debugger:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yfZx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" width="724" height="372.93956043956047" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:750,&quot;width&quot;:1456,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:194056,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>While the above example is a simple illustration, Burr is commonly used for AI assistants (like in this example), RAG applications, and human-in-the-loop AI interfaces. See the repository <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples">examples</a> for a (more exhaustive) set of use-cases.</p><h2>A multilayered API for parallelism</h2><p>To allow for agent-level parallelism, burr uses recursion as a core primitive. No matter how small the sub-application is, each parallel branch gets run in its entirety under the context of a  parent action, as a set of separate, simultaneous burr applications. Conceptually, parallelism in Burr uses a simple <a href="https://en.wikipedia.org/wiki/MapReduce">map reduce</a> pattern.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OvKp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OvKp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 424w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 848w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 1272w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OvKp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png" width="724" height="671.620578778135" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:577,&quot;width&quot;:622,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;../../_images/parallelism.png&quot;,&quot;title&quot;:&quot;../../_images/parallelism.png&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="../../_images/parallelism.png" title="../../_images/parallelism.png" srcset="https://substackcdn.com/image/fetch/$s_!OvKp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 424w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 848w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 1272w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Map to a set of actions/sub-applications with their own state, wait for them to complete, then join the results to form the next state for downstream consumption</figcaption></figure></div><p>While there are many ways to specify the sub-actions (see the <a href="https://burr.dagworks.io/concepts/parallelism/">docs on parallelism</a>), we will be showing an example of the <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.MapStates">MapStates</a> API. The user implements a class that takes the state in as an input, splits it out into multiple separate states (one for each task), runs each of those, and joins the results. </p><p>To demonstrate, let&#8217;s write an agent that takes a prompt and generates a poem in multiple styles from that prompt. To generate the poem, it will delegate to a write/edit loop that does a few iterations to improve the poem.</p><p>Our overall structure will look like this &#8211; note that this graph does not include the details of the sub-applications:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4z2b!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4z2b!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 424w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 848w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 1272w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4z2b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png" width="594" height="322" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cc978b37-341e-4124-a087-611d92fac965_594x322.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:322,&quot;width&quot;:594,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21678,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!4z2b!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 424w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 848w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 1272w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">A simple three-node flowchart &#8212; note that generate_all_poems is actually a recursive sub-application!</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mmZj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mmZj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 424w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 848w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 1272w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mmZj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png" width="137" height="234" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b0411fba-9a62-4185-8eb6-94c779902a97_137x234.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:234,&quot;width&quot;:137,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:10361,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!mmZj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 424w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 848w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 1272w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">The flowchart for generate_all_poems</figcaption></figure></div><p>The user provides workflow-level parameters (poem_types, poem_subject, and max_drafts). From these, we manipulate the state, and generate a sub-application from each step. The most interesting part is the distribution &#8212; E.G. the use of MapStates. The code looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yT_R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yT_R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 424w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 848w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 1272w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yT_R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png" width="1456" height="1610" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/daa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1610,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:809830,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yT_R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 424w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 848w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 1272w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Creating one sub-application for each poem type, with a state in which the poem type has been bound appropriately. We specify the action it runs (the write/edit loop draft). The reduce function then joins them together, gathering all final drafts to present to the user. Corresponding <a href="https://gist.github.com/elijahbenizzy/58ad4ab9dddc0b4d2f70ba54320d3e7b">gist</a>.</figcaption></figure></div><p>To tie this together, we&#8217;ll include this action as part of our overall application: </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!z_X8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!z_X8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 424w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 848w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 1272w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!z_X8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png" width="1396" height="480" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:480,&quot;width&quot;:1396,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:92892,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!z_X8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 424w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 848w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 1272w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/2eb47aee2bde4c02d87c60ec04b6cfc5">gist</a></figcaption></figure></div><p>Now we&#8217;ve got all we need to run! We execute as we would any normal application &#8211; by default, the sub-applications will be spawned in threads, which will be joined when they are done. This is easy to follow in the UI &#8211; you can see an application with multiple child applications.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yHNs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yHNs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 424w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 848w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 1272w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yHNs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png" width="1456" height="312" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:312,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:189608,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!yHNs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 424w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 848w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 1272w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can also click to expand them individually:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xLpW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xLpW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 424w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 848w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 1272w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xLpW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png" width="1456" height="505" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:505,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:300038,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!xLpW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 424w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 848w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 1272w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And view state for the sub-applications inline (in case you wanted an in-depth analysis of a limerick based on a state machine&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Hgla!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hgla!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 424w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 848w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 1272w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hgla!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png" width="1456" height="815" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d36d8250-0314-426e-ae89-852cb0798b98_1698x950.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:815,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:687559,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Hgla!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 424w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 848w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 1272w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>When you click on one of the child applications, you will see a link back to the spawning parent: </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MeML!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MeML!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 424w, https://substackcdn.com/image/fetch/$s_!MeML!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 848w, https://substackcdn.com/image/fetch/$s_!MeML!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 1272w, https://substackcdn.com/image/fetch/$s_!MeML!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MeML!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png" width="1456" height="195" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:195,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:316625,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!MeML!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 424w, https://substackcdn.com/image/fetch/$s_!MeML!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 848w, https://substackcdn.com/image/fetch/$s_!MeML!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 1272w, https://substackcdn.com/image/fetch/$s_!MeML!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can also <a href="https://blog.dagworks.io/p/annotating-data-in-burr">annotate</a> the workflow, and track additional data with <a href="https://blog.dagworks.io/p/trace-all-parts-of-your-agenticai">opentelemetry</a>, giving you full visibility into the way your sub-applications function.</p><h1>Parallelism improvements</h1><p>While Burr has capabilities to make launching, waiting for, and joining tasks easy, it additionally provides two advanced APIs to make parallelizing more powerful.</p><ol><li><p>Persistence of sub-agents/workflows for fault-tolerance with checkpointing</p></li><li><p>Customization of execution to run on a task orchestrator (such as Ray)</p></li></ol><h1>Fault-tolerance with inherited persisters</h1><p>If the sub-applications fail, we will need to start where it left off &#8211; either for a retry or a manual adjustment (of state/code). To enable this, Burr leverages the <a href="https://burr.dagworks.io/concepts/state-persistence/">persister framework</a>. Specifically, it allows child agents/workflows to inherit their parent&#8217;s persisters. This is enabled by default in the <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.MapActions">MapActions</a>, <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.MapStates">MapStates</a>, and <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.MapActionsAndStates">MapActionsAndStates</a> interfaces. It works as follows:</p><ol><li><p>The parent task instantiates a set of sub-applications, with a stable ID (this is currently dependent on the task order, but will be customizable in the future)</p></li><li><p>Each sub-application clones the parent application, creating a new application ID with a stable hash of the parent ID and the unique child ID</p></li><li><p>These clones also copy the persister object that the parent has &#8211; ensuring that the configuration matches</p></li><li><p>When sub-applications are executed, they persist state according to the persister they instantiated</p></li></ol><p>Thus when an application fails &#8211; either when the parent task exits early, when a child fails randomly, or when the connection is lost, it can pick up from where it left off on the next instantiation with the same state. All tasks that are complete will effectively be no-ops (relaunched from a final state), and those that are in progress or have not started will resume at the latest state they persisted.</p><p>To ensure that this works, you need to add persistence to your parent application with the <a href="https://burr.dagworks.io/reference/application/#burr.core.application.ApplicationBuilder.initialize_from">initialize_from</a> API &#8211; the settings will cascade to the child apps, so that if a parent knows to start from where it left off, the child will as well.</p><p>Practically, this looks like this (using the <a href="http://burr.dagworks.io/reference/persister/#burr.core.persistence.SQLitePersister">SQLite persister</a> for simplicity &#8212; if you&#8217;re doing true concurrent systems you&#8217;ll likely want a more multi-tennant database):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4TjO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4TjO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png 424w, https://substackcdn.com/image/fetch/$s_!4TjO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png 848w, https://substackcdn.com/image/fetch/$s_!4TjO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png 1272w, https://substackcdn.com/image/fetch/$s_!4TjO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4TjO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png" width="712" height="417" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:417,&quot;width&quot;:712,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:66088,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4TjO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png 424w, https://substackcdn.com/image/fetch/$s_!4TjO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png 848w, https://substackcdn.com/image/fetch/$s_!4TjO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png 1272w, https://substackcdn.com/image/fetch/$s_!4TjO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d1097b5-ddfb-4d3a-9f53-3319127952d2_712x417.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/5e76ee60b93054d8406787a6074f72bd">gist</a></figcaption></figure></div><p>Note that you can further customize the persistence of child apps by overriding the <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.MapActionsAndStates.state_initializer">state_initializer</a> or <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.MapActionsAndStates.state_persister">state_persister</a> implementation in your subclasses.</p><p>If you run a regularly failing application in the UI you will see it start from where it left off and eventually complete! In this case we&#8217;ve just stuck something flaky in a while loop&#8230;</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bGal!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bGal!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png 424w, https://substackcdn.com/image/fetch/$s_!bGal!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png 848w, https://substackcdn.com/image/fetch/$s_!bGal!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png 1272w, https://substackcdn.com/image/fetch/$s_!bGal!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bGal!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png" width="1456" height="330" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:330,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:262566,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bGal!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png 424w, https://substackcdn.com/image/fetch/$s_!bGal!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png 848w, https://substackcdn.com/image/fetch/$s_!bGal!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png 1272w, https://substackcdn.com/image/fetch/$s_!bGal!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d2f0f82-fb46-4b23-959a-1e12d9de0ba5_2252x510.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can also use the Burr UI to dig into the failure reasons with the full stack trace:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!W4VA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!W4VA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png 424w, https://substackcdn.com/image/fetch/$s_!W4VA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png 848w, https://substackcdn.com/image/fetch/$s_!W4VA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png 1272w, https://substackcdn.com/image/fetch/$s_!W4VA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!W4VA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png" width="1456" height="715" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:715,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:753852,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!W4VA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png 424w, https://substackcdn.com/image/fetch/$s_!W4VA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png 848w, https://substackcdn.com/image/fetch/$s_!W4VA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png 1272w, https://substackcdn.com/image/fetch/$s_!W4VA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f9c5641-f888-48f2-80b7-a9b1a050ae5d_2518x1237.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Custom Execution with Ray</h1><p>Subtasks in Burr are, by default, managed with a simple concurrent threadpool (using <a href="https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor">concurrent.futures.ThreadPoolExecutor</a>). That said, you can actually customize execution with any implementation of <a href="https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.Executor">concurrent.futures.Executor</a>. To run in Ray, Burr provides an implementation that submits Ray tasks on the user&#8217;s behalf, as part of the ray plugin.</p><p>To enable, all you need to do is call <a href="https://burr.dagworks.io/reference/application/#burr.core.application.ApplicationBuilder.with_parallel_executor">with_parallel_executor</a> on the application builder, passing it a factory function that instantiates the executor (in this case, the constructor will suffice):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AhFG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AhFG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png 424w, https://substackcdn.com/image/fetch/$s_!AhFG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png 848w, https://substackcdn.com/image/fetch/$s_!AhFG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png 1272w, https://substackcdn.com/image/fetch/$s_!AhFG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AhFG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png" width="1356" height="1058" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1058,&quot;width&quot;:1356,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:479910,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AhFG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png 424w, https://substackcdn.com/image/fetch/$s_!AhFG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png 848w, https://substackcdn.com/image/fetch/$s_!AhFG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png 1272w, https://substackcdn.com/image/fetch/$s_!AhFG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59a41bbd-76db-4ea5-b9db-6bd068aa9e17_1356x1058.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Same as the above, except we&#8217;re calling out to the ray executor. Don&#8217;t use Ray + SQLite in production together. Corresponding <a href="https://gist.github.com/elijahbenizzy/1426ef5cba174395e0c6c6629a163490">gist</a>. </figcaption></figure></div><p>When you run your application, all sub-applications will be tasks on ray! They will write back to the same persister configuration (copied on a per-task basis), so ensure that if you&#8217;re doing more than the local testing we&#8217;re doing here, you use a truly distributed persister (<a href="https://burr.dagworks.io/reference/persister/#burr.integrations.persisters.b_redis.RedisBasePersister">redis</a>, <a href="https://burr.dagworks.io/reference/persister/#burr.integrations.persisters.postgresql.PostgreSQLPersister">postgres</a>, <a href="https://burr.dagworks.io/reference/persister/#burr.integrations.persisters.b_mongodb.MongoDBBasePersister">mongodb</a>, etc&#8230;). Note you will also want to use the <a href="https://github.com/DAGWorks-Inc/burr/blob/main/burr/tracking/server/s3/README.md">s3 based tracking client</a>, or leverage a distributed filesystem, as your local filesystem will likely be unavailable on remote hosts.</p><h1>Wrapping Up</h1><p>In the prior post, we outlined Burr&#8217;s approach to building parallel agents &#8211; demonstrating a few of the APIs to make specifying tasks and joining the results easy. In this post we dug into two more advanced features &#8211; ensuring your agent is fault tolerant with checkpointing, and distributing out execution with Ray. While we did not demonstrate further extensions, Burr enables you to build your own concurrent.futures.Executor to run on whatever distributed system you want (<a href="https://www.dask.org/">dask</a>, <a href="http://run.house">runhouse</a>, etc&#8230;), or build your own custom persister to match the schema in your DB (please contribute these back if you think they might be general purpose!)</p><h2>Next steps</h2><p>While the API is stable and production-ready, we have a host of improvements we are planning. In particular, we want to:</p><ol><li><p>Add customizable IDs for sub-applications, both so you can specify equivalence between runs and observe in the UI</p></li><li><p>Add additional asynchronous-based parallelism capabilities &#8211; while we handle parallelism with asyncio.gather, we will extend customizable execution capabilities to async as well (E.G. allow async execution on Ray).</p></li><li><p>Consider providing a higher-level execution API (than concurrent.futures) to specify more burr-specific concerns (maximum workers, serialization concerns, messages passed between actions using event-driven/actor model, etc&#8230;)</p></li><li><p>Add the ability to execute any task (not just parallel sub-actions) on a remote host using the same executor</p></li></ol><p>And we&#8217;re building quickly! If you have a need for these (or other ideas), please reach out. We&#8217;re happy to chat.</p><h2>Further Reading</h2><p>If you&#8217;re interested in learning more about Burr:</p><ul><li><p>Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a> for help or if you have questions!</p></li><li><p><a href="https://www.youtube.com/@dagworks-inc">Subscribe to our youtube</a> to watch some in-depth tutorials/overviews</p></li><li><p>Star our <a href="https://github.com/dagworks-inc/burr">Github repository</a> if you like what you see</p></li><li><p>Check out the recent <a href="https://burr.dagworks.io/reference/integrations/opentelemetry/">OpenTelemetry integration</a> for additional observability</p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Test Driven Development (TDD) of LLM / Agent Applications with pytest]]></title><description><![CDATA[An introduction to using pytest with Burr to build reliable AI software.]]></description><link>https://blog.dagworks.io/p/test-driven-development-tdd-of-llm</link><guid isPermaLink="false">https://blog.dagworks.io/p/test-driven-development-tdd-of-llm</guid><dc:creator><![CDATA[DAGWorks Inc.]]></dc:creator><pubDate>Mon, 30 Dec 2024 17:15:34 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Shipping on more than vibes</h1><p>To build reliable AI software, i.e. wrangle the non-determinism inherent with LLMs, one must graduate from shipping on &#8220;vibes&#8221; to instead invest in building systematic evaluations. Much like unit test suites ensure standard software is reliable, LLM-powered software also need a suite of tests to directionally assess or evaluate reliability. The hard part is that these tests aren&#8217;t as simple as those for regular software.</p><p>In this post we show <em>one possible approach to building an LLM application test suite and using it in a test driven manner</em> - with <a href="https://docs.pytest.org/en/stable/">pytest</a>! If you aren&#8217;t using python, don&#8217;t use pytest, or don&#8217;t use Burr, this post will still be helpful at a high level &#8212; you can replicate the learnings with other testing libraries/systems. Overall, this post should leave you with:</p><ol><li><p>A mental picture of how to iterate on LLM / agent applications.</p></li><li><p>What pytest is and how to use it.</p></li><li><p>What type of extension we need to make pytest work in the LLM / Agent use case.</p></li><li><p>Features of <a href="https://github.com/dagworks-inc/burr">Burr</a> that can help with pytest and creating more reliable AI software.</p></li></ol><blockquote><p>For the code that&#8217;s featured here you can also find it under this <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/pytest">pytest example in the Burr repository</a>.</p></blockquote><blockquote><p>Side note: if this topic interests you <a href="https://www.linkedin.com/in/hugo-bowne-anderson-045939a5?originalSubdomain=au">Hugo Bowne-Anderson</a> and <a href="https://www.linkedin.com/in/skrawczyk/">Stefan Krawczyk</a> have a <a href="https://maven.com/hugo-stefan/building-llm-apps-ds-and-swe-from-first-principles?utm_medium=clp_share_link&amp;utm_source=maven">Maven Course: &#8220;Building LLM Applications for Data Scientists and Software Engineers&#8221;</a> starting January 6th covering content like this to help you ship reliable AI applications.</p></blockquote><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/p/test-driven-development-tdd-of-llm?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/p/test-driven-development-tdd-of-llm?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><p>This post is a long one, here&#8217;s an outline of this post&#8217;s structure to help you navigate it (or use the left hand side navigation bar of substack!), e.g. skip the introduction to pytest if you already know it:</p><ol><li><p>Why pytest &amp; Burr.</p></li><li><p>The high level SDLC with Burr &amp; pytest.</p></li><li><p>pytest constructs &amp; what needs to be adjusted to use pytest.</p></li><li><p>Burr&#8217;s functionality to help create pytest tests &amp; a sketch of the TDD loop.</p></li><li><p>Some tips and then links to a full example.</p></li><li><p>Summary &amp; FAQ.</p></li></ol><h2>Why <a href="https://docs.pytest.org/en/stable/">pytest</a>?</h2><p>Pytest is a very popular python library for functionally testing python software. Rather than introduce <em>a new tool</em>, why not use what&#8217;s already available, and something you probably already know how to use? We think that reusing a well known tool will enable a more streamlined iteration loop (read on for more details). </p><p>Note: While pytest is very extensible due to its <em><a href="https://docs.pytest.org/en/stable/how-to/index.html#plugins">plugins</a></em> framework, we&#8217;ll only be scratching the surface in this post. There are a few ways you could achieve the desired end result. If you come up with something better, please share it!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/subscribe?"><span>Subscribe now</span></a></p><h2>Why <a href="https://github.com/dagworks-inc/burr">Burr</a>?</h2><p>When building LLM Applications / Agents, you get to choose <em>how</em> you build. Do you do everything yourself or do you use a framework? Burr allows you to take both paths. Rather than hide LLM calls (e.g. LangChain), or only require prompts to build agents (e.g. CrewAI), Burr aims to be really good at allowing you to &#8220;glue&#8221; whatever logic together you need in a standard manner, in a way where iteration is fast and observability is included. This means that you can choose to control all LLM API calls yourself, use other frameworks like <a href="https://github.com/deepset-ai/haystack">Haystack</a>, or do both, when building LLM applications / Agents with Burr. Burr&#8217;s strengths are that it solves the pain of (a) how to structure your code for fast iteration, (b) instrumenting for observability.</p><blockquote><p>If you can draw a flowchart of your LLM application / Agent, then your code structure in Burr should mirror it.</p></blockquote><h3>What is Burr?</h3><p><a href="https://github.com/DAGWorks-Inc/burr/">Burr</a> is a lightweight Python library you use to build applications modeled similarly to state machines. You construct your application out of a series of <em>actions</em> (these can be either decorated functions or objects), which declare inputs from <em>state</em>, as well as <em>inputs</em> from the user. These specify custom logic (delegating to any framework), as well as instructions on how to update state. State is immutable, which allows you to inspect it at any given point. Burr handles orchestration, monitoring, persistence, etc&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aVVt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" width="723" height="65" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:65,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30725,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Hello world counter action. Gist <a href="https://gist.github.com/elijahbenizzy/c295c2578685867996577733b8005f59">here</a></figcaption></figure></div><p>You run your Burr actions as part of an application &#8211; this allows you to string them together with a series of (optionally) conditional transitions from action to action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ejRj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" width="1444" height="568" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:568,&quot;width&quot;:1444,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:119779,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Using the application builder. Gist <a href="http://238196b05d123353999b9263c3c1a76f/">here</a></figcaption></figure></div><p>Burr comes with a user-interface that enables monitoring/telemetry, as well as hooks to persist state/execute arbitrary code during execution.</p><p>You can visualize this as a flow chart, i.e. graph / state machine:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lYVz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" width="216" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;State Machine&quot;,&quot;title&quot;:&quot;State Machine&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="State Machine" title="State Machine" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>And monitor it using the local telemetry debugger:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yfZx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" width="724" height="372.93956043956047" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:750,&quot;width&quot;:1456,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:194056,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>While the above example is a simple illustration, Burr is commonly used for AI assistants (like in this example), RAG applications, and human-in-the-loop AI interfaces. See the repository <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples">examples</a> for a (more exhaustive) set of use-cases.</p><h1>A SDLC with Burr and pytest</h1><p>With the rise of LLMs, the regular software development cycle (SDLC) doesn&#8217;t really work. Why? Well you can&#8217;t write a simple test, you need to curate (and continually update) a suite of tests or a data set.  This means you need to continually gather data to know how well your application is working and curate existing tests when requirements / the world changes. To put what we&#8217;ll present in perspective, here&#8217;s an example software development lifecycle (SDLC) with Burr and pytest:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6TMd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6TMd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png 424w, https://substackcdn.com/image/fetch/$s_!6TMd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png 848w, https://substackcdn.com/image/fetch/$s_!6TMd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png 1272w, https://substackcdn.com/image/fetch/$s_!6TMd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6TMd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png" width="710" height="352" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:352,&quot;width&quot;:710,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:52269,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6TMd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png 424w, https://substackcdn.com/image/fetch/$s_!6TMd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png 848w, https://substackcdn.com/image/fetch/$s_!6TMd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png 1272w, https://substackcdn.com/image/fetch/$s_!6TMd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0be84dc-a87f-4cd4-a684-67ffdcde579d_710x352.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The two loops of LLM / Agent / GenAI app development. See the split on where you use Burr vs pytest.</figcaption></figure></div><p>While we don't cover everything in the diagram, in this post we specifically show how to do most of the Test Driven Development (TDD) loop:</p><ol><li><p>Create a test case.</p></li><li><p>Run the test case.</p></li><li><p>Create a dataset.</p></li><li><p>Show how you might construct evaluation logic to evaluate the output of your agent / augmented LLM / application.</p></li></ol><p>In terms of the rest of this post, we&#8217;ll introduce pytest for those that are new to it, and then explain how we can adopt it for our TDD cycle to wrangle evaluating non-deterministic outputs, i.e. the outputs of an LLM / agent.</p><h1>pytest Introduction</h1><h3>pytest basics</h3><p>We like <a href="https://pytest.org/">pytest</a> because we think it's simpler than the unittest module python comes with. To use it you need to install it first:</p><pre><code><code>pip install pytest</code></code></pre><p>Then to define a test it's just a function that starts with <code>test_</code>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OGyi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OGyi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png 424w, https://substackcdn.com/image/fetch/$s_!OGyi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png 848w, https://substackcdn.com/image/fetch/$s_!OGyi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png 1272w, https://substackcdn.com/image/fetch/$s_!OGyi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OGyi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png" width="508" height="186.010101010101" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:145,&quot;width&quot;:396,&quot;resizeWidth&quot;:508,&quot;bytes&quot;:20339,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OGyi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png 424w, https://substackcdn.com/image/fetch/$s_!OGyi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png 848w, https://substackcdn.com/image/fetch/$s_!OGyi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png 1272w, https://substackcdn.com/image/fetch/$s_!OGyi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4313f8b2-4803-41ff-88f4-83127a79cfca_396x145.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_my_agent-py">Gist</a></figcaption></figure></div><p>Yep - no classes to deal with. Just a function that starts with <code>test_</code>. Then to run it:</p><pre><code><code>pytest test_my_agent.py</code></code></pre><p>Boom, you're testing!</p><h3>Parameterizing Tests</h3><p>We can also parameterize tests to run the same test with different inputs. This comes in handy as we build up data points to evaluate our agent  / llm calls. Each input is then an individual test that can error. Here's an example:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CYls!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CYls!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png 424w, https://substackcdn.com/image/fetch/$s_!CYls!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png 848w, https://substackcdn.com/image/fetch/$s_!CYls!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png 1272w, https://substackcdn.com/image/fetch/$s_!CYls!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CYls!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png" width="664" height="302" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:302,&quot;width&quot;:664,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:53634,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CYls!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png 424w, https://substackcdn.com/image/fetch/$s_!CYls!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png 848w, https://substackcdn.com/image/fetch/$s_!CYls!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png 1272w, https://substackcdn.com/image/fetch/$s_!CYls!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ded12df-8dbb-42d6-b12c-04a7ca1f8192_664x302.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_my_agent2-py">Gist</a></figcaption></figure></div><h3>pytest fixtures</h3><p>Another useful construct to know are pytest fixtures. A &#8220;fixture&#8221; is a function that is used to provide a fixed baseline upon which tests can reliably and repeatedly execute. They set up preconditions for a test, such as creating test data, initializing objects, or establishing database connections, etc&#8230; To create one in pytest, you declare a function and annotate it:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LNYW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LNYW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png 424w, https://substackcdn.com/image/fetch/$s_!LNYW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png 848w, https://substackcdn.com/image/fetch/$s_!LNYW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png 1272w, https://substackcdn.com/image/fetch/$s_!LNYW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LNYW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png" width="585" height="161" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:161,&quot;width&quot;:585,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27902,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LNYW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png 424w, https://substackcdn.com/image/fetch/$s_!LNYW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png 848w, https://substackcdn.com/image/fetch/$s_!LNYW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png 1272w, https://substackcdn.com/image/fetch/$s_!LNYW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2179ffc7-8711-4fd4-9dbc-a6fbe3832fe4_585x161.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-show_fixture-py">Gist</a></figcaption></figure></div><p>To use it, one just needs to &#8220;declare&#8221; it as a function parameter for a test.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gDBg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gDBg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png 424w, https://substackcdn.com/image/fetch/$s_!gDBg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png 848w, https://substackcdn.com/image/fetch/$s_!gDBg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png 1272w, https://substackcdn.com/image/fetch/$s_!gDBg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gDBg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png" width="585" height="180" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:180,&quot;width&quot;:585,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37166,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gDBg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png 424w, https://substackcdn.com/image/fetch/$s_!gDBg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png 848w, https://substackcdn.com/image/fetch/$s_!gDBg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png 1272w, https://substackcdn.com/image/fetch/$s_!gDBg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F44e467c5-cb2e-4579-9ec9-99ec253d12a4_585x180.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-show_fixture-py">Gist</a></figcaption></figure></div><p>We will both be constructing our own pytest fixture in this post, and using some pytest fixtures that come prebuilt with the <a href="https://github.com/smarie/python-pytest-harvest/">pytest-harvest library</a>.</p><h1>Using pytest to evaluate your agent / augmented LLM / application</h1><p>An agent / augmented LLM is a combination of LLM calls and logic. But how do we know if it's working? Well we can test &amp; evaluate it.</p><p>From a high level we want to test &amp; evaluate the "micro" i.e. the LLM calls &amp; individual bits of logic, through to the "macro" i.e. the agent/application as a whole. </p><p>But, the challenge with LLM calls is that you might want to "assert" on various aspects of the output / behavior without stopping execution on the first assertion failure, which is standard test framework behavior. So what are you to do?</p><h2>By default pytest fails on the first assert failure</h2><p>In the examples we've shown above, the test will stop executing on the first assertion failure. This is the default behavior of pytest. While this works well for regular deterministic software testing, failing at the first failed evaluation for an LLM / agent test would be prohibitive in getting a full picture of our LLM / Agent application&#8217;s health. If you&#8217;re scratching your head here as to why this would be a problem, this next section is for you.</p><h3>What kind of "asserts" do we want?</h3><p>We might want to <em>evaluate</em>, or <em>assert</em> on the output in a number of ways:</p><ol><li><p><strong>Exact match</strong> - the output is exactly as expected.</p></li><li><p><strong>Fuzzy match</strong> - the output is close to what we expect, e.g. does it contain the right words, is it "close" to the answer, etc.</p></li><li><p><strong>Human grade</strong> - the output is graded by a human as to how close it is to the expected output. E.g. is this funny?</p></li><li><p><strong>LLM grade</strong> - the output is graded by an LLM as to how close it is to the expected output.</p></li><li><p><strong>Static measures</strong> - the output has some static measures that we want to evaluate, e.g. length, etc.</p></li></ol><p>It is rare that you solely rely on (1) with LLMs, and you'll likely want to evaluate the output in a number of ways before making a pass / fail decision. E.g. that the output is close to the expected output, that it contains the right words, etc., and then make a pass / fail decision based on all these evaluations.</p><p>We will not dive deep into what evaluation logic you should use. If you want more information there, we suggest you start with <a href="https://hamel.dev/notes/llm/officehours/evalmultiturn.html">posts like this</a>. The TL;DR: is:</p><ol><li><p>You need to understand your data and outcomes to choose the right evaluation logic.</p></li><li><p>Focus on binary measures, e.g. yes / no, pass /fail, etc.</p></li><li><p>Categorize errors to know what to test / check for</p></li></ol><p>So now what? How do we evaluate all the assertions before making a pass / fail decision?</p><h3>Not failing on first assert failure / logging test results</h3><p>As mentioned above, one limitation of pytest is that it fails on the first assertion failure. This is not ideal if you want to evaluate multiple aspects of the output before making a pass / fail decision.</p><p>One approach is using the <a href="https://smarie.github.io/python-pytest-harvest/">pytest-harvest</a> plugin to log what our tests are doing. This allows us to capture the results of evaluations in a structured way without breaking at the first asserting failure. </p><p>This doesn&#8217;t limit how we use pytest. Rather, it enables us to mix and match  appropriate hard "assertions" - i.e. definitely fail, with softer ones where we want to evaluate all aspects before making an overall pass / fail decision. We will walk through how to do this below using a few pytest &amp; pytest-harvest constructs.</p><h3>pytest-harvest</h3><pre><code>pip install pytest-harvest</code></pre><p><a href="https://github.com/smarie/python-pytest-harvest/">pytest-harvest</a> is a plugin that provides a number of pytest fixtures. These fixtures have certain behaviors that we&#8217;ll use to log and then see the results of evaluations from within our tests.</p><p><code>results_bag</code> is a fixture that we can log values to from our tests. This is useful if we don't want to fail on the first assert statement, and instead capture a lot more. E.g. you can assign arbitrary values to &#8220;keys&#8221; like below.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!P53H!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!P53H!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png 424w, https://substackcdn.com/image/fetch/$s_!P53H!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png 848w, https://substackcdn.com/image/fetch/$s_!P53H!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png 1272w, https://substackcdn.com/image/fetch/$s_!P53H!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!P53H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png" width="604" height="141" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:141,&quot;width&quot;:604,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:31715,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!P53H!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png 424w, https://substackcdn.com/image/fetch/$s_!P53H!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png 848w, https://substackcdn.com/image/fetch/$s_!P53H!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png 1272w, https://substackcdn.com/image/fetch/$s_!P53H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b4d8005-07e9-498c-8c3e-385899617e69_604x141.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_pytestharvest_example-py">Gist</a></figcaption></figure></div><p>We can then access what was assigned in the <code>results_bag</code> from the <code>pytest-harvest</code> plugin via the <code>module_results_df</code> fixture that provides a pandas dataframe of the results:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ruJs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ruJs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png 424w, https://substackcdn.com/image/fetch/$s_!ruJs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png 848w, https://substackcdn.com/image/fetch/$s_!ruJs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png 1272w, https://substackcdn.com/image/fetch/$s_!ruJs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ruJs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png" width="604" height="341" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:341,&quot;width&quot;:604,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:68987,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ruJs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png 424w, https://substackcdn.com/image/fetch/$s_!ruJs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png 848w, https://substackcdn.com/image/fetch/$s_!ruJs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png 1272w, https://substackcdn.com/image/fetch/$s_!ruJs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3bfefe20-6459-426b-bb2a-526e5af164c4_604x341.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_pytestharvest_example-py">Gist</a></figcaption></figure></div><p>We can then evaluate them as we see fit for our use case. E.g. we only pass tests if all the outputs are as expected, or we pass if 90% of the outputs are as expected, etc. You could also log this to a file, or a database, etc. for further inspection and record keeping, or combining it with open source frameworks like <a href="https://mlflow.org/">mlflow</a> and using their <a href="https://mlflow.org/docs/latest/llms/llm-evaluate/index.html">evaluate functionality</a>.</p><p>Note: we can also combine <code>results_bag</code> with <code>pytest.mark.parametrize</code> to run the same test with different inputs and expected outputs:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XRjs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XRjs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png 424w, https://substackcdn.com/image/fetch/$s_!XRjs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png 848w, https://substackcdn.com/image/fetch/$s_!XRjs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png 1272w, https://substackcdn.com/image/fetch/$s_!XRjs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XRjs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png" width="588" height="321" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:321,&quot;width&quot;:588,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:57341,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XRjs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png 424w, https://substackcdn.com/image/fetch/$s_!XRjs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png 848w, https://substackcdn.com/image/fetch/$s_!XRjs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png 1272w, https://substackcdn.com/image/fetch/$s_!XRjs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08db9e4d-528e-4604-800a-9c57817a63aa_588x321.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_pytestharvest_example2-py">Gist</a></figcaption></figure></div><h2>Using Burr's pytest Hook</h2><p>With Burr you can curate test cases from real application runs. You can then use these test cases in your pytest suite. Burr then has a hook that enables you to curate a file with the input state and expected output state for an entire run, or a single Burr action. See the <a href="https://burr.dagworks.io/examples/guardrails/creating_tests/">Burr test case creation documentation</a> for more details on how (or see the &#8220;reproduce&#8221; tab in the Burr UI like below). </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bGMt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bGMt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png 424w, https://substackcdn.com/image/fetch/$s_!bGMt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png 848w, https://substackcdn.com/image/fetch/$s_!bGMt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png 1272w, https://substackcdn.com/image/fetch/$s_!bGMt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bGMt!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png" width="1200" height="423.06569343065695" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:483,&quot;width&quot;:1370,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:90148,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bGMt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png 424w, https://substackcdn.com/image/fetch/$s_!bGMt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png 848w, https://substackcdn.com/image/fetch/$s_!bGMt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png 1272w, https://substackcdn.com/image/fetch/$s_!bGMt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ad35339-7b33-4c85-9385-f8a044e817f7_1370x483.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">You can bootstrap a pytest test case using the &#8220;reproduce&#8221; button on a trace in the Burr UI. </figcaption></figure></div><p>Once you run the command you&#8217;ll get some code and a JSON file that you can then manage and curate into a pytest test. Then to combine with the pytest-harvest fixtures to capture evaluations, we need to add the `results_bag` fixture argument to the python function &#8212; note the final code below:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OW9w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OW9w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png 424w, https://substackcdn.com/image/fetch/$s_!OW9w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png 848w, https://substackcdn.com/image/fetch/$s_!OW9w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png 1272w, https://substackcdn.com/image/fetch/$s_!OW9w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OW9w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png" width="790" height="704" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:704,&quot;width&quot;:790,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:154665,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OW9w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png 424w, https://substackcdn.com/image/fetch/$s_!OW9w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png 848w, https://substackcdn.com/image/fetch/$s_!OW9w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png 1272w, https://substackcdn.com/image/fetch/$s_!OW9w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb8911938-93b4-44d1-b95d-748b9f8420e0_790x704.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_burr_test1-py">Gist</a></figcaption></figure></div><p>To test an entire agent, we can use the same approach, but instead rely on the input and output state being the entire state of the agent at the start and end of the run.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UsAs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UsAs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png 424w, https://substackcdn.com/image/fetch/$s_!UsAs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png 848w, https://substackcdn.com/image/fetch/$s_!UsAs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png 1272w, https://substackcdn.com/image/fetch/$s_!UsAs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UsAs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png" width="956" height="746" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:746,&quot;width&quot;:956,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:169796,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UsAs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png 424w, https://substackcdn.com/image/fetch/$s_!UsAs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png 848w, https://substackcdn.com/image/fetch/$s_!UsAs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png 1272w, https://substackcdn.com/image/fetch/$s_!UsAs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8091b740-fae5-469a-9f78-8b8a5117b08d_956x746.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_burr_e2e-py">Gist</a></figcaption></figure></div><h4>Using the Burr UI to observe test runs</h4><p>You can also use the Burr UI to observe the test runs. This can be useful to see the results of the tests in a more visual way. To do this, you'd instantiate the Burr Tracker and then run the tests as normal. A note on ergonomics:</p><ol><li><p>It's useful to use the test_name as the partition_key to easily find test runs in the Burr UI. You can also make the app_id match some test run ID, e.g. date-time, etc.</p></li><li><p>You can turn on <a href="https://opentelemetry.io/">opentelemetry</a> tracing to see the traces in the Burr UI as well.</p></li><li><p>In general this means that you should have a parameterizeable application builder function that can take in a tracker and partition key.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!f_L1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!f_L1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png 424w, https://substackcdn.com/image/fetch/$s_!f_L1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png 848w, https://substackcdn.com/image/fetch/$s_!f_L1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png 1272w, https://substackcdn.com/image/fetch/$s_!f_L1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!f_L1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png" width="956" height="1043" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1043,&quot;width&quot;:956,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:234715,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!f_L1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png 424w, https://substackcdn.com/image/fetch/$s_!f_L1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png 848w, https://substackcdn.com/image/fetch/$s_!f_L1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png 1272w, https://substackcdn.com/image/fetch/$s_!f_L1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bcabab1-a463-4441-a83b-f7ee6cea60c9_956x1043.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_burr_e2e-py">Gist</a></figcaption></figure></div><h2>TDD: Adopting an iterative SDLC to get out of POC purgatory</h2><p>Unlike traditional software where writing tests means you&#8217;re done, with LLMs that is just the start of an iterative loop. By logging traces to get data and turning them into datapoints for tests in pytest, one can move fluidly between an application development, test driven development, and back. As more datapoints are accumulated, you can then better evaluate and measure prompt changes and their impacts.</p><p>By using pytest as the means to systematically go from shipping on vibes to having a structured way to evaluate and ensure that projects are heading in the right direction, you stand a much better chance of getting your LLM &amp; Agent applications out of POC purgatory.</p><h3>Your TDD Loop with Burr and pytest</h3><p>To put it more concretely, the above code showed how you could:</p><ol><li><p>Pull an application trace and create a pytest test for it.</p></li><li><p>Add and manage datapoints with parameterize and/or Burr&#8217;s pytest integration.</p></li><li><p>Evaluate multiple aspects of a single test and then aggregate them for multiple data points.</p></li></ol><p>With this setup, you can now operate a <strong>Test Driven Development (TDD)</strong> loop to optimize and work on a single LLM call! As you make changes to the code / prompt, you&#8217;ll be able to use pytest to exercise that one LLM call and then evaluate the changes in a systematic fashion, without working only off of vibes.</p><h4>Some uses of TDD:</h4><p>Here are some more situations where applying TDD can help speed up development:</p><ol><li><p><strong>Guardrails</strong>. Taking the aforementioned TDD approach can make sure that prompt injection, harmful content, etc. is ignored, or dealt with appropriately.</p></li><li><p><strong>Evaluating the impact of using a different LLM</strong>. If you got your application working with a large model, and want to assess if you can switch to a lower cost model, having a pytest suite you can run will help you quickly assess where you need to tune / change things. </p></li></ol><h2>One trick we like - run things multiple times</h2><p>LLMs are inherently non-deterministic. So one way to explore and determine how the variance of a single prompt + data input leads to different outputs, is to run it multiple times.</p><p>With pytest this can take the form of a test that runs an action multiple times, then aggregates the responses to see how different they are. Using this approach can help you better tweak prompts to reduce variance.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5xQf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5xQf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png 424w, https://substackcdn.com/image/fetch/$s_!5xQf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png 848w, https://substackcdn.com/image/fetch/$s_!5xQf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png 1272w, https://substackcdn.com/image/fetch/$s_!5xQf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5xQf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png" width="653" height="262" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:262,&quot;width&quot;:653,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59117,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5xQf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png 424w, https://substackcdn.com/image/fetch/$s_!5xQf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png 848w, https://substackcdn.com/image/fetch/$s_!5xQf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png 1272w, https://substackcdn.com/image/fetch/$s_!5xQf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2e34d32-d32a-431e-b38f-d7d965ff8281_653x262.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_example_stability-py">Gist</a></figcaption></figure></div><p>The output of this test will show you where variance occurs, and is also then a useful measure in of itself in how stable things are, e.g. maybe it&#8217;s okay for some variance to exist, but not too much&#8230;</p><h2>Capturing versions of your prompts to go with the datasets you generate via pytest</h2><p>As you start to iterate and generate datasets (that's what happens if you log the output of the dataframe), you will need to tie together the version of the code that generated the dataset to the dataset itself. This is useful for debugging, and for ensuring that you can reproduce results (e.g. which version of the code / prompt created this output?). One way to do this is to capture the version of the code that generated the dataset in the dataset itself. Assuming you&#8217;re using `git` for version control, one just needs to capture the git commit hash of the code that generated the data set, i.e. the prompts + business logic. If you treat prompts as code, then your workflow might be:</p><ol><li><p>Use git to commit changes.</p></li><li><p>Create a pytest fixture that captures the git commit hash of the current state of the git repo.</p></li><li><p>When you log the results of your tests, log the git commit hash as well as a column. </p></li><li><p>When you load / look at the data set, you can see the git commit hash that generated the data set to tie it back to the code that generated it.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1sRO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1sRO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png 424w, https://substackcdn.com/image/fetch/$s_!1sRO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png 848w, https://substackcdn.com/image/fetch/$s_!1sRO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png 1272w, https://substackcdn.com/image/fetch/$s_!1sRO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1sRO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png" width="916" height="495" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:495,&quot;width&quot;:916,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:104811,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1sRO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png 424w, https://substackcdn.com/image/fetch/$s_!1sRO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png 848w, https://substackcdn.com/image/fetch/$s_!1sRO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png 1272w, https://substackcdn.com/image/fetch/$s_!1sRO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c8e50ba-c996-4fca-8b7e-052100c17369_916x495.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_example_git-py">Gist</a></figcaption></figure></div><p>To use it we add the fixture to the function that saves the results:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OiBx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OiBx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png 424w, https://substackcdn.com/image/fetch/$s_!OiBx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png 848w, https://substackcdn.com/image/fetch/$s_!OiBx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png 1272w, https://substackcdn.com/image/fetch/$s_!OiBx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OiBx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png" width="916" height="181" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:181,&quot;width&quot;:916,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:42492,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OiBx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png 424w, https://substackcdn.com/image/fetch/$s_!OiBx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png 848w, https://substackcdn.com/image/fetch/$s_!OiBx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png 1272w, https://substackcdn.com/image/fetch/$s_!OiBx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fac571bc6-29ee-41b9-b606-3f457cc953fd_916x181.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption"><a href="https://gist.github.com/skrawcz/3d84b70a9df0e71048b69339d130aa62#file-test_example_git-py">Gist</a></figcaption></figure></div><h1>A Runnable Example</h1><p>If you want to see some working code, using a dummy medical diagnosis workflow. Please see <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/pytest">this example</a>. In it you&#8217;ll find:</p><ul><li><p><code>some_actions.py</code> - a file that defines an augmented LLM application (it's not a full agent) with some actions. See image below - note the hypotheses action runs multiple LLM calls in parallel.</p></li><li><p><code>test_some_actions.py</code> - a file that defines some tests for the actions in <code>some_actions.py</code>.</p></li><li><p><code>conftest.py</code> - a file that contains some custom fixtures and pytest configuration for running our tests.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1Eqq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1Eqq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png 424w, https://substackcdn.com/image/fetch/$s_!1Eqq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png 848w, https://substackcdn.com/image/fetch/$s_!1Eqq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png 1272w, https://substackcdn.com/image/fetch/$s_!1Eqq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1Eqq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png" width="206" height="234" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:234,&quot;width&quot;:206,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;toy example&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="toy example" title="toy example" srcset="https://substackcdn.com/image/fetch/$s_!1Eqq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png 424w, https://substackcdn.com/image/fetch/$s_!1Eqq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png 848w, https://substackcdn.com/image/fetch/$s_!1Eqq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png 1272w, https://substackcdn.com/image/fetch/$s_!1Eqq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F68f37cf4-da57-4d67-9c85-a54904b09d16_206x234.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You'll see that we use the <code>results_bag</code> fixture to log the results of our tests,and then we can access these results via the <code>module_results_df</code> fixture that provides a pandas dataframe of the results. This dataframe is then saved as a CSV for uploading to google sheets, etc. for further analysis. You will also see uses of <code>pytest.mark.parametrize</code> and Burr's pytest feature for parameterizing tests from a JSON file.</p><p>To run the tests, you can run them with pytest:</p><pre><code>pytest test_some_actions.py</code></pre><p>After running the tests, you can see the results in a CSV file called <code>results.csv</code> in the same directory as the tests. Users then generally export / import that to a UI of their choice (e.g. google sheets, or a notebook) for further error analysis and human review.</p><p>You should also see the following in the Burr UI that can aid in reviewing some traces.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Hy83!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hy83!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png 424w, https://substackcdn.com/image/fetch/$s_!Hy83!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png 848w, https://substackcdn.com/image/fetch/$s_!Hy83!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png 1272w, https://substackcdn.com/image/fetch/$s_!Hy83!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hy83!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png" width="1456" height="840" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:840,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Burr UI&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Burr UI" title="Burr UI" srcset="https://substackcdn.com/image/fetch/$s_!Hy83!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png 424w, https://substackcdn.com/image/fetch/$s_!Hy83!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png 848w, https://substackcdn.com/image/fetch/$s_!Hy83!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png 1272w, https://substackcdn.com/image/fetch/$s_!Hy83!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25f3b18c-744a-43c2-8f78-39ea2d10b524_2265x1306.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/p/test-driven-development-tdd-of-llm?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/p/test-driven-development-tdd-of-llm?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><h1>Summary</h1><p>In this post we showed how to build a test driven development (TDD) loop using Burr and pytest. Specifically, we showed how you can take a trace from a Burr application and create a pytest case, then use pytest-fixtures (from pytest-harvest) to record all test evaluations and later post-process them to provide an aggregate measure to help you discern the reliability of your AI application over time. This allows you to quickly set up a test driven development loop where you then tweak prompts / code and then run pytest to systematically run evaluations on your changes.</p><p>If you like this post, or find other / better ways to use pytest, please leave a comment or create an issue in Burr&#8217;s repository. There&#8217;s also a FAQ list below.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/p/test-driven-development-tdd-of-llm/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/p/test-driven-development-tdd-of-llm/comments"><span>Leave a comment</span></a></p><h3>Maven Course: <a href="https://maven.com/hugo-stefan/building-llm-apps-ds-and-swe-from-first-principles?utm_medium=clp_share_link&amp;utm_source=maven">Building LLM Applications for Data Scientists and Software Engineers</a></h3><p>If you got this far and want to learn more, then sign-up for <a href="https://www.linkedin.com/in/hugo-bowne-anderson-045939a5?originalSubdomain=au">Hugo Bowne-Anderson</a>&#8217;s and <a href="https://www.linkedin.com/in/skrawczyk/">Stefan Krawczyk</a>&#8217;s <a href="https://maven.com/hugo-stefan/building-llm-apps-ds-and-swe-from-first-principles?utm_medium=clp_share_link&amp;utm_source=maven">Maven Course: &#8220;Building LLM Applications for Data Scientists and Software Engineers&#8221;</a>. It stars January 6th and will cover topics such as this that are required to ship reliable AI software.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/subscribe?"><span>Subscribe now</span></a></p><h2>Further Reading</h2><p>If you&#8217;re interested in learning more about Burr:</p><ul><li><p>Find the code for this example <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/pytest">here</a></p></li><li><p>Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a> for help or if you have questions!</p></li><li><p><a href="https://www.youtube.com/@dagworks-inc">Subscribe to our youtube</a> to watch some in-depth tutorials/overviews</p></li><li><p>Star our <a href="https://github.com/dagworks-inc/burr">Github repository</a> if you like what you see</p></li></ul><p></p><h1>Frequently Asked Questions: </h1><h2>General Questions</h2><p><strong>Q: Do I need to use Python to implement this testing approach?</strong></p><p>A: While the examples use Python, pytest, and Burr, the general principles of systematic evaluation and test-driven development can be implemented in any programming language with appropriate testing frameworks. The key concepts of capturing test results, evaluating multiple aspects of LLM outputs, and maintaining test suites are language-agnostic.</p><p><strong>Q: How is this different from traditional software testing?</strong></p><p>A: Traditional software testing typically focuses on deterministic outputs with clear pass/fail criteria. Testing AI applications requires handling non-deterministic outputs, evaluating multiple aspects of responses, and often using fuzzy matching or LLM-based evaluation. This approach allows for capturing and analyzing various quality metrics rather than just binary pass/fail results.</p><h2>Testing Implementation</h2><p><strong>Q: How do I decide which aspects of LLM output to evaluate?</strong></p><p>A: Consider evaluating:</p><ul><li><p>Content accuracy (exact or fuzzy matching)</p></li><li><p>Output format compliance</p></li><li><p>Response consistency across multiple runs</p></li><li><p>Domain-specific requirements</p></li><li><p>Safety and appropriateness checks</p></li></ul><p>The specific aspects will depend on your application's requirements.</p><p><strong>Q: What's the recommended approach for handling test data?</strong></p><p>A: Start by capturing real application runs using Burr's tracking functionality. Curate these into test cases, focusing on diverse scenarios and edge cases. Maintain separate test suites for different aspects (e.g., content generation, safety checks, format compliance) and regularly update them as requirements evolve.</p><h2>Performance and Scale</h2><p><strong>Q: How does this testing approach impact development speed?</strong></p><p>A: While setting up systematic testing requires initial investment, it typically saves time in the long run by:</p><ul><li><p>Catching issues early in development</p></li><li><p>Providing clear metrics for improvement</p></li><li><p>Enabling confident iteration on prompts and model interactions</p></li><li><p>Reducing manual testing effort</p></li></ul><p><strong>Q: Can this testing approach handle large-scale AI applications?</strong></p><p>A: Yes, the approach scales well because:</p><ul><li><p>Tests can be parameterized to handle many test cases</p></li><li><p>Results can be exported for analysis in external tools</p></li><li><p>The Burr UI provides visibility into test runs</p></li></ul><h2>Best Practices</h2><p><strong>Q: How often should these tests be run?</strong></p><p>A: Consider running:</p><ul><li><p>Core functionality tests with each code change</p></li><li><p>Comprehensive evaluation suites daily or weekly</p></li><li><p>Stability tests (multiple runs) during significant prompt or model changes</p></li><li><p>Performance benchmarks on a regular schedule</p></li></ul><p><strong>Q: How should I maintain test cases over time?</strong></p><p>A: Best practices include:</p><ul><li><p>Regular review and updates of test cases</p></li><li><p>Tying together version control with the results of tests.</p></li><li><p>Documentation of evaluation criteria</p></li><li><p>Tracking of model and prompt versions</p></li><li><p>Regular analysis of test results to identify patterns</p></li></ul><h2>Troubleshooting</h2><p><strong>Q: What should I do if test results are inconsistent?</strong></p><p>A: Consider these steps:</p><ol><li><p>Use the multiple-run approach described in the post to measure output variance</p></li><li><p>Review and possibly adjust evaluation criteria</p></li><li><p>Check if the inconsistency is expected LLM behavior or a bug</p></li><li><p>Consider adjusting prompts to reduce variance if needed</p></li></ol><p><strong>Q: How can I debug failed tests effectively?</strong></p><p>A: Utilize:</p><ul><li><p>Burr's UI for visualizing test runs</p></li><li><p>The detailed results captured in results_bag</p></li><li><p>pytest's debugging features</p></li><li><p>The CSV export functionality for detailed analysis</p></li></ul><h2>Integration and Tools</h2><p><strong>Q: Can this testing approach integrate with CI/CD pipelines?</strong></p><p>A: Yes, you can integrate these tests into CI/CD pipelines. Consider:</p><ul><li><p>Running core tests on every PR</p></li><li><p>Scheduling comprehensive evaluations</p></li><li><p>Setting appropriate thresholds for test success</p></li><li><p>Exporting results for tracking over time</p></li></ul><p><strong>Q: What tools are recommended for analyzing test results?</strong></p><p>A: Common tools include:</p><ul><li><p>Spreadsheet applications for basic analysis</p></li><li><p>Jupyter notebooks for detailed investigation</p></li><li><p>Visualization tools for tracking metrics over time</p></li><li><p>MLflow for experiment tracking</p></li><li><p>Custom dashboards using exported CSV data</p></li></ul><h2>Burr-Specific Questions</h2><p><strong>Q: What's the learning curve for implementing Burr in an existing AI application?</strong></p><p>A: Burr is designed to be lightweight and integrates with existing Python applications. The main concepts to understand are state machines, actions, and transitions. If you're already familiar with pytest, the additional Burr-specific testing features should be straightforward to adopt.</p><p><strong>Q: Can Burr handle asynchronous operations in AI applications?</strong></p><p>A: Yes, Burr supports asynchronous operations and parallel execution of actions, as demonstrated in the medical diagnosis workflow example where multiple hypotheses are generated in parallel.</p><p></p>]]></content:encoded></item><item><title><![CDATA[Parallel Multi Agent Workflows with Burr ]]></title><description><![CDATA[Leverage Burr's new parallelism capabilities to build concurrent multi-agent workflows]]></description><link>https://blog.dagworks.io/p/parallel-multi-agent-workflows-with</link><guid isPermaLink="false">https://blog.dagworks.io/p/parallel-multi-agent-workflows-with</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Mon, 23 Dec 2024 14:31:15 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Introduction</h1><p>Many AI applications start off simple &#8211; you query some hosted model, do a little bit of prompt engineering, process/store/index the result, and stream it back to the user. You model this as a simple <a href="https://blog.dagworks.io/p/burr-develop-stateful-ai-applications">ping-pong application</a> &#8211; (AI &#8594; Human &#8594; AI, etc&#8230;). Inevitably, as you hit some success, you will need more from your application. The natural next step is to enable it to <a href="https://blog.dagworks.io/p/agentic-design-pattern-1-tool-calling">call tools</a>, or dive into a more complicated research question (E.G. with chain of thought prompting). This is when it turns into an <em>agent</em> &#8211; an AI system that <em><a href="https://www.anthropic.com/research/building-effective-agents">dynamically directs their own processes and tool-usage</a></em>, either with or without human input. An agent is often modeled by a graph with state &#8211; it has a set of capabilities and needs to dynamically decide the order.</p><p>As your agent&#8217;s capabilities grow in complexity, you likely start to realize that it needs to execute multiple tasks at once &#8211; generate several candidates for user/LLM selection, leverage various tools simultaneously, etc&#8230; While you will still model this as a graph, you end up being in multiple states at once, and have to worry about distributing the computation and coordinating state between tasks.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe to get the latest updates.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>In this post we show how the Burr library helps you solve these problems. We will:</p><ol><li><p>Dig into Burr/why we built it</p></li><li><p>Walk through the API layers burr exposes for parallelism</p></li><li><p>Show a simple example of generating multiple poems in different styles and presenting them to the user</p></li><li><p>Wrap up &#8211; talk through other applications/directions for future work</p></li></ol><h1>Burr</h1><p><a href="https://github.com/DAGWorks-Inc/burr/">Burr</a> is a lightweight Python library you use to build applications as state machines. You construct your application out of a series of <em>actions</em> (these can be either decorated functions or objects), which declare inputs from <em>state</em>, as well as <em>inputs</em> from the user. These specify custom logic (delegating to any framework), as well as instructions on how to update state. State is immutable, which allows you to inspect it at any given point. Burr handles orchestration, monitoring, persistence, etc&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aVVt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" width="723" height="65" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:65,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30725,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Hello world counter action. Gist <a href="https://gist.github.com/elijahbenizzy/c295c2578685867996577733b8005f59">here</a></figcaption></figure></div><p>You run your Burr actions as part of an application &#8211; this allows you to string them together with a series of (optionally) conditional transitions from action to action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ejRj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" width="1444" height="568" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:568,&quot;width&quot;:1444,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:119779,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Using the application builder. Gist <a href="http://238196b05d123353999b9263c3c1a76f/">here</a></figcaption></figure></div><p>Burr comes with a user-interface that enables monitoring/telemetry, as well as hooks to persist state/execute arbitrary code during execution.</p><p>You can visualize this as a flow chart, i.e. graph / state machine:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lYVz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" width="216" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;State Machine&quot;,&quot;title&quot;:&quot;State Machine&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="State Machine" title="State Machine" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>And monitor it using the local telemetry debugger:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yfZx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" width="724" height="372.93956043956047" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:750,&quot;width&quot;:1456,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:194056,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>While the above example is a simple illustration, Burr is commonly used for AI assistants (like in this example), RAG applications, and human-in-the-loop AI interfaces. See the repository <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples">examples</a> for a (more exhaustive) set of use-cases.</p><h2>A multilayered API for parallelism</h2><p>To allow for agent-level parallelism, burr uses recursion as a core primitive. No matter how small the sub-application is, each parallel branch gets run in its entirety under the context of a  parent action, as a set of separate, simultaneous burr applications. Conceptually, parallelism in Burr uses a simple <a href="https://en.wikipedia.org/wiki/MapReduce">map reduce</a> pattern.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OvKp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OvKp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 424w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 848w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 1272w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OvKp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png" width="724" height="671.620578778135" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:577,&quot;width&quot;:622,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;../../_images/parallelism.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="../../_images/parallelism.png" title="../../_images/parallelism.png" srcset="https://substackcdn.com/image/fetch/$s_!OvKp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 424w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 848w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 1272w, https://substackcdn.com/image/fetch/$s_!OvKp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91374bb-0238-4ecc-8280-c9af4206f2a0_622x577.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Map to a set of actions/sub-applications with their own state, wait for them to complete, then join the results to form the next state for downstream consumption.</figcaption></figure></div><p>The parent action broadcasts the state to multiple sub-applications (run/controlled by the parent action), each of which has their own state &#8211; a transformation of the parent&#8217;s state. These are run, waited for, and the result is merged to form a final state for the parent action, which downstream actions consume. While the spawning application and the sub-applications it spawns are largely decoupled, Burr framework provides two features to make this process easier:</p><ol><li><p><a href="https://burr.dagworks.io/concepts/recursion/#tracking">An API allows</a> for cascading of telemetry from the parent to the child application &#8211; the UI is aware of the parent-child relationships, and provides bidirectional links + inline expansions in the trace view</p></li><li><p>Burr provides tooling to make the process of launching tasks, joining/merging state, and tracking linkage automatic.</p></li></ol><p>For (2), Burr has three different API layers &#8211; the implementation of each leverages those below. They are:</p><h3><strong>1. Full control</strong></h3><p>With the lowest-level API layer, you launch and manage your own tasks, linking them together with the tracker. You are responsible for forking/joining processes, wiring persistence/tracking, etc&#8230; to the child applications, and setting up sub-applications. While we won&#8217;t go over this in the blog post, you can read about it <a href="https://burr.dagworks.io/concepts/recursion/">in the docs</a>.</p><h3><strong>2. Task-based map/reduce</strong></h3><p>You can also specify a series of tasks. You did this by implementing the <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.TaskBasedParallelAction">TaskBasedParallelAction</a> class, which produces a generator of <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.SubGraphTask">SubGraphTasks</a>, each of which specifies the state/application ID for an input. While you still have to wire through some application-level concerns (tracking/persistence), it handles execution. You then specify how to reduce/join the state with a simple reduce function. Again, we will not cover this in the post. Read more <a href="https://burr.dagworks.io/concepts/parallelism/#lower-level-api">in the docs</a>.</p><h3><strong>3. State/action-based map/reduce</strong></h3><p>You can specify either a set of actions or a set of states to map over. If you specify both, it will take the cartesian product of the actions/states. There are three different classes to implement &#8211; <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.MapActions">MapActions</a>, <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.MapStates">MapStates</a>, and <a href="https://burr.dagworks.io/reference/parallelism/#burr.core.parallelism.MapActionsAndStates">MapActionsAndStates</a> (cartesian product). We will be showing an example of the MapStates implementation during the rest of this &#8211; hold tight! </p><h3>Which to choose?</h3><p>It all depends on how much control you need, but you should choose the greatest layer of abstraction that effectively models your problem. Many agentic shapes we&#8217;ve found can be represented as a simple map over either actions/states, which is why we made it the top-level interface. Otherwise, if you want a full set of executions for an experiment/comparison, you&#8217;ll likely leverage the cartesian product, and if you have specific logic that doesn&#8217;t boil down to actions/states, you&#8217;ll use the task-based approach. The fully-controlled API is reserved for odd cases in which the map/reduce pattern does not effectively fit. E.G. if you&#8217;re streaming parallel results out, have a few longer-running tasks and want to leverage task inter-communication, etc&#8230; For the latter two interfaces, you can customize execution approach, tracking behavior, persistence behavior, and more.</p><h1>Generating Poems in Parallel</h1><p>Let&#8217;s go over a fairly simple example of the MapStates API &#8211; we will be writing an agent that takes a prompt and generates a poem in multiple styles from that prompt. To generate the poem, it will delegate to a write/edit loop that does a few iterations to improve the poem.</p><p>Our overall structure will look like this &#8211; note that this graph does not include the details of the sub-application:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4z2b!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4z2b!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 424w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 848w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 1272w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4z2b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png" width="594" height="322" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cc978b37-341e-4124-a087-611d92fac965_594x322.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:322,&quot;width&quot;:594,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:21678,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4z2b!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 424w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 848w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 1272w, https://substackcdn.com/image/fetch/$s_!4z2b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc978b37-341e-4124-a087-611d92fac965_594x322.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">A simple three-node flowchart &#8212; note that generate_all_poems is actually a recursive sub-application!</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mmZj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mmZj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 424w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 848w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 1272w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mmZj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png" width="137" height="234" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b0411fba-9a62-4185-8eb6-94c779902a97_137x234.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:234,&quot;width&quot;:137,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:10361,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mmZj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 424w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 848w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 1272w, https://substackcdn.com/image/fetch/$s_!mmZj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb0411fba-9a62-4185-8eb6-94c779902a97_137x234.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">The flowchart for generate_all_poems</figcaption></figure></div><p>The user provides workflow-level parameters (poem_types, poem_subject, and max_drafts). From these, we manipulate the state, and generate a sub-application from each step. The most interesting part is the distribution &#8212; E.G. the use of MapStates. The code looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yT_R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yT_R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 424w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 848w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 1272w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yT_R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png" width="1456" height="1610" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/daa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1610,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:809830,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!yT_R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 424w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 848w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 1272w, https://substackcdn.com/image/fetch/$s_!yT_R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdaa49520-2ae1-47d2-9462-db5984bcf8ab_1476x1632.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Creating one sub-application for each poem type, with a state in which the poem type has been bound appropriately. We specify the action it runs (the write/edit loop draft). The reduce function then joins them together, gathering all final drafts to present to the user. Corresponding <a href="https://gist.github.com/elijahbenizzy/58ad4ab9dddc0b4d2f70ba54320d3e7b">gist</a>.</figcaption></figure></div><p>To tie this together, we&#8217;ll include this action as part of our overall application: </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!z_X8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!z_X8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 424w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 848w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 1272w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!z_X8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png" width="1396" height="480" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:480,&quot;width&quot;:1396,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:92892,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!z_X8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 424w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 848w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 1272w, https://substackcdn.com/image/fetch/$s_!z_X8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5f856db-8662-4950-8bd2-1c0a9357dcea_1396x480.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Now we&#8217;ve got all we need to run! We execute as we would any normal application &#8211; by default, the sub-applications will be spawned in threads, which will be joined when they are done. This is easy to follow in the UI &#8211; you can see an application with multiple child applications.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yHNs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yHNs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 424w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 848w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 1272w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yHNs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png" width="1456" height="312" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:312,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:189608,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yHNs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 424w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 848w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 1272w, https://substackcdn.com/image/fetch/$s_!yHNs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffa2f1b54-96c5-4e7c-b97e-88b30d3f200e_1701x365.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can also click to expand them individually:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xLpW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xLpW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 424w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 848w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 1272w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xLpW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png" width="1456" height="505" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:505,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:300038,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xLpW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 424w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 848w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 1272w, https://substackcdn.com/image/fetch/$s_!xLpW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c5e325-038c-4825-bc4f-ea332cd14a3d_1694x587.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And view state for the sub-applications inline (in case you wanted an in-depth analysis of a limerick based on a state machine&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Hgla!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hgla!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 424w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 848w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 1272w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hgla!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png" width="1456" height="815" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d36d8250-0314-426e-ae89-852cb0798b98_1698x950.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:815,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:687559,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Hgla!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 424w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 848w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 1272w, https://substackcdn.com/image/fetch/$s_!Hgla!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd36d8250-0314-426e-ae89-852cb0798b98_1698x950.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>When you click on one of the child applications, you will see a link back to the spawning parent: </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MeML!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MeML!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 424w, https://substackcdn.com/image/fetch/$s_!MeML!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 848w, https://substackcdn.com/image/fetch/$s_!MeML!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 1272w, https://substackcdn.com/image/fetch/$s_!MeML!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MeML!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png" width="1456" height="195" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:195,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:316625,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MeML!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 424w, https://substackcdn.com/image/fetch/$s_!MeML!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 848w, https://substackcdn.com/image/fetch/$s_!MeML!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 1272w, https://substackcdn.com/image/fetch/$s_!MeML!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bc1844c-6b2d-4dc6-8396-efd9157b50c7_3412x456.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can also <a href="https://blog.dagworks.io/p/annotating-data-in-burr">annotate</a> the workflow, and track additional data with <a href="https://blog.dagworks.io/p/trace-all-parts-of-your-agenticai">opentelemetry</a>, giving you full visibility into the way your sub-applications function.</p><h1>Wrapping Up</h1><h2>Comparison</h2><p>Burr&#8217;s approach towards parallelism differs from other libraries, largely due to the design goals. While <a href="https://github.com/langchain-ai/langgraph">langgraph</a> took a heavier-handed <a href="https://stanford.edu/~rezab/classes/cme323/S15/notes/lec8.pdf">pregel-based</a> approach to orchestrate running actions over state, Burr aims towards simplification. The core philosophy is central management and execution &#8211; launching tasks, delegating to a single node, and joining the results. While talking to our users, we found that the vast majority prioritized clear control flow primitives that enabled them to reason about what their agents are doing and where. By not taking a state-convergence based pregel approach and then breaking its assumptions to allow a human-in-the-loop control flow, we think our implementation is simpler to understand top to bottom. You could already roll your own parallelism in a Burr action manually, so with this new functionality we focused on simplifying that and integrating parallelism deeply within the Burr UI for a better observability and user experience.</p><h2>Next steps</h2><p>Although we covered the basics of parallelism, there is still quite a bit more to cover. In particular &#8211; what happens when you lose track of your execution halfway through (E.G. accidentally hit ctrl-c during execution)? Can you ensure all tasks will restart where they left off? Furthermore, multithreading won&#8217;t always work &#8211; especially if you have anything that requires specialized compute. In the <a href="https://blog.dagworks.io/p/5baf1077-2490-44bc-afff-fcdafe18e819">next post</a>, we will talk about how to make this truly distributed with Ray, and ensure that it is fault-tolerant &#8211; upon failure, it can resume where it left off.</p><h2>Further Reading</h2><p>If you&#8217;re interested in learning more about Burr:</p><ul><li><p>Find the code for this example <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/ray">here</a> (note this is the same as the next post)</p></li><li><p>Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a> for help or if you have questions!</p></li><li><p><a href="https://www.youtube.com/@dagworks-inc">Subscribe to our youtube</a> to watch some in-depth tutorials/overviews</p></li><li><p>Star our <a href="https://github.com/dagworks-inc/burr">Github repository</a> if you like what you see</p></li><li><p>Check out the recent <a href="https://burr.dagworks.io/reference/integrations/opentelemetry/">OpenTelemetry integration</a> for additional observability</p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Deep dive on Hamilton Decorators ]]></title><description><![CDATA[My journey into the heart of one of Hamilton's most powerful abstractions...]]></description><link>https://blog.dagworks.io/p/deep-dive-on-hamilton-decorators</link><guid isPermaLink="false">https://blog.dagworks.io/p/deep-dive-on-hamilton-decorators</guid><dc:creator><![CDATA[Jernej Frank]]></dc:creator><pubDate>Wed, 18 Dec 2024 14:02:36 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Ho ho ho, tis the Christmas season; when everyone is decorating their Christmas trees, I am excited to talk about decorating Python functions (leave me a present under my abstract syntax tree, please&#8230;).</em></p><h1>Introduction</h1><p>Data-driven decision-making is a useful addition to most businesses. However, a common obstacle to adoption is the slow development-to-production lifecycle; while the initial building stage often involves more effort, the ongoing adjustment of dataflows to new demands should not require a full rewrite. Hamilton creates expressive dataflows to keep data pipeline lifecycles short by improving code readability and maintenance ease.</p><p>An important challenge in designing Hamilton was to address the trade-off between asset visibility and function cluttering, which makes code unmaintainable and unreadable. We represent the data pipeline as nodes in a Directed Acyclic Graph (DAG) and designed an internal decorator lifecycle framework to perform DAG-level manipulation. Nodes provide the necessary interface layer abstracting away from Python functions and, in conjunction with the decorator lifecycle, reducing code verbosity.</p><p>In this post, we talk about a few things:</p><ol><li><p>How Hamilton, can improve your dataflow building capabilities and increase team productivity.</p></li><li><p>How Hamilton naturally represents the trade-off between explicitness and verbosity.</p></li><li><p>How Hamilton uses decorators to overcome that trade-off and make everyone more productive.</p></li><li><p>How Hamilton implements the fine-grained details of the architecture and decorator lifecycle.</p></li></ol><p>If you just want to get a sense of why you want to use Hamilton, read (1) and (2). If you want to understand some of its more advanced features, read (3). If you want to dig into the architecture of those and really want to nerd out (like I do), read (4). </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe to stay updated with the latest posts.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h1>The Power of Explicitness</h1><p>Working with data is messy; you never know what comes out or which direction you are meant to go. This entails a lot of experimentation, visualization, and hypothesis testing before you arrive at useful business insights. If you need to do this once a year, it may be acceptable to rewrite a previous analysis. Imagine now, that you need to redo the process every day, or better yet, every hour. God forbid, your colleague asks you to share your Jupyter notebook with them.</p><p>It would be good to keep track of how things change so that you can retrace your steps and, more importantly, your colleagues know what is happening / can work on the same data pipeline or re-use parts for their needs. This is where some battle-tested principles from software engineering come in handy, such as version control and breaking things apart into single functionality modules.</p><p>We can achieve this by making data transformations explicit and modular. This allows us:</p><ul><li><p>to group them conceptually together, for example creating a <a href="https://blog.dagworks.io/p/building-a-better-feature-platform?r=2cg5z1&amp;utm_campaign=post&amp;utm_medium=web">feature platform</a></p></li><li><p>finding a good balance between building fast vs. to last, for example, having <a href="https://blog.dagworks.io/p/enterprise-ready-data-pipelines-with">enterprise grade data pipelines</a></p></li><li><p>incorporating flexibility for future requirements, for example by <a href="https://blog.dagworks.io/p/separate-data-io-from-transformation">decoupling the different pipeline stages</a></p></li></ul><p>The aim is to turn a messy Jupyter notebook used for data analysis into a structured data pipeline (organized in Python modules). This naturally leads to better code readability and to the codebase being better maintained. Hamilton is an opinionated but lightweight framework that enables exactly that.</p><h2>What is Hamilton?</h2><p>Hamilton is a standardized way of building dataflows, a.k.a. &#8220;pipelines&#8221;, in Python. The core concepts are simple &#8211; you write each data transformation step as a single Python function with the following rules:</p><ol><li><p>The name of the function corresponds to the output variable it computes.</p></li><li><p>The parameter names (and types) correspond to inputs. These can be either passed-in parameters or names of other upstream functions.</p></li></ol><p>This approach allows you to represent assets in ways that correspond closely to code, naturally self-documenting, and portable across infrastructure.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QIOK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QIOK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg 424w, https://substackcdn.com/image/fetch/$s_!QIOK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg 848w, https://substackcdn.com/image/fetch/$s_!QIOK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!QIOK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QIOK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg" width="1130" height="704" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:704,&quot;width&quot;:1130,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QIOK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg 424w, https://substackcdn.com/image/fetch/$s_!QIOK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg 848w, https://substackcdn.com/image/fetch/$s_!QIOK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!QIOK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b1330f8-ba89-474f-a63b-3371dfcf4adc_1130x704.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>After writing your functions, you call a driver to execute them &#8211; in most cases this is a simple import/run (specifying the assets you want computed and letting the framework do the rest), but it provides options to customize execution:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wx5G!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wx5G!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg 424w, https://substackcdn.com/image/fetch/$s_!wx5G!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg 848w, https://substackcdn.com/image/fetch/$s_!wx5G!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!wx5G!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wx5G!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg" width="1438" height="398" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:398,&quot;width&quot;:1438,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wx5G!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg 424w, https://substackcdn.com/image/fetch/$s_!wx5G!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg 848w, https://substackcdn.com/image/fetch/$s_!wx5G!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!wx5G!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc55918eb-f83f-4413-8aa2-cea8c8bf6f82_1438x398.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/c5f46a612bf498d3100936b84d693ea3">gist</a></figcaption></figure></div><p>Visit <a href="https://www.tryhamilton.dev/">tryhamilton.dev</a> for a quick interactive introduction in the browser.</p><h1>Explicitness/Verbosity Trade-Off</h1><p>Hamilton's main (initial) selling point is explicitness. For every asset you have a corresponding function -- modifying that asset is an O(1) operation (a simple lookup), which can help iteration/debugging speed. On the other hand, this represents an increase in the verbosity of your code. To demonstrate:</p><p>A common use case would be to pull some dates from a database and calculate the date ranges. For simplicity, let us only consider three dates leading to three date ranges that we need to input into a series forecast, and, depending on the region, the date format changes. Here is the code snippet that only uses plain Python functions and Hamilton to build our DAG.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fvbf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fvbf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png 424w, https://substackcdn.com/image/fetch/$s_!fvbf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png 848w, https://substackcdn.com/image/fetch/$s_!fvbf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png 1272w, https://substackcdn.com/image/fetch/$s_!fvbf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fvbf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png" width="725" height="1437.4350086655113" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:1144,&quot;width&quot;:577,&quot;resizeWidth&quot;:725,&quot;bytes&quot;:152875,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fvbf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png 424w, https://substackcdn.com/image/fetch/$s_!fvbf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png 848w, https://substackcdn.com/image/fetch/$s_!fvbf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png 1272w, https://substackcdn.com/image/fetch/$s_!fvbf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8007b295-259f-4ee4-93ca-002e16fa698c_577x1144.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Very verbose! See gist <a href="https://gist.github.com/elijahbenizzy/97a21de97d12dbeb96389f1e7d8cefb6">here</a>.</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XAo5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XAo5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png 424w, https://substackcdn.com/image/fetch/$s_!XAo5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png 848w, https://substackcdn.com/image/fetch/$s_!XAo5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png 1272w, https://substackcdn.com/image/fetch/$s_!XAo5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XAo5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png" width="726" height="229.97135636057288" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:376,&quot;width&quot;:1187,&quot;resizeWidth&quot;:726,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XAo5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png 424w, https://substackcdn.com/image/fetch/$s_!XAo5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png 848w, https://substackcdn.com/image/fetch/$s_!XAo5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png 1272w, https://substackcdn.com/image/fetch/$s_!XAo5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9860e9b3-d802-4749-8bcc-c64248a5d927_1187x376.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Corresponding DAG</figcaption></figure></div><p>Keeping things explicit lets us have an overview of the different assets used in that data flow. However, the increase in verbosity can actually harm code readability and maintenance.</p><p>A simple solution to decrease verbosity would be to move the database calls to &#8220;helper functions&#8221; (using an underscore prefix in the Python function tells Hamilton to ignore it in the DAG creation process). We can then create a node that takes as input the region, fetches data from the database, and converts it into datetime objects. With this, we are already able to decrease the verbosity a bit.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7uS3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7uS3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png 424w, https://substackcdn.com/image/fetch/$s_!7uS3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png 848w, https://substackcdn.com/image/fetch/$s_!7uS3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png 1272w, https://substackcdn.com/image/fetch/$s_!7uS3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7uS3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png" width="725" height="1222.2513089005236" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:966,&quot;width&quot;:573,&quot;resizeWidth&quot;:725,&quot;bytes&quot;:103736,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7uS3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png 424w, https://substackcdn.com/image/fetch/$s_!7uS3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png 848w, https://substackcdn.com/image/fetch/$s_!7uS3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png 1272w, https://substackcdn.com/image/fetch/$s_!7uS3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81bce45f-5381-4377-b7d9-3b23fd85fb3a_573x966.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/3d46648c0ba8e0b43ef32ddb0071ca4b">gist</a></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yhI4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yhI4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png 424w, https://substackcdn.com/image/fetch/$s_!yhI4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png 848w, https://substackcdn.com/image/fetch/$s_!yhI4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png 1272w, https://substackcdn.com/image/fetch/$s_!yhI4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yhI4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png" width="727" height="476.52100840336135" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:390,&quot;width&quot;:595,&quot;resizeWidth&quot;:727,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yhI4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png 424w, https://substackcdn.com/image/fetch/$s_!yhI4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png 848w, https://substackcdn.com/image/fetch/$s_!yhI4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png 1272w, https://substackcdn.com/image/fetch/$s_!yhI4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b563f39-a99f-4d17-a138-3e80c028e3e0_595x390.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding DAG</figcaption></figure></div><p>This improves the readability a lot! As a first pass at building your dataflow, this can be &#8220;good enough&#8221; and just using these basic functionalities can serve you for a long time.</p><p>Two points to note here; firstly, we reduced code verbosity at the expense of reducing explicitness since we hid the database calls. Secondly, we still have a lot of &#8220;empty functions&#8221; for the three dates each just returning a single value of a dictionary &#8211; imagine we have a dictionary with 20 entries!</p><p>It is time to ask: Can we refine the code further by moving core programming concepts such as loops and conditionals to the explicit DAG level?</p><h1>Overcoming the Trade-Off: Using Decorators to Perform DAG Operations</h1><p>We are looking for a solution that remains explicit (easy to read/plain English/easy to debug), but it is also much easier to develop/iterate on. It should both cut down on verbosity and allow for abstractions.</p><p>Hamilton does this with Python decorators. We are aware that decorators are an advanced concept in Python, but at the same time, we believe we made using them quite simple and provide lots of <a href="https://hamilton.dagworks.io/en/latest/reference/decorators/">documentation</a>.</p><p>In case you are not familiar with decorators in Python, they are functions that take as an argument an existing function, modify it in some way, and output a new function. See: <a href="https://realpython.com/primer-on-python-decorators/">https://realpython.com/primer-on-python-decorators/</a> for a detailed explanation. Hamilton uses decorators to attach instructions on how the local subgraph arising from the decorated function should be modified and has its own compiler that uses this data in the DAG creation process (see (4) for a more detailed explanation).</p><p>Let&#8217;s continue iterating on the same example and refactor the &#8220;empty functions&#8221; using <a href="https://hamilton.dagworks.io/en/latest/reference/decorators/extract_fields/">@extract_fields</a>. This directly corresponds to having a loop on the DAG level (for other concepts such as if/else conditionals and re-using nodes, check out the BONUS section at the end where we use multiple decorators at the same time). We get the following code:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MPOB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MPOB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png 424w, https://substackcdn.com/image/fetch/$s_!MPOB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png 848w, https://substackcdn.com/image/fetch/$s_!MPOB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png 1272w, https://substackcdn.com/image/fetch/$s_!MPOB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MPOB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png" width="725" height="801.3599537037037" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:955,&quot;width&quot;:864,&quot;resizeWidth&quot;:725,&quot;bytes&quot;:130111,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MPOB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png 424w, https://substackcdn.com/image/fetch/$s_!MPOB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png 848w, https://substackcdn.com/image/fetch/$s_!MPOB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png 1272w, https://substackcdn.com/image/fetch/$s_!MPOB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9885bc1d-ebbc-4188-8ffc-affd2d3c8131_864x955.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/5a1cd2a0f168efecf6a5ad9846f6cb17">gist</a></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9eib!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9eib!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png 424w, https://substackcdn.com/image/fetch/$s_!9eib!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png 848w, https://substackcdn.com/image/fetch/$s_!9eib!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png 1272w, https://substackcdn.com/image/fetch/$s_!9eib!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9eib!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png" width="727" height="476.52100840336135" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:390,&quot;width&quot;:595,&quot;resizeWidth&quot;:727,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9eib!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png 424w, https://substackcdn.com/image/fetch/$s_!9eib!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png 848w, https://substackcdn.com/image/fetch/$s_!9eib!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png 1272w, https://substackcdn.com/image/fetch/$s_!9eib!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5dbf64f4-6437-4156-92f7-eeab0a33a862_595x390.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding DAG</figcaption></figure></div><p>Great, with a single decorator we cut down on verbosity by eliminating three functions while maintaining the DAG structure. Several things happen in the background that we will dive into later, but for now, notice how adding a new date for example involves only adding an entry to the attached decorator that creates a node out of it.</p><p>Likewise, the module is less cluttered which makes it easier to understand. It also allows us to quickly add or remove assets based on our needs, which accelerates the development-to-production cycle. Lastly, with fewer functions, we have a smaller code area to cover and our testing process is simplified.</p><p>While Hamilton provides you with a powerful, high-level language to build dataflows, you don't have to (and probably shouldn't) jump straight into the deep end. Rather, you can start like above with plain Python and helper functions. Once you see the code getting verbose/messy, you can refactor by creating conditional branches or making the code <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a>) by defining common data transformations and decorating the corresponding asset functions - Hamilton will do the rest and construct the correct DAG for you. If you are interested in what happens in the background, we will be digging into Hamilton&#8217;s decorator framework for the rest of this post -- buckle in! We're going to go very low-level.</p><h1>The Nitty-Gritty Details</h1><p>Before we look at decorators in detail, let us take a step back and understand Hamilton under the hood. In the background, Hamilton abstracts away from user-defined functions and associates them to an object class <em>Nodes</em>, which in turn connect based on names and types, forming a graph. Based on the requested outputs, Hamilton only selects necessary nodes connecting the two endpoints and runs the minimal DAG. This abstraction layer provides the necessary interface we need to use decorators for graph operations.</p><p>Let us first go through the high-level overview of how Hamilton creates a DAG (see Figure 1). We start with defining the DAG (user input):</p><ol><li><p>Create a Python module and define functions inside.</p></li><li><p>Use Hamilton decorators on some of the functions.</p></li><li><p>Specify the Python module and optional config file for the Hamilton Driver that creates the DAG.</p></li></ol><p>In the last step Hamilton does the following:</p><ol><li><p>Collect all functions from the provided module. Skip functions that start with an underscore (i.e., helper functions).</p></li><li><p>Loop through the collected functions and for each function determine which decorators were used.</p></li><li><p>Go through the list of used decorator classes in order of priority and transform the subgraph of that function.</p></li><li><p>Return the subgraph (can be empty).</p></li><li><p>Connect all the subgraphs together into a DAG and validate it.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HMIM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HMIM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png 424w, https://substackcdn.com/image/fetch/$s_!HMIM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png 848w, https://substackcdn.com/image/fetch/$s_!HMIM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png 1272w, https://substackcdn.com/image/fetch/$s_!HMIM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HMIM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png" width="1308" height="645" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:645,&quot;width&quot;:1308,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HMIM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png 424w, https://substackcdn.com/image/fetch/$s_!HMIM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png 848w, https://substackcdn.com/image/fetch/$s_!HMIM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png 1272w, https://substackcdn.com/image/fetch/$s_!HMIM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4465eabf-d601-4435-8655-9dc125d8a495_1308x645.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The compilation of Hamilton lifecycle decorators</figcaption></figure></div><p>Great, now that we have the big picture let us explore how Hamilton creates subgraphs and, in particular, how the decorator framework is implemented. At the heart of the decorator lifecycle is the <strong>NodeTransformLifecycle </strong>abstract class. The class defines the high-level interface/functionality all child classes need as well as implements the <em>call</em> method of the decorator, which watermarks the decorated function with the specific decorator.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></p><p>This implementation, where we attach the decorator to the function and delay its execution, allows us to decouple the concrete user instance and subgraph transformations. In other words, the user first gets to define what subgraph transformation he wants to perform before the DAG even exists and delays the execution until we build that part of the DAG and the operations make sense to execute.</p><p>If there are no decorators attached to the function, a simple subgraph consisting of a single node corresponding to the underlying function gets created.</p><p>Otherwise, for a function with decorators, the decorators get executed in order of subgraph transformation relevance each taking in the output of the prior subgraph transformation:</p><ol><li><p>NodeResolver: determine if the subgraph should be present.</p></li><li><p>NodeCreator: construct subgraph node(s) out of the underlying function.</p></li><li><p>NodeInjector: inject a subgraph before the current node.</p></li><li><p>NodeExpander: expand the current node into multiple new nodes.</p></li><li><p>NodeTransformer: transform the output of the current node.</p></li><li><p>NodeDecorator: add metadata to the current node.</p></li></ol><p>This precedence order is critical for chaining together multiple subgraph transformations (stacking decorators) or informing the user that certain operations are incompatible with one another. For example, we can hardly expand the current node into many others if no current node exists.</p><p>In the following, we describe each subgraph transformation class and provide a use case. To view all supported subgraph transformations please see the <a href="https://hamilton.dagworks.io/en/latest/reference/decorators/">decorators reference</a>.</p><h2>NodeResolver</h2><p>The first decorator class resolves whether nodes should be created or not. It is the first decorator class called in the lifecycle since it determines the if/else conditionals for the whole subgraph arising from other decorators on that function.</p><p>A prime example is to decorate a function with <a href="https://hamilton.dagworks.io/en/latest/reference/decorators/config_when/#">@config.when</a>, which creates a key-value pair that is used at DAG creation runtime to determine if we short-circuit the lifecycle and output an empty list (no nodes associated with this function).</p><p>In this case, we have two different transforms: &#8220;transform__a&#8221; and &#8220;transform__b&#8221;. For &#8220;transform__a&#8221;, the NodeResolver gets called with the provided config and returns the node associated with it. Since Python does not allow two functions to have the same name (and we access all functions in a module by inspecting it) we differentiate the two functions by appending a double underscore namespace that will get stripped when resolved. For the &#8220;transform__b&#8221;, the NodeResolver returns an empty list (no node is created) since the condition is not fulfilled. We can select which transform (either a or b) gets executed by providing the correct config to the driver at runtime.</p><p>In case we do not use the decorator, we would need to define an additional node collecting &#8220;transform__a&#8221; and &#8220;transform__b&#8221; with the body performing an if/else statement based on the additional config input.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mVr6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mVr6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png 424w, https://substackcdn.com/image/fetch/$s_!mVr6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png 848w, https://substackcdn.com/image/fetch/$s_!mVr6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png 1272w, https://substackcdn.com/image/fetch/$s_!mVr6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mVr6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png" width="464" height="500" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:464,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mVr6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png 424w, https://substackcdn.com/image/fetch/$s_!mVr6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png 848w, https://substackcdn.com/image/fetch/$s_!mVr6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png 1272w, https://substackcdn.com/image/fetch/$s_!mVr6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531b54f3-933f-4492-9d05-f3344b6bfe96_464x500.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Before</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!53Oq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!53Oq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png 424w, https://substackcdn.com/image/fetch/$s_!53Oq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png 848w, https://substackcdn.com/image/fetch/$s_!53Oq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png 1272w, https://substackcdn.com/image/fetch/$s_!53Oq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!53Oq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png" width="570" height="383" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:383,&quot;width&quot;:570,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!53Oq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png 424w, https://substackcdn.com/image/fetch/$s_!53Oq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png 848w, https://substackcdn.com/image/fetch/$s_!53Oq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png 1272w, https://substackcdn.com/image/fetch/$s_!53Oq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff48dbae9-b85f-4767-a23c-bde97e722ed2_570x383.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">after</figcaption></figure></div><h2><br>NodeCreator</h2><p>The decorator class creates a subgraph consisting of at least one node out of the current function. It is the first decorator class creating a subgraph that all the consequent decorator classes apply transformations on. In case the function has no additional decorators, this class still gets called to create a node out of the function.</p><p>For example <a href="https://hamilton.dagworks.io/en/latest/reference/decorators/dataloader/">@dataloader</a> allows us to specify that a certain function is meant to be an I/O interface.</p><p>Below we have a node loading JSON data and an additional node created for its metadata (materializer). In case we do not use the decorator, the additional node disappears.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-YBc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-YBc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png 424w, https://substackcdn.com/image/fetch/$s_!-YBc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png 848w, https://substackcdn.com/image/fetch/$s_!-YBc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png 1272w, https://substackcdn.com/image/fetch/$s_!-YBc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-YBc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png" width="507" height="281" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:281,&quot;width&quot;:507,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-YBc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png 424w, https://substackcdn.com/image/fetch/$s_!-YBc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png 848w, https://substackcdn.com/image/fetch/$s_!-YBc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png 1272w, https://substackcdn.com/image/fetch/$s_!-YBc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbd34aa6-6cf5-42a1-b2c5-1cd7c1851fd2_507x281.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Before</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!M-aw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!M-aw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png 424w, https://substackcdn.com/image/fetch/$s_!M-aw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png 848w, https://substackcdn.com/image/fetch/$s_!M-aw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png 1272w, https://substackcdn.com/image/fetch/$s_!M-aw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!M-aw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png" width="530" height="257.13548387096773" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:376,&quot;width&quot;:775,&quot;resizeWidth&quot;:530,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!M-aw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png 424w, https://substackcdn.com/image/fetch/$s_!M-aw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png 848w, https://substackcdn.com/image/fetch/$s_!M-aw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png 1272w, https://substackcdn.com/image/fetch/$s_!M-aw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e9a99e3-490c-4aeb-aac9-a1de63670a1f_775x376.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">after</figcaption></figure></div><h2>NodeInjector</h2><p>The decorator class creates a subgraph and prepends it to the existing node via a specific function argument 1-to-1 map. This allows us to pre-process that argument before using it in the function. The preprocessing can be a complicated subDAG, like <a href="https://hamilton.dagworks.io/en/latest/reference/decorators/with_columns/">@with_columns</a>, or a straightforward linear chain of nodes created by<em> </em><a href="https://hamilton.dagworks.io/en/latest/reference/decorators/pipe/">@pipe_input</a>.</p><p>We take the argument &#8220;input_x&#8221; as an input argument for &#8220;_add_1&#8221;, which in turn is input into &#8220;_add_2&#8221;. We have injected a chain of 2 nodes that modify &#8220;input_x&#8221; and the result gets injected into &#8220;feature&#8221; in place of the original &#8220;input_x&#8221; argument.</p><p>In case we do not use the decorator, we could add the transformation as helper functions, but we lose lineage information or connect the nodes the conventional way forsaking the ability to reuse them.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!asOG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!asOG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png 424w, https://substackcdn.com/image/fetch/$s_!asOG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png 848w, https://substackcdn.com/image/fetch/$s_!asOG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png 1272w, https://substackcdn.com/image/fetch/$s_!asOG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!asOG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png" width="368" height="385.85074626865674" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:281,&quot;width&quot;:268,&quot;resizeWidth&quot;:368,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!asOG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png 424w, https://substackcdn.com/image/fetch/$s_!asOG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png 848w, https://substackcdn.com/image/fetch/$s_!asOG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png 1272w, https://substackcdn.com/image/fetch/$s_!asOG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb79a01fb-13b9-4005-92a5-20df4212d39c_268x281.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">before</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EThc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EThc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png 424w, https://substackcdn.com/image/fetch/$s_!EThc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png 848w, https://substackcdn.com/image/fetch/$s_!EThc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png 1272w, https://substackcdn.com/image/fetch/$s_!EThc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!EThc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png" width="402" height="487" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:487,&quot;width&quot;:402,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!EThc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png 424w, https://substackcdn.com/image/fetch/$s_!EThc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png 848w, https://substackcdn.com/image/fetch/$s_!EThc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png 1272w, https://substackcdn.com/image/fetch/$s_!EThc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb77e6408-30bc-4e5c-9b8a-22387d7a9720_402x487.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">After</figcaption></figure></div><h2>NodeExpander</h2><p>The decorator class creates a subgraph out of the existing nodes in a 1-to-many fashion. This operation allows us to avoid &#8220;empty functions&#8221; and can be thought of as a for-loop.</p><p>For example, when we have elements of a dictionary, it is cumbersome to manually create a function for each column. Instead, we can use [@extract_fields](<a href="https://hamilton.dagworks.io/en/latest/reference/decorators/extract_fields/">https://hamilton.dagworks.io/en/latest/reference/decorators/extract_fields/</a>) to create nodes out of the individual entries.</p><p>We created the three nodes &#8220;a&#8221;, &#8220;b&#8221;, and &#8220;c&#8221; and only need to specify their type to have them represented as nodes and avoid the necessity to define individual functions for each of the nodes.</p><p>In case we do not use the decorator, we are forced to manually define the three functions and do the extraction in each of them.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EqRo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EqRo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png 424w, https://substackcdn.com/image/fetch/$s_!EqRo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png 848w, https://substackcdn.com/image/fetch/$s_!EqRo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png 1272w, https://substackcdn.com/image/fetch/$s_!EqRo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!EqRo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png" width="191" height="220" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:220,&quot;width&quot;:191,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!EqRo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png 424w, https://substackcdn.com/image/fetch/$s_!EqRo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png 848w, https://substackcdn.com/image/fetch/$s_!EqRo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png 1272w, https://substackcdn.com/image/fetch/$s_!EqRo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1dbde4e0-e65e-47e2-84c1-8e0c5a71b93f_191x220.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Before</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dksc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dksc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png 424w, https://substackcdn.com/image/fetch/$s_!dksc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png 848w, https://substackcdn.com/image/fetch/$s_!dksc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png 1272w, https://substackcdn.com/image/fetch/$s_!dksc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dksc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png" width="302" height="329" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:329,&quot;width&quot;:302,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dksc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png 424w, https://substackcdn.com/image/fetch/$s_!dksc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png 848w, https://substackcdn.com/image/fetch/$s_!dksc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png 1272w, https://substackcdn.com/image/fetch/$s_!dksc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd8e0933-83e0-4d7b-9f35-557bfb20f628_302x329.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">After</figcaption></figure></div><h2>NodeTransformer</h2><p>This decorator class also creates a subgraph and appends it to the existing nodes. It allows us to post-process a node output. For example, <a href="https://hamilton.dagworks.io/en/latest/reference/decorators/pipe/">@pipe_output</a> takes the output of the function and appends a linear chain of nodes to it, which is the dual behavior of @pipe_input.</p><p>We have the same example as with @pipe_input; in contrast, the execution order with @pipe_output is first executing &#8220;feature&#8221;, which in this case is an identity function, then we apply &#8220;_add_1&#8221; and afterward &#8220;_add_2&#8221;.</p><p>In case we do not use the decorator, we could similarly use helper functions inside the existing function or connect the nodes the conventional way forsaking the ability to reuse them.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kYfI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kYfI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png 424w, https://substackcdn.com/image/fetch/$s_!kYfI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png 848w, https://substackcdn.com/image/fetch/$s_!kYfI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png 1272w, https://substackcdn.com/image/fetch/$s_!kYfI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kYfI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png" width="370" height="387.94776119402985" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:281,&quot;width&quot;:268,&quot;resizeWidth&quot;:370,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kYfI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png 424w, https://substackcdn.com/image/fetch/$s_!kYfI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png 848w, https://substackcdn.com/image/fetch/$s_!kYfI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png 1272w, https://substackcdn.com/image/fetch/$s_!kYfI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6090e453-9265-4d65-b240-d7dcbc4d1a5f_268x281.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">before</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HtlI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HtlI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png 424w, https://substackcdn.com/image/fetch/$s_!HtlI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png 848w, https://substackcdn.com/image/fetch/$s_!HtlI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png 1272w, https://substackcdn.com/image/fetch/$s_!HtlI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HtlI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png" width="402" height="611" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:611,&quot;width&quot;:402,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HtlI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png 424w, https://substackcdn.com/image/fetch/$s_!HtlI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png 848w, https://substackcdn.com/image/fetch/$s_!HtlI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png 1272w, https://substackcdn.com/image/fetch/$s_!HtlI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F594d4873-a10b-4b85-91a2-b299a2263c61_402x611.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">after</figcaption></figure></div><h2>NodeDecorator</h2><p>The last decorator class in the lifecycle allows us to attach metadata to the subgraph. For example, we can use <em>@tag</em> to add tags to nodes providing code ownership within a team and can filter the nodes that have the specific tag &#8220;team=Platform&#8221;.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8ZvW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8ZvW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png 424w, https://substackcdn.com/image/fetch/$s_!8ZvW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png 848w, https://substackcdn.com/image/fetch/$s_!8ZvW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png 1272w, https://substackcdn.com/image/fetch/$s_!8ZvW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8ZvW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png" width="725" height="256.4388736263736" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:515,&quot;width&quot;:1456,&quot;resizeWidth&quot;:725,&quot;bytes&quot;:111333,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8ZvW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png 424w, https://substackcdn.com/image/fetch/$s_!8ZvW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png 848w, https://substackcdn.com/image/fetch/$s_!8ZvW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png 1272w, https://substackcdn.com/image/fetch/$s_!8ZvW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbcc1981a-6423-4fde-b321-6f049e20db7c_1802x638.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Bonus</h2><p>Before we wrap up, we just want to have fun and share a more exotic use of decorators. Remember the initial mini-pipeline example of fetching dates and calculating periods between them?</p><p>We can STACK decorators to encapsulate all of the above <code>ddmmyy</code> functions as a single function? Practically, we can:</p><ol><li><p>Set an if/else conditional for creating a node using @config.when.</p></li><li><p>Create a separate node for each of the dates by using @extract_fields.</p></li><li><p>Convert the string from the database into Python&#8217;s datetime format by post-processing all three &#8220;a&#8221;, &#8220;b&#8221;, and &#8220;c&#8221; nodes at once using @pipe_output.</p></li></ol><p>Here is the code that does exactly that:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Hm3F!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hm3F!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png 424w, https://substackcdn.com/image/fetch/$s_!Hm3F!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png 848w, https://substackcdn.com/image/fetch/$s_!Hm3F!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png 1272w, https://substackcdn.com/image/fetch/$s_!Hm3F!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hm3F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png" width="1410" height="1678" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1678,&quot;width&quot;:1410,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:325042,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Hm3F!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png 424w, https://substackcdn.com/image/fetch/$s_!Hm3F!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png 848w, https://substackcdn.com/image/fetch/$s_!Hm3F!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png 1272w, https://substackcdn.com/image/fetch/$s_!Hm3F!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2129a118-a2a5-4532-9a80-82f7109a1920_1410x1678.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/2b668f1a871a1f94ef733ec49aacbbdf">gist</a></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-vLB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-vLB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png 424w, https://substackcdn.com/image/fetch/$s_!-vLB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png 848w, https://substackcdn.com/image/fetch/$s_!-vLB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png 1272w, https://substackcdn.com/image/fetch/$s_!-vLB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-vLB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png" width="1117" height="401" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:401,&quot;width&quot;:1117,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-vLB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png 424w, https://substackcdn.com/image/fetch/$s_!-vLB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png 848w, https://substackcdn.com/image/fetch/$s_!-vLB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png 1272w, https://substackcdn.com/image/fetch/$s_!-vLB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe0fee32d-c08b-4dda-ab82-7223029b2eaf_1117x401.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding DAG</figcaption></figure></div><p>Selecting the correct region at DAG creation eliminates the unnecessary nodes leaving us with a single region DAG. We have achieved full explicitness with a minimal increase in verbosity!</p><p>Adding a new date format involves only adding a Python function for that asset and giving it the appropriate decorators. We managed to further localize the data transformations and shorten the development-to-production cycle. The functions are concise and not cluttered with if/else statements which makes the Python module clean and easy to understand. Lastly, by keeping truly essential functions that describe our dataflow and being able to re-use some of the transformations, we can test for dataflow coherence and do not need to unit test every single node.</p><h1>Summary</h1><p>We have shown how Hamilton utilizes decorators to cut down on code verbosity while keeping explicitness intact. Hamilton strikes a balance that lets you maintain a neat codebase that can be shared across users, while at the same time offering the ability to quickly iterate on dataflows. Although Hamilton&#8217;s approach requires basic familiarity with Python decorators, it abstracts away the complicated bits and lets you enjoy the full power in a straightforward application.</p><p>While the decorator lifecycle framework addresses an important trade-off, we have identified some limitations that warrant a revision of the initial design ideas.</p><p>For example, decorators only operate on the current function and keep things very local. While creating new nodes, the decorator does not get any information from other nodes in the DAG, which makes it harder to define a global operation. First attempts at something like that are made with the <a href="https://hamilton.dagworks.io/en/latest/reference/decorators/pipe/#mutate">@mutate</a> decorator.</p><p>Another emerging issue is the choice to create new nodes for actions arising from decorators. This can quickly lead to the original DAG being cluttered with additional nodes, which complicates the overview.</p><p>If you have not yet used Hamilton, hopefully this post shows that the bar to entry is set very low (you need to use Python in your data pipelines) and once you are comfortable with the basics, have fun exploring the rich and continuously expanding decorator ecosystem. If you are already a seasoned Hamilton user, give us a shout about your experience using decorators and we will incorporate your feedback in our next major overhaul of the decorator lifecycle framework!</p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>The watermarking does the following: the user defines a decorator instance, where the <strong>call</strong> method attaches the same instance to the decorated function as an attribute. During the graph building procedure, we can then collect for each function all the decorators and call on their internal methods that predefine subgraph operations based on the user-provided input at instance creation.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[Burr + BentoML: LLM agent deployment made easy]]></title><description><![CDATA[How to deploy a web page Q&A bot with Burr and BentoML]]></description><link>https://blog.dagworks.io/p/burr-bentoml-llm-agent-deployment</link><guid isPermaLink="false">https://blog.dagworks.io/p/burr-bentoml-llm-agent-deployment</guid><dc:creator><![CDATA[Thierry Jean]]></dc:creator><pubDate>Wed, 11 Dec 2024 13:32:28 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/d132e104-464f-4bf6-b41c-9335ec4ed833_1455x1047.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You build an LLM agent that works locally, but now you want to deploy it and make it available to users. You need to start thinking about:</p><ol><li><p>Package code + dependencies into a container</p></li><li><p>Create API endpoints to interact with the agent</p></li><li><p>Create a client to interact with the endpoints reliably</p></li><li><p>Manage resources and batch requests for efficient processing</p></li><li><p>Monitor API usage</p></li><li><p>Track how your agent behave</p></li><li><p>Persist data produced by the agent for debugging and create training data</p></li><li><p>Add hooks and alerts for certain agent behavior</p></li><li><p>&#8230; and more</p></li></ol><p><a href="https://github.com/dagworks-inc/burr">Burr</a> is an open source framework to build LLM agents and all types of applications that make (or help make) decisions. <a href="https://github.com/bentoml/BentoML">BentoML</a> is an open source library specialized for deploying LLM, ML, and AI services. Together, they provide the <strong>application</strong> and <strong>serving </strong>layers to solve the aforementioned problems.</p><blockquote><p>Find the<a href="https://github.com/bentoml/BentoBurr"> full example on GitHub</a></p></blockquote><h2>Application layer</h2><p>With Burr, you create an <code>Application</code> by defining all the possible <strong>actions</strong> and the <strong>transitions</strong> between them. The result is graph that&#8217;s easy to reason about, making your application easy to reason about and debug.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!acUf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!acUf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png 424w, https://substackcdn.com/image/fetch/$s_!acUf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png 848w, https://substackcdn.com/image/fetch/$s_!acUf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png 1272w, https://substackcdn.com/image/fetch/$s_!acUf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!acUf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png" width="449" height="188.21314387211368" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:236,&quot;width&quot;:563,&quot;resizeWidth&quot;:449,&quot;bytes&quot;:17529,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!acUf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png 424w, https://substackcdn.com/image/fetch/$s_!acUf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png 848w, https://substackcdn.com/image/fetch/$s_!acUf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png 1272w, https://substackcdn.com/image/fetch/$s_!acUf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42d01e28-79b5-48bb-87fc-093e996e1bb0_563x236.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Graph of an application loading a web page and answering questions about it using an LLM</figcaption></figure></div><p>Actions can read from / write to a centralized <strong>state</strong>. By storing the state, you create checkpoints you can resume from. This enables <a href="https://blog.dagworks.io/p/travel-back-in-time-with-burr?">&#8220;time-travel&#8221; debugging</a> where you move backwards through states to see where things went wrong. </p><p>When building the <code>Application</code>, you can directly add the persistence, hooks, and telemetry necessary for production via the <code>ApplicationBuilder</code>. Then, you can run your application step, iterate over actions, or run until a halting condition, synchronously or asynchronously.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VG5u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VG5u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png 424w, https://substackcdn.com/image/fetch/$s_!VG5u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png 848w, https://substackcdn.com/image/fetch/$s_!VG5u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png 1272w, https://substackcdn.com/image/fetch/$s_!VG5u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VG5u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png" width="1288" height="1200" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1200,&quot;width&quot;:1288,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:189497,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!VG5u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png 424w, https://substackcdn.com/image/fetch/$s_!VG5u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png 848w, https://substackcdn.com/image/fetch/$s_!VG5u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png 1272w, https://substackcdn.com/image/fetch/$s_!VG5u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bc88a45-0a3e-4b68-b3da-3eca10920fd9_1288x1200.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Burr comes with the open source Burr UI, which allows you to track live execution, inspect past runs, annotate data, create tests fixtures, and more.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iQBz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iQBz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png 424w, https://substackcdn.com/image/fetch/$s_!iQBz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png 848w, https://substackcdn.com/image/fetch/$s_!iQBz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png 1272w, https://substackcdn.com/image/fetch/$s_!iQBz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iQBz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png" width="1456" height="886" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:886,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:227444,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iQBz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png 424w, https://substackcdn.com/image/fetch/$s_!iQBz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png 848w, https://substackcdn.com/image/fetch/$s_!iQBz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png 1272w, https://substackcdn.com/image/fetch/$s_!iQBz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78b0fcb2-1446-489f-ac42-abaa80e701fd_2151x1309.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Serving layer</h2><p>BentoML allows you to define a service using a Python class. Its methods, sync or async, will automatically be converted to API endpoints. You can also specify the number of workers and the resources (e.g., CPU, RAM, GPU) required for your service. It also offers <a href="https://docs.bentoml.com/en/latest/scale-with-bentocloud/scaling/autoscaling.html">autoscaling based on service traffic</a>.</p><p>AI, LLM, and ML inference is challenging because preprocessing inputs and making predictions is often an expensive operation. The main way to improve throughput and reduce latency is to batch requests. You could do this manually, but BentoML provides <a href="https://docs.bentoml.com/en/latest/get-started/adaptive-batching.html">adaptive batching</a> out of the box!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NiB3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NiB3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png 424w, https://substackcdn.com/image/fetch/$s_!NiB3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png 848w, https://substackcdn.com/image/fetch/$s_!NiB3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png 1272w, https://substackcdn.com/image/fetch/$s_!NiB3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NiB3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png" width="1456" height="915" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:915,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:180721,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NiB3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png 424w, https://substackcdn.com/image/fetch/$s_!NiB3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png 848w, https://substackcdn.com/image/fetch/$s_!NiB3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png 1272w, https://substackcdn.com/image/fetch/$s_!NiB3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb576014c-0e65-4a73-9b24-53f107b46e1a_1546x972.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Define a service to deploy a Burr application with a /run endpoint to launch it.</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tMV3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tMV3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png 424w, https://substackcdn.com/image/fetch/$s_!tMV3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png 848w, https://substackcdn.com/image/fetch/$s_!tMV3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png 1272w, https://substackcdn.com/image/fetch/$s_!tMV3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tMV3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png" width="577" height="607.1181318681319" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1532,&quot;width&quot;:1456,&quot;resizeWidth&quot;:577,&quot;bytes&quot;:181805,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tMV3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png 424w, https://substackcdn.com/image/fetch/$s_!tMV3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png 848w, https://substackcdn.com/image/fetch/$s_!tMV3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png 1272w, https://substackcdn.com/image/fetch/$s_!tMV3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ace738e-52d9-432d-a776-c6ae0c49df81_1785x1878.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The generated API documentation</figcaption></figure></div><p>After defining your service class, you want to configure how to package your service. You need to specify the files to include, the Python requirements, and environment variables to read from the host. BentoML uses this configuration to efficiently build a Docker image, and it will automatically update it when required.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pKHh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pKHh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png 424w, https://substackcdn.com/image/fetch/$s_!pKHh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png 848w, https://substackcdn.com/image/fetch/$s_!pKHh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png 1272w, https://substackcdn.com/image/fetch/$s_!pKHh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pKHh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png" width="539" height="349.56504854368933" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cd10d028-3730-4e00-8375-f5903b918283_1030x668.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:668,&quot;width&quot;:1030,&quot;resizeWidth&quot;:539,&quot;bytes&quot;:89518,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pKHh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png 424w, https://substackcdn.com/image/fetch/$s_!pKHh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png 848w, https://substackcdn.com/image/fetch/$s_!pKHh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png 1272w, https://substackcdn.com/image/fetch/$s_!pKHh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd10d028-3730-4e00-8375-f5903b918283_1030x668.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Now, run this command to launch your service:</p><pre><code>bentoml serve .</code></pre><p>BentoML is also capable of automatically generating a client for your service. By creating a <code>SyncHTTPClient</code> object pointed to the service URL, you get a client object with methods that matches the service definition.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XkRQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XkRQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png 424w, https://substackcdn.com/image/fetch/$s_!XkRQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png 848w, https://substackcdn.com/image/fetch/$s_!XkRQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png 1272w, https://substackcdn.com/image/fetch/$s_!XkRQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XkRQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png" width="1254" height="364" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:364,&quot;width&quot;:1254,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43974,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XkRQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png 424w, https://substackcdn.com/image/fetch/$s_!XkRQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png 848w, https://substackcdn.com/image/fetch/$s_!XkRQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png 1272w, https://substackcdn.com/image/fetch/$s_!XkRQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd5e33fe1-61f9-4933-8a07-dc760a22ca73_1254x364.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The client receives the .run() method from the WebPageQAService.</figcaption></figure></div><p>With the same deployment and client, you can query the API <a href="https://docs.bentoml.com/en/latest/get-started/async-task-queues.html">asynchronously by using a task queue</a>. For instance, instead of calling <code>.run()</code>, you would submit a task via <code>.run.submit()</code> and wait for the task status to be <code>completed</code> and get the result.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/subscribe?"><span>Subscribe now</span></a></p><h2>Deployment options</h2><p>Burr and BentoML are two open-source projects that you&#8217;re free to self-host. Alternatively, <a href="https://docs.bentoml.com/en/latest/scale-with-bentocloud/manage-api-tokens.html">BentoCloud</a> can host your deployment and provide an interface with permissions, secret management, logs and status, and service versioning. When deploying in the cloud, Burr will need a destination to persist state and send telemetry. Here&#8217;s <a href="https://github.com/DAGWorks-Inc/burr/tree/main/burr/tracking/server/s3">the details for setting up Burr&#8217;s UI on AWS S3</a>.</p><h1>Conclusion</h1><p>The path to deploying LLM agents is paved with engineering challenges. Good tools should minimize the number of engineering problems to solve and let you focus on the aspect unique to your business that generate value. With Burr for the application layer and BentoML for serving, many challenges are solved before you encounter them yourself.</p><h1>We want to hear from you!</h1><p>If you&#8217;re excited by any of this, or have strong opinions:</p><p>&#127857; <a href="https://l.bentoml.com/join-slack">BentoML Slack</a> (<a href="https://github.com/bentoml/BentoML">GitHub</a>)</p><p>&#129302; <a href="https://discord.gg/6Zy2DwP4f3">Burr Discord</a><a href="https://hamilton-opensource.slack.com/join/shared_invite/zt-1bjs72asx-wcUTgH7q7QX1igiQ5bbdcg#/shared-invite/email">&#8202;</a> (<a href="https://github.com/dagworks-inc/burr">GitHub</a>)</p><p>&#128218; <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples">More Burr examples</a></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;f46cad3a-93ee-4320-8326-05953befd0c9&quot;,&quot;caption&quot;:&quot;Ready-made solutions and large language model (LLM) frameworks can get you started quickly with GenAI, but two years after ChatGPT&#8217;s release, teams are feeling the limitations of these tools. The reality is that retrieval augmented generation (RAG) or LLM agents are broad approaches rather than a single thing.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;The graduation problem: avoid frameworks getting in the way&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-11-21T17:58:59.393Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3336f44c-5558-48c3-aa6f-4d50e9e3188c_1456x1048.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/the-graduation-problem-avoid-frameworks&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:151976893,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:5,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;fe774b1b-516f-4b83-b709-235460144a08&quot;,&quot;caption&quot;:&quot;With new innovations each week: chatbots, retrieval-augmented generation (RAG), LLM agents, tool usage, multi-agents, multi-modal LLMs, choosing a framework to start building can be a difficult decision.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Build LLM agents faster with Haystack + Burr!&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-10-31T13:01:10.918Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c1002fb7-034a-4a42-ada4-f628007d29a4_1455x1047.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/build-llm-agents-faster-with-haystack&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:150728469,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:5,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[The graduation problem: avoid frameworks getting in the way]]></title><description><![CDATA[Use the 2-layer approach to build a maintainable system]]></description><link>https://blog.dagworks.io/p/the-graduation-problem-avoid-frameworks</link><guid isPermaLink="false">https://blog.dagworks.io/p/the-graduation-problem-avoid-frameworks</guid><dc:creator><![CDATA[Thierry Jean]]></dc:creator><pubDate>Thu, 21 Nov 2024 17:58:59 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/3336f44c-5558-48c3-aa6f-4d50e9e3188c_1456x1048.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Ready-made solutions and large language model (LLM) frameworks can get you started quickly with GenAI, but two years after ChatGPT&#8217;s release, teams are feeling the limitations of these tools. The reality is that retrieval augmented generation (RAG) or LLM agents are broad approaches rather than a single thing. </p><p>From proof-of-concept to deployment and maintenance, your technical needs will evolve. To build a reliable product, you will inevitably need custom code and some frameworks may get in the way more than others.</p><p>This post will show how a RAG feature typically evolves using three versions of the same project. We will use the <strong>2-layer approach </strong>to handle the growing complexity and ensure that we create a maintainable solution without ready-made components.</p><blockquote><p>Follow along on <a href="https://github.com/DAGWorks-Inc/burr/blob/main/examples/hamilton-integration/notebook.ipynb">GitHub</a> or <a href="https://colab.research.google.com/github/dagworks-inc/burr/blob/main/examples/hamilton-integration/notebook.ipynb">Google Colab</a></p></blockquote><h2>The 2-layer approach</h2><p>The 2-layer approach separates the low-level implementation (layer 1) from the high-level application logic (layer 2). Layer 2 encodes &#8220;how the system should make decisions and behave&#8221; and Layer 1 processes the data to make these decisions possible.</p><p>Burr is a Python framework specifically focused on Layer 2. It structures an <code>Application </code>as a set of actions, transitions &amp; conditions between actions, and state shared between actions. It comes with useful features for deployment such as state persistence, telemetry, annotations, and more. Then, Layer 1 is encapsulated in individual actions (for another example of these concepts in action see our <a href="https://blog.dagworks.io/p/build-llm-agents-faster-with-haystack">Burr + Haystack post</a>).</p><h2>Version 1: a simple LLM pipeline</h2><p>It may be counterintuitive, but you should start with the high-level logic and determine the intended behavior of your application. Skipping these initial questions usually leads to refactoring and slows down development.</p><h3>Layer 2: Define the Application logic</h3><p>In the next snippet, we outline the logic to ingest a blog post and ask questions over its content. Note that we haven&#8217;t implemented <code>@actions</code> yet, but we get the ability to build and view the graph.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gdkk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gdkk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png 424w, https://substackcdn.com/image/fetch/$s_!gdkk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png 848w, https://substackcdn.com/image/fetch/$s_!gdkk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png 1272w, https://substackcdn.com/image/fetch/$s_!gdkk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gdkk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png" width="1442" height="1162" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1162,&quot;width&quot;:1442,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:238435,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gdkk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png 424w, https://substackcdn.com/image/fetch/$s_!gdkk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png 848w, https://substackcdn.com/image/fetch/$s_!gdkk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png 1272w, https://substackcdn.com/image/fetch/$s_!gdkk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a14396f-88dd-456d-8453-e1ffed04354a_1442x1162.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KlYT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KlYT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png 424w, https://substackcdn.com/image/fetch/$s_!KlYT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png 848w, https://substackcdn.com/image/fetch/$s_!KlYT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png 1272w, https://substackcdn.com/image/fetch/$s_!KlYT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KlYT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png" width="302" height="176.41584158415841" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:236,&quot;width&quot;:404,&quot;resizeWidth&quot;:302,&quot;bytes&quot;:13154,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KlYT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png 424w, https://substackcdn.com/image/fetch/$s_!KlYT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png 848w, https://substackcdn.com/image/fetch/$s_!KlYT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png 1272w, https://substackcdn.com/image/fetch/$s_!KlYT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F72607669-fb98-4cfb-a7f1-dfd1a90b6ab0_404x236.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3>Layer 1: Implement individual @action</h3><p>The previous outline sets &#8220;contracts&#8221; for each actions:</p><ol><li><p><code>ingest_blog </code>downloads an HTML page, parses it into a plain text.</p></li><li><p><code>ask_question</code> prompts an OpenAI LLM with the full blog in the prompt and the user query.</p></li></ol><p>It allows us to build simple implementations for each to get a functional prototype. Notice that <code>@action </code>functions (Layer 1) can use any Python library and don&#8217;t hide implementation behind complex objects. This makes it easier to adapt to evolving product requirements.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!byJn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!byJn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png 424w, https://substackcdn.com/image/fetch/$s_!byJn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png 848w, https://substackcdn.com/image/fetch/$s_!byJn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png 1272w, https://substackcdn.com/image/fetch/$s_!byJn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!byJn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png" width="1456" height="1416" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1416,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:322095,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!byJn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png 424w, https://substackcdn.com/image/fetch/$s_!byJn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png 848w, https://substackcdn.com/image/fetch/$s_!byJn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png 1272w, https://substackcdn.com/image/fetch/$s_!byJn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f1a33aa-8a88-462b-8f51-832567c22336_1546x1504.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>We can reuse the previous <code>ApplicationBuilder</code>, but we will pass the new <code>_v1</code> functions instead</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Qgsz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Qgsz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png 424w, https://substackcdn.com/image/fetch/$s_!Qgsz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png 848w, https://substackcdn.com/image/fetch/$s_!Qgsz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png 1272w, https://substackcdn.com/image/fetch/$s_!Qgsz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Qgsz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png" width="1456" height="363" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:363,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59394,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Qgsz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png 424w, https://substackcdn.com/image/fetch/$s_!Qgsz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png 848w, https://substackcdn.com/image/fetch/$s_!Qgsz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png 1272w, https://substackcdn.com/image/fetch/$s_!Qgsz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81f7941e-dda0-445d-8a4a-6f063807b06d_1462x364.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Here&#8217;s the code to launch your Burr application</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!l4D8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l4D8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png 424w, https://substackcdn.com/image/fetch/$s_!l4D8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png 848w, https://substackcdn.com/image/fetch/$s_!l4D8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png 1272w, https://substackcdn.com/image/fetch/$s_!l4D8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l4D8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png" width="1456" height="351" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b2157b9a-5f32-48bd-996e-e75529186117_1668x402.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:351,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:68820,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!l4D8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png 424w, https://substackcdn.com/image/fetch/$s_!l4D8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png 848w, https://substackcdn.com/image/fetch/$s_!l4D8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png 1272w, https://substackcdn.com/image/fetch/$s_!l4D8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2157b9a-5f32-48bd-996e-e75529186117_1668x402.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h2>Version 2: Let&#8217;s use RAG</h2><p>While <strong>Version 1</strong> simply ingested the blog and prompted the LLM, <strong>Version 2</strong> will add RAG capabilities. We have to ask ourselves: </p><blockquote><p>Are we making changes to layer 1 or 2?</p></blockquote><p>In this case, we&#8217;re focusing on Layer 1. With Burr, we can keep the same &#8220;contracts&#8221; and simply upgrade the action implementation. As you make changes, you might decide to merge/split actions, modify state variables, etc. Then, you can revisit and update your application outline.</p><h3>Layer 1: Adding RAG</h3><p>In the next snippet, you'll notice:</p><ul><li><p>we define a <code>TextDocument </code>model to create the schema of our LanceDB table. It specifies to embed the <code>text </code>field using the OpenAI model.</p></li><li><p>because text chunks are stored on disk, we don't need to pass them via the <code>Application </code>state.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FW88!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FW88!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png 424w, https://substackcdn.com/image/fetch/$s_!FW88!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png 848w, https://substackcdn.com/image/fetch/$s_!FW88!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png 1272w, https://substackcdn.com/image/fetch/$s_!FW88!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FW88!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png" width="1456" height="2674" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2674,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:745578,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FW88!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png 424w, https://substackcdn.com/image/fetch/$s_!FW88!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png 848w, https://substackcdn.com/image/fetch/$s_!FW88!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png 1272w, https://substackcdn.com/image/fetch/$s_!FW88!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0db5550-1556-4780-9bcb-0485a136060c_1874x3442.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Layer 2: Tracking and observing your application</h3><p>When developing AI systems, it&#8217;s essential to track how your application behave across versions. It&#8217;s not uncommon that new exciting techniques don&#8217;t fully deliver on promises and it&#8217;s important to assess if your earlier and simpler versions perform as well. This is a Layer 2 concern and should be decoupled from your Layer 1 implementation.  </p><p>Burr makes tracking easy. Simply add a tracker to the <code>ApplicationBuilder</code>. This is compatible with OpenTelemetry! The next snippet will enabling tracking for our RAG application and gather telemetry events from OpenAI and LanceDB.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9Tmq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9Tmq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png 424w, https://substackcdn.com/image/fetch/$s_!9Tmq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png 848w, https://substackcdn.com/image/fetch/$s_!9Tmq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png 1272w, https://substackcdn.com/image/fetch/$s_!9Tmq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9Tmq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png" width="1456" height="695" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:695,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:152322,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9Tmq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png 424w, https://substackcdn.com/image/fetch/$s_!9Tmq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png 848w, https://substackcdn.com/image/fetch/$s_!9Tmq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png 1272w, https://substackcdn.com/image/fetch/$s_!9Tmq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37717fae-b8fd-4cd4-b241-cd250b49a376_1478x706.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Now, running your application will emit events that you can see in the Burr UI</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Cp3R!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Cp3R!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png 424w, https://substackcdn.com/image/fetch/$s_!Cp3R!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png 848w, https://substackcdn.com/image/fetch/$s_!Cp3R!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png 1272w, https://substackcdn.com/image/fetch/$s_!Cp3R!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Cp3R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png" width="489" height="433.48667324777887" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:898,&quot;width&quot;:1013,&quot;resizeWidth&quot;:489,&quot;bytes&quot;:77609,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Cp3R!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png 424w, https://substackcdn.com/image/fetch/$s_!Cp3R!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png 848w, https://substackcdn.com/image/fetch/$s_!Cp3R!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png 1272w, https://substackcdn.com/image/fetch/$s_!Cp3R!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15514855-dc92-439f-8b9c-27122d1b6081_1013x898.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Burr UI has many other useful features:</p><ul><li><p>view token usage</p></li><li><p>annotate state values and logged attributes</p></li><li><p>create test fixtures from application state</p></li><li><p>and more</p></li></ul><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/subscribe?"><span>Subscribe now</span></a></p><h2>Version 3: Keeping your code modular</h2><p>You probably noticed that functions in <strong>Version 2 </strong>started to be lengthy and do several things. It&#8217;s a good occasion to refactor to smaller functions that will facilitate development, testing, and maintenance.</p><h3><strong>Layer 1: Modular actions</strong></h3><p>In the next snippets, we refactor actions using Hamilton, a lightweight library to structure data transformations as directed acyclic graphs (DAGs). Hamilton uses the function and parameter names to infer the dependencies between functions and the graph structure.</p><h4>action: ingest_blog</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!R-Bz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!R-Bz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png 424w, https://substackcdn.com/image/fetch/$s_!R-Bz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png 848w, https://substackcdn.com/image/fetch/$s_!R-Bz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png 1272w, https://substackcdn.com/image/fetch/$s_!R-Bz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!R-Bz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png" width="1456" height="2275" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2275,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:481199,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!R-Bz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png 424w, https://substackcdn.com/image/fetch/$s_!R-Bz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png 848w, https://substackcdn.com/image/fetch/$s_!R-Bz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png 1272w, https://substackcdn.com/image/fetch/$s_!R-Bz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F977a27bc-de40-450e-819a-0cb482f4f33a_1546x2416.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!d4ZY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!d4ZY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png 424w, https://substackcdn.com/image/fetch/$s_!d4ZY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png 848w, https://substackcdn.com/image/fetch/$s_!d4ZY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png 1272w, https://substackcdn.com/image/fetch/$s_!d4ZY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!d4ZY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png" width="1375" height="283" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:283,&quot;width&quot;:1375,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:41101,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!d4ZY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png 424w, https://substackcdn.com/image/fetch/$s_!d4ZY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png 848w, https://substackcdn.com/image/fetch/$s_!d4ZY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png 1272w, https://substackcdn.com/image/fetch/$s_!d4ZY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9e0ff4f-050e-46a8-a512-93d455f1bccb_1375x283.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>While this may seem trivial, these simple functions are easier to test, debug, and modify. It also allows us to develop and test actions outside of Burr. Hamilton has a great caching feature that can speed up development significantly when iterating over your application.</p><h4>action: answer_question</h4><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rHzQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rHzQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png 424w, https://substackcdn.com/image/fetch/$s_!rHzQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png 848w, https://substackcdn.com/image/fetch/$s_!rHzQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png 1272w, https://substackcdn.com/image/fetch/$s_!rHzQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rHzQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png" width="1456" height="1309" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1309,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:259893,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rHzQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png 424w, https://substackcdn.com/image/fetch/$s_!rHzQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png 848w, https://substackcdn.com/image/fetch/$s_!rHzQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png 1272w, https://substackcdn.com/image/fetch/$s_!rHzQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca588d7e-d538-4821-b6db-2bbb8418d33c_1546x1390.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TWbJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TWbJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png 424w, https://substackcdn.com/image/fetch/$s_!TWbJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png 848w, https://substackcdn.com/image/fetch/$s_!TWbJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png 1272w, https://substackcdn.com/image/fetch/$s_!TWbJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TWbJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png" width="503" height="218.98102016607353" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:367,&quot;width&quot;:843,&quot;resizeWidth&quot;:503,&quot;bytes&quot;:27226,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TWbJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png 424w, https://substackcdn.com/image/fetch/$s_!TWbJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png 848w, https://substackcdn.com/image/fetch/$s_!TWbJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png 1272w, https://substackcdn.com/image/fetch/$s_!TWbJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b16223a-f4d0-41f5-9118-15cb82cb10fb_843x367.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>We encourage considering prompt as code, which allows us to commit and version our prompt with the rest of our code. For instance, the function `system_prompt()` helps understand what information goes into the prompt and an additional docstring can add context to it.</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;ba01ccb4-2769-4d4a-b8dd-26a8283dc43f&quot;,&quot;caption&quot;:&quot;What you send to your LLM is quite important. Small variations and changes can have large impacts on outputs, so as your product evolves, the need to evolve your prompts will too. LLMs are also constantly being developed and released, and so as LLMs change, your prompts will also need to change. Therefore it&#8217;s important to set up an iteration pattern to&#8230;&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;LLMOps: Production prompt engineering patterns with Hamilton&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:73006291,&quot;name&quot;:&quot;Stefan Krawczyk&quot;,&quot;bio&quot;:&quot;MLOps + Data + LLMOps; creator of https://github.com/dagworks-inc/hamilton.\nFormerly of: Stitch Fix, Idibon, Nextdoor, LinkedIn, HRI, IBM. \nCEO @ DAGWorks - dagworks.io&quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/43b2b624-13e6-44f7-be46-ccedd3246482_3002x3002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2023-09-06T22:34:00.692Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28102ed4-d91e-49c1-87a8-695306055f19_1838x699.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/llmops-production-prompt-engineering&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:136677869,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:5,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><h3>Layer 2: Using Burr + Hamilton</h3><p>Since Burr is not opinionated about the implementation of `@action` functions, you can simply call Hamilton from it. We add the `OpenTelemetryTracer` to the Hamilton `Driver` to get tracing in Burr UI.</p><p>You'll see that the Layer 2 becomes much lighter and only the high-level logic remains.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Jm-P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Jm-P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png 424w, https://substackcdn.com/image/fetch/$s_!Jm-P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png 848w, https://substackcdn.com/image/fetch/$s_!Jm-P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png 1272w, https://substackcdn.com/image/fetch/$s_!Jm-P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Jm-P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png" width="1456" height="1281" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1281,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:254966,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Jm-P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png 424w, https://substackcdn.com/image/fetch/$s_!Jm-P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png 848w, https://substackcdn.com/image/fetch/$s_!Jm-P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png 1272w, https://substackcdn.com/image/fetch/$s_!Jm-P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bd11259-1b58-435d-a69c-5b89e09b6bf3_1494x1314.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><blockquote><p>Find more simplifications in the <a href="https://github.com/DAGWorks-Inc/burr/blob/main/examples/hamilton-integration/notebook.ipynb">full example notebook</a> </p></blockquote><p>The biggest benefit of Burr + Hamilton is the unbeatable observability you get. The Burr UI will show a granular breakdown of the operations.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rks4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rks4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png 424w, https://substackcdn.com/image/fetch/$s_!rks4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png 848w, https://substackcdn.com/image/fetch/$s_!rks4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png 1272w, https://substackcdn.com/image/fetch/$s_!rks4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rks4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png" width="517" height="415.5092322643343" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:827,&quot;width&quot;:1029,&quot;resizeWidth&quot;:517,&quot;bytes&quot;:68554,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rks4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png 424w, https://substackcdn.com/image/fetch/$s_!rks4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png 848w, https://substackcdn.com/image/fetch/$s_!rks4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png 1272w, https://substackcdn.com/image/fetch/$s_!rks4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F38bb4a07-054a-45cf-a310-3dd6858d9cba_1029x827.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Hamilton even has its dedicated <a href="https://hamilton.dagworks.io/en/latest/hamilton-ui/ui/">Hamilton UI</a> that tracks execution, catalogs data transformations, and provides in-depth introspection. We're looking to integrate the two further together!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5HZr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5HZr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png 424w, https://substackcdn.com/image/fetch/$s_!5HZr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png 848w, https://substackcdn.com/image/fetch/$s_!5HZr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png 1272w, https://substackcdn.com/image/fetch/$s_!5HZr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5HZr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png" width="539" height="325.7692307692308" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:880,&quot;width&quot;:1456,&quot;resizeWidth&quot;:539,&quot;bytes&quot;:897434,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5HZr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png 424w, https://substackcdn.com/image/fetch/$s_!5HZr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png 848w, https://substackcdn.com/image/fetch/$s_!5HZr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png 1272w, https://substackcdn.com/image/fetch/$s_!5HZr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59cc5d99-550a-4523-a5df-5a0fd87720d4_1855x1121.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Conclusion</h2><p>We presented the 2-layer approach to building a RAG application, which separates high-level logic from the implementation of individual actions.</p><p>The key lesson is that you should adopt frameworks incrementally. A tool shouldn't lock you in and limit the evolution of your application. Adopting Burr from the start helps you develop in a principled way, and adding Hamilton as the complexity increases helps with maintainability and observability. &nbsp;</p><h2>We want to hear from you!</h2><p>If you&#8217;re excited by any of this, or have strong opinions</p><p>&#128227; Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a><a href="https://hamilton-opensource.slack.com/join/shared_invite/zt-1bjs72asx-wcUTgH7q7QX1igiQ5bbdcg#/shared-invite/email">&#8202;</a></p><p>&#11088;&#65039; us on <a href="https://github.com/dagworks-inc/burr">GitHub</a></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;6fe2edef-3252-4bda-beb5-f649f8acb838&quot;,&quot;caption&quot;:&quot;Flashcards help break down complex topics and learn anything from biology to a new language or lines for a play. This blog will show how to use LLMs to generate flashcards and kickstart your learning!&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Flashcard generator with Instructor + Burr&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-11-12T17:25:45.165Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/flashcard-generator-with-instructor&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:151329068,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:4,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;ca720daf-f5ca-4ab9-9c4c-2092072fe990&quot;,&quot;caption&quot;:&quot;With new innovations each week: chatbots, retrieval-augmented generation (RAG), LLM agents, tool usage, multi-agents, multi-modal LLMs, choosing a framework to start building can be a difficult decision.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Build LLM agents faster with Haystack + Burr!&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-10-31T13:01:10.918Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c1002fb7-034a-4a42-ada4-f628007d29a4_1455x1047.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/build-llm-agents-faster-with-haystack&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:150728469,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:5,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[Flashcard generator with Instructor + Burr]]></title><description><![CDATA[Learn to use LLM structured outputs to create useful agents.]]></description><link>https://blog.dagworks.io/p/flashcard-generator-with-instructor</link><guid isPermaLink="false">https://blog.dagworks.io/p/flashcard-generator-with-instructor</guid><dc:creator><![CDATA[Thierry Jean]]></dc:creator><pubDate>Tue, 12 Nov 2024 17:25:45 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3qfL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Flashcards help break down complex topics and learn anything from biology to a new language or lines for a play. This blog will show how to use LLMs to generate flashcards and kickstart your learning! </p><p><strong>Instructor</strong> lets us get structured outputs from LLMs reliably, and <a href="https://github.com/dagworks-inc/burr">Burr</a> helps create an LLM application that's easy to understand and debug. It comes with <strong>Burr UI</strong>, a free, open-source, and local-first tool for observability, annotations, and more!</p><blockquote><p>This post is a cross-post from a <a href="https://python.useinstructor.com/blog/2024/10/18/youtube-flashcards/">guest post on the Instructor blog</a> and expands on an earlier one: <a href="https://python.useinstructor.com/blog/2024/07/11/youtube-transcripts/#extracting-chapter-information">Analyzing Youtube Transcripts with Instructor</a>. </p></blockquote><p>&#129302; <a href="https://github.com/instructor-ai/instructor/blob/main/examples/youtube-flashcards/run.py">The full code example is available on GitHub</a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for more.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>Generate flashcards using LLMs with Instructor</h2><pre><code>pip install openai instructor pydantic youtube_transcript_api "burr[start]"</code></pre><h3>1. Define the LLM response model</h3><p>With <code>instructor</code>, you define Pydantic models that will serve as template for the LLM to fill.</p><p>Here, we define the <code>QuestionAnswer</code> model which will store the question, the answer, and some metadata. Attributes without a default value will be generated by the LLM.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3qfL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3qfL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png 424w, https://substackcdn.com/image/fetch/$s_!3qfL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png 848w, https://substackcdn.com/image/fetch/$s_!3qfL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png 1272w, https://substackcdn.com/image/fetch/$s_!3qfL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3qfL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png" width="1456" height="933" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:933,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:205869,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3qfL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png 424w, https://substackcdn.com/image/fetch/$s_!3qfL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png 848w, https://substackcdn.com/image/fetch/$s_!3qfL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png 1272w, https://substackcdn.com/image/fetch/$s_!3qfL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff51d46bf-f118-42b9-ba68-3c13b1cb7b9c_1754x1124.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Define a QuestionAnswer Pydantic model</figcaption></figure></div><p>This example shows several <code>instructor</code> features:</p><ul><li><p>ue to prevent the LLM from hallucinating the value</p><ul><li><p><code>id</code> generates a unique id (<code>uuid</code>)</p></li></ul></li><li><p>The type annotation <code>SkipJsonSchema</code> also prevents the LLM from generating the value.</p><ul><li><p><code>youtube_url</code> is set programmatically in the application. We don't want the LLM to hallucinate it.</p></li></ul></li><li><p><code>Field</code> can set constraints on what the LLM generates.</p><ul><li><p><code>min_items=3, max_items=5</code> to limit the number of potential answers between 3 and 5</p></li><li><p><code>ge=0, lt=5</code> to limit the difficulty between 0 and 5 with 5 being the most difficult</p></li></ul></li></ul><h3>2. Retrieve the YouTube transcript</h3><p>We use <code>youtube-transcript-api</code> to get the full transcript of a video.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IM86!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IM86!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png 424w, https://substackcdn.com/image/fetch/$s_!IM86!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png 848w, https://substackcdn.com/image/fetch/$s_!IM86!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png 1272w, https://substackcdn.com/image/fetch/$s_!IM86!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IM86!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png" width="1202" height="326" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:326,&quot;width&quot;:1202,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:63308,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!IM86!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png 424w, https://substackcdn.com/image/fetch/$s_!IM86!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png 848w, https://substackcdn.com/image/fetch/$s_!IM86!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png 1272w, https://substackcdn.com/image/fetch/$s_!IM86!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa36dabba-3fdb-4e3b-9d9b-3c56844c6f54_1202x326.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Extract the transcript of a YouTube video</figcaption></figure></div><h3>Generate question-answer pairs</h3><p>Now, to produce question-answer pairs:</p><ol><li><p>Create an <code>instructor</code> client by wrapping the OpenAI client</p></li><li><p>Use <code>.create_iterable()</code> on the <code>instructor_client</code> to generate multiple outputs from the input</p></li><li><p>Specify <code>response_model=QuestionAnswer</code> to ensure outputs are <code>QuestionAnswer</code> objects</p></li><li><p>Use the <code>messages</code> to pass the task instructos via the <code>system</code> message, and the input transcript via <code>user</code> message.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fKTE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fKTE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png 424w, https://substackcdn.com/image/fetch/$s_!fKTE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png 848w, https://substackcdn.com/image/fetch/$s_!fKTE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png 1272w, https://substackcdn.com/image/fetch/$s_!fKTE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fKTE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png" width="1456" height="624" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:624,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:142615,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fKTE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png 424w, https://substackcdn.com/image/fetch/$s_!fKTE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png 848w, https://substackcdn.com/image/fetch/$s_!fKTE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png 1272w, https://substackcdn.com/image/fetch/$s_!fKTE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5159e87e-8bed-4855-a16d-3c9415226b5a_1736x744.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This will return an generator that you can iterate over to access individual <code>QuestionAnswer</code> objects.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lKlE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lKlE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png 424w, https://substackcdn.com/image/fetch/$s_!lKlE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png 848w, https://substackcdn.com/image/fetch/$s_!lKlE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!lKlE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lKlE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png" width="1456" height="862" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:862,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:200439,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lKlE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png 424w, https://substackcdn.com/image/fetch/$s_!lKlE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png 848w, https://substackcdn.com/image/fetch/$s_!lKlE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png 1272w, https://substackcdn.com/image/fetch/$s_!lKlE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81b36cb7-6f31-4a42-8403-78eb48986c1c_1770x1048.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">QuestionAnswer object generated by the LLM using Instructor</figcaption></figure></div><h2>Create a flashcard application with Burr</h2><p>Burr uses <code>actions</code> and <code>transitions</code> to define complex applications while preserving the simplicity of a flowchart for understanding and debugging.</p><h3>1. Define <code>actions</code></h3><p>Actions are what your application can do. The <code>@action</code> decorator specifies what values can be read from or written to <code>State</code>. The decorated function takes a <code>State</code> as first argument and return an updated <code>State</code> object.</p><p>Next, we define three actions:</p><ul><li><p>Process the user input to get the YouTube URL</p></li><li><p>Get the YouTube transcript associated with the URL</p></li><li><p>Generate question-answer pairs for the transcript</p></li></ul><p>Note that this is only a light refactor from the previous code snippets.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!e1sB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!e1sB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png 424w, https://substackcdn.com/image/fetch/$s_!e1sB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png 848w, https://substackcdn.com/image/fetch/$s_!e1sB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png 1272w, https://substackcdn.com/image/fetch/$s_!e1sB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!e1sB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png" width="1456" height="1629" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1629,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:479852,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!e1sB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png 424w, https://substackcdn.com/image/fetch/$s_!e1sB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png 848w, https://substackcdn.com/image/fetch/$s_!e1sB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png 1272w, https://substackcdn.com/image/fetch/$s_!e1sB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2e5d74b-327b-4526-99fa-3b31e1eacb8f_1752x1960.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Define 3 actions to get the user input, retrieve the YouTube transcript, and generate Q&amp;A pairs.</figcaption></figure></div><h3>2. Build the <code>Application</code></h3><p>To create a Burr <code>Application</code>, we use the <code>ApplicationBuilder</code> object.</p><p>Minimally, it needs to:</p><ul><li><p>Use <code>.with_actions()</code> to define all possible actions. Simply pass the functions decorated with <code>@action</code>.</p></li><li><p>Use <code>.with_transitions()</code> to define possible transitions between actions. This is done via tuples <code>(from_action, to_action)</code>.</p></li><li><p>Use <code>.with_entrypoint()</code> to specify which action to run first.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MG4y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MG4y!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png 424w, https://substackcdn.com/image/fetch/$s_!MG4y!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png 848w, https://substackcdn.com/image/fetch/$s_!MG4y!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png 1272w, https://substackcdn.com/image/fetch/$s_!MG4y!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MG4y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png" width="1356" height="782" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:782,&quot;width&quot;:1356,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:117421,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MG4y!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png 424w, https://substackcdn.com/image/fetch/$s_!MG4y!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png 848w, https://substackcdn.com/image/fetch/$s_!MG4y!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png 1272w, https://substackcdn.com/image/fetch/$s_!MG4y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa363b04d-de13-4e66-a6ed-0a788c69f816_1356x782.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Build an Application from actions and transitions</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3TZS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3TZS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png 424w, https://substackcdn.com/image/fetch/$s_!3TZS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png 848w, https://substackcdn.com/image/fetch/$s_!3TZS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png 1272w, https://substackcdn.com/image/fetch/$s_!3TZS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3TZS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png" width="379" height="324" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:324,&quot;width&quot;:379,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Burr application graph&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Burr application graph" title="Burr application graph" srcset="https://substackcdn.com/image/fetch/$s_!3TZS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png 424w, https://substackcdn.com/image/fetch/$s_!3TZS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png 848w, https://substackcdn.com/image/fetch/$s_!3TZS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png 1272w, https://substackcdn.com/image/fetch/$s_!3TZS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe273cb5-9d00-43c8-9be2-f8493bd48b3c_379x324.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Visualization of the created Burr Application</figcaption></figure></div><h3>3. Launch the application</h3><p>Using <code>Application.run()</code> will make the application execute actions until a halt condition. In this case, we halt before <code>process_user_input</code> to get the YouTube URL from the user.</p><p>The method <code>.run()</code> returns a tuple <code>(action_name, result, state)</code>. In this case, we only use the state to inspect the generated question-answer pairs.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tr7U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tr7U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png 424w, https://substackcdn.com/image/fetch/$s_!tr7U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png 848w, https://substackcdn.com/image/fetch/$s_!tr7U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png 1272w, https://substackcdn.com/image/fetch/$s_!tr7U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tr7U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png" width="1426" height="288" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:288,&quot;width&quot;:1426,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:48995,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tr7U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png 424w, https://substackcdn.com/image/fetch/$s_!tr7U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png 848w, https://substackcdn.com/image/fetch/$s_!tr7U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png 1272w, https://substackcdn.com/image/fetch/$s_!tr7U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F324e4c08-4dc3-4559-9202-0fd5eb27afbd_1426x288.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Launch the Application using the `.run()` method</figcaption></figure></div><p>You can create a simple local experience by using <code>.run()</code> in a <code>while</code> loop</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!s9Mi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!s9Mi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png 424w, https://substackcdn.com/image/fetch/$s_!s9Mi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png 848w, https://substackcdn.com/image/fetch/$s_!s9Mi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png 1272w, https://substackcdn.com/image/fetch/$s_!s9Mi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!s9Mi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png" width="1456" height="455" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:455,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:81306,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!s9Mi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png 424w, https://substackcdn.com/image/fetch/$s_!s9Mi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png 848w, https://substackcdn.com/image/fetch/$s_!s9Mi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png 1272w, https://substackcdn.com/image/fetch/$s_!s9Mi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e10e406-6d77-480d-a729-219a44b5417a_1530x478.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Executing the Application in a loop</figcaption></figure></div><h2>Next steps</h2><p>Now that you know how to use Instructor for reliable LLM outputs and Burr to structure your application, many avenues open up depending on your goals!</p><h3>1. Build complex agents</h3><p>Instructor improves the LLM's reasoning by providing structure. Nesting models and adding constraints allow to <a href="https://github.com/instructor-ai/instructor/blob/main/docs/examples/exact_citations.md">get facts with citations</a> or <a href="https://github.com/instructor-ai/instructor/blob/main/docs/examples/knowledge_graph.md">extract a knowledge graph</a> in a few lines of code. Also, <a href="https://github.com/instructor-ai/instructor/blob/main/docs/concepts/retrying.md">retries</a> enable the LLM to self-correct.</p><p>Burr sets the boundaries between users, LLMs, and the rest of your system. You can add <code>Condition</code> on transitions to create complex workflows that remain easy to reason about.</p><h3>2. Add Burr to your product</h3><p>Your Burr <code>Application</code> is a lightweight Python object. You can run it within a notebook, via script, a web app (Streamlit, Gradio, etc.), or as a <a href="https://burr.dagworks.io/examples/deployment/web-server/">web service</a> (e.g., FastAPI).</p><p>The <code>ApplicationBuilder</code> provides many features to productionize your app:</p><ul><li><p><a href="https://burr.dagworks.io/concepts/state-persistence/">Persistence</a>: save and restore <code>State</code> (e.g., store conversation history)</p></li><li><p><a href="https://burr.dagworks.io/concepts/additional-visibility/">Observability</a>: log and monitor application telemetry (e.g., LLM calls, number of tokens used, errors and retries)</p></li><li><p><a href="https://burr.dagworks.io/concepts/streaming-actions/">Streaming and async</a>: create snappy user interfaces by streaming LLM responses and running actions asynchronously.</p></li></ul><p>For example, you can log telemetry into Burr UI in a few lines of code. First, instrument the OpenAI library. Then, add <code>.with_tracker()</code> the <code>ApplicationBuilder</code> with a project name and enabling <code>use_otel_tracing=True</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BRhN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BRhN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png 424w, https://substackcdn.com/image/fetch/$s_!BRhN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png 848w, https://substackcdn.com/image/fetch/$s_!BRhN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png 1272w, https://substackcdn.com/image/fetch/$s_!BRhN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BRhN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png" width="1392" height="934" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e381431b-7020-419f-adf7-c1c10309c625_1392x934.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:934,&quot;width&quot;:1392,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:171002,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BRhN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png 424w, https://substackcdn.com/image/fetch/$s_!BRhN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png 848w, https://substackcdn.com/image/fetch/$s_!BRhN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png 1272w, https://substackcdn.com/image/fetch/$s_!BRhN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe381431b-7020-419f-adf7-c1c10309c625_1392x934.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Enable OpenTelemetry via the ApplicationBuilder</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!flnb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!flnb!,w_424,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif 424w, https://substackcdn.com/image/fetch/$s_!flnb!,w_848,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif 848w, https://substackcdn.com/image/fetch/$s_!flnb!,w_1272,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif 1272w, https://substackcdn.com/image/fetch/$s_!flnb!,w_1456,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!flnb!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;telemetry&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="telemetry" title="telemetry" srcset="https://substackcdn.com/image/fetch/$s_!flnb!,w_424,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif 424w, https://substackcdn.com/image/fetch/$s_!flnb!,w_848,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif 848w, https://substackcdn.com/image/fetch/$s_!flnb!,w_1272,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif 1272w, https://substackcdn.com/image/fetch/$s_!flnb!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d74fb75-fd42-4f18-b462-a9aceb52d53e_2199x1666.gif 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Telemetry for our OpenAI API calls with Instructor. We see the prompt, the response model, and the response content.</figcaption></figure></div><h3>3. Annotate application logs</h3><p>Burr UI has a built-in annotation tool that allows you to label, rate, or comment on logged data (e.g., user input, LLM response, content retrieved for RAG). This can be useful to create test cases and evaluation datasets.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DyXL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DyXL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png 424w, https://substackcdn.com/image/fetch/$s_!DyXL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png 848w, https://substackcdn.com/image/fetch/$s_!DyXL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png 1272w, https://substackcdn.com/image/fetch/$s_!DyXL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DyXL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png" width="1456" height="571" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:571,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;annotation tool&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="annotation tool" title="annotation tool" srcset="https://substackcdn.com/image/fetch/$s_!DyXL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png 424w, https://substackcdn.com/image/fetch/$s_!DyXL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png 848w, https://substackcdn.com/image/fetch/$s_!DyXL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png 1272w, https://substackcdn.com/image/fetch/$s_!DyXL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F94d04a93-cbdc-4c8c-a7bf-c270855c73ec_2996x1175.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Burr UI&#8217;s annotation menu</figcaption></figure></div><h2>Conclusion</h2><p>We've shown how Instructor helps getting reliable outputs from LLMs and Burr provides the right tools to build an application. Now it's your turn to start building!</p><h2>We want to hear from you!</h2><p>If you&#8217;re excited by any of this, or have strong opinions:</p><p>&#128227; Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a><a href="https://hamilton-opensource.slack.com/join/shared_invite/zt-1bjs72asx-wcUTgH7q7QX1igiQ5bbdcg#/shared-invite/email">&#8202;</a></p><p>&#11088;&#65039; us on <a href="https://github.com/dagworks-inc/burr">GitHub</a></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;d539ddc4-a131-41ec-b4a7-5f2203119cf4&quot;,&quot;caption&quot;:&quot;With new innovations each week: chatbots, retrieval-augmented generation (RAG), LLM agents, tool usage, multi-agents, multi-modal LLMs, choosing a framework to start building can be a difficult decision.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Build LLM agents faster with Haystack + Burr!&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-10-31T13:01:10.918Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c1002fb7-034a-4a42-ada4-f628007d29a4_1455x1047.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/build-llm-agents-faster-with-haystack&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:150728469,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:3,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;1b29b4e2-5d90-4060-bcf1-199915ae63e4&quot;,&quot;caption&quot;:&quot;Building Reliable AI&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Annotating Data in Burr&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:151994830,&quot;name&quot;:&quot;Elijah ben Izzy&quot;,&quot;bio&quot;:&quot;CTO of DAGWorks, Inc. Co-creator of Hamilton (github.com/dagworks-inc/hamilton).&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06374da8-19cd-418a-bf2a-e5fa5ae2bf6f_375x335.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:73006291,&quot;name&quot;:&quot;Stefan Krawczyk&quot;,&quot;bio&quot;:&quot;MLOps + Data + LLMOps; creator of https://github.com/dagworks-inc/hamilton.\nFormerly of: Stitch Fix, Idibon, Nextdoor, LinkedIn, HRI, IBM. \nCEO @ DAGWorks - dagworks.io&quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/43b2b624-13e6-44f7-be46-ccedd3246482_3002x3002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-10-22T18:38:19.814Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e653220f-f35f-4dcb-a6d2-35097260a73c_2526x1319.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/annotating-data-in-burr&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:150547109,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:3,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;709cde00-cc9f-453a-8466-9cf5274fec02&quot;,&quot;caption&quot;:&quot;Off-the-shelf LLMs are excellent at manipulating and generating text, but they only know general facts about the world and probably very little about your use case. Retrieval augmented generation (RAG) refers not to a single algorithm, but rather a broad approach to provide rel&#8230;&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Retrieval augmented generation (RAG) with Streamlit, FastAPI, Weaviate, and Hamilton!&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:73006291,&quot;name&quot;:&quot;Stefan Krawczyk&quot;,&quot;bio&quot;:&quot;MLOps + Data + LLMOps; creator of https://github.com/dagworks-inc/hamilton.\nFormerly of: Stitch Fix, Idibon, Nextdoor, LinkedIn, HRI, IBM. \nCEO @ DAGWorks - dagworks.io&quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/43b2b624-13e6-44f7-be46-ccedd3246482_3002x3002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2023-09-08T13:57:01.758Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e75b5f-6621-4f40-a919-2a777cb26832_1600x1225.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/retrieval-augmented-generation-reference-arch&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:136820551,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:6,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Build LLM agents faster with Haystack + Burr!]]></title><description><![CDATA[Learn about Burr's new HaystackAction]]></description><link>https://blog.dagworks.io/p/build-llm-agents-faster-with-haystack</link><guid isPermaLink="false">https://blog.dagworks.io/p/build-llm-agents-faster-with-haystack</guid><dc:creator><![CDATA[Thierry Jean]]></dc:creator><pubDate>Thu, 31 Oct 2024 13:01:10 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/c1002fb7-034a-4a42-ada4-f628007d29a4_1455x1047.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>With new innovations each week: chatbots, retrieval-augmented generation (RAG), LLM agents, tool usage, multi-agents, multi-modal LLMs, choosing a framework to start building can be a difficult decision.</p><p>A few key considerations are:</p><ul><li><p>How efficiently can I test a new idea or build a demo?</p></li><li><p>Can I reliably move my project to production?</p></li><li><p>How easy is it to make changes as project requirements evolve?</p></li></ul><p><a href="https://github.com/deepset-ai/haystack">Haystack</a> and <a href="https://github.com/dagworks-inc/burr">Burr</a> can help you build LLM pipelines and agentic workflows, respectively. In this post, we explore how well they do on these criteria and how you can use them together to build fast and reliably.</p><h1><strong>Haystack 101: build a pipeline</strong></h1><p>Haystack is a framework for building data pipelines, especially RAG. You start by creating <code>Component</code>s then you assemble them into a <code>Pipeline</code> and run it. </p><p>This snippet defines a simple RAG application (adapted from <a href="https://github.com/deepset-ai/haystack-tutorials/blob/main/tutorials/27_First_RAG_Pipeline.ipynb">this Haystack tutorial</a>)</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zqXS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zqXS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png 424w, https://substackcdn.com/image/fetch/$s_!zqXS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png 848w, https://substackcdn.com/image/fetch/$s_!zqXS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png 1272w, https://substackcdn.com/image/fetch/$s_!zqXS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zqXS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png" width="1456" height="1560" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1560,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:389230,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!zqXS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png 424w, https://substackcdn.com/image/fetch/$s_!zqXS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png 848w, https://substackcdn.com/image/fetch/$s_!zqXS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png 1272w, https://substackcdn.com/image/fetch/$s_!zqXS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F26fd55e4-f599-45e3-831d-cc8f34e08a03_1546x1656.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Haystack RAG pipeline definition (<a href="https://gist.github.com/zilto/af5f99c1832f00ec73f55f2f1a58fb53">Gist</a>)</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SxO1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SxO1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png 424w, https://substackcdn.com/image/fetch/$s_!SxO1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png 848w, https://substackcdn.com/image/fetch/$s_!SxO1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png 1272w, https://substackcdn.com/image/fetch/$s_!SxO1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SxO1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png" width="183" height="983.857627118644" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1586,&quot;width&quot;:295,&quot;resizeWidth&quot;:183,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SxO1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png 424w, https://substackcdn.com/image/fetch/$s_!SxO1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png 848w, https://substackcdn.com/image/fetch/$s_!SxO1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png 1272w, https://substackcdn.com/image/fetch/$s_!SxO1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff496c325-4f3d-40e0-be38-102e0627df5d_295x1586.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Haystack pipeline visualization</figcaption></figure></div><p>Haystack provides a catalog of ready-to-use <code>Component</code> (LLM APIs, vector databases, document processors, data readers, etc.) helps get started quickly. It encourages a &#8220;LEGO brick&#8221; approach to building pipelines (the example only 40 lines of code) and makes it easy to swap components and try different configurations. Haystack also enables you to define custom components (<a href="https://docs.haystack.deepset.ai/docs/custom-components">documentation</a>).</p><blockquote><p>We also maintain <a href="https://github.com/DAGWorks-Inc/hamilton">Hamilton</a>, a lightweight framework to define pipelines. It is broader than RAG / LLMs, but we have <a href="https://github.com/DAGWorks-Inc/hamilton/tree/main/examples/LLM_Workflows">several examples on the topic</a>.<br>The product <a href="https://github.com/Canner/WrenAI/tree/main">WrenAI</a> actually uses both <a href="https://github.com/Canner/WrenAI/blob/1860cf82e8bc1d826bd22551c8ef0233ccd0f79f/wren-ai-service/src/pipelines/generation/sql_answer.py">Haystack and Hamilton</a> under the hood!</p></blockquote><h1><strong>Burr 101: build an application</strong></h1><p>Burr is a framework for building applications and agents. It has a similar feel to Haystack, you define <code>Action</code>s (equiv. <code>Component</code>) and transitions between them to form an <code>Application</code> (equiv. <code>Pipeline</code>). We&#8217;ll explore their differences next.</p><p>The previous RAG pipeline could be recreated entirely in Burr. Burr is flexible as to how you define <code>Action</code>s, you could even use an Haystack <code>Component</code> inside one as shown in <code>embed_text()</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!d64P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!d64P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png 424w, https://substackcdn.com/image/fetch/$s_!d64P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png 848w, https://substackcdn.com/image/fetch/$s_!d64P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png 1272w, https://substackcdn.com/image/fetch/$s_!d64P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!d64P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png" width="1456" height="2409" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2409,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:442918,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!d64P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png 424w, https://substackcdn.com/image/fetch/$s_!d64P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png 848w, https://substackcdn.com/image/fetch/$s_!d64P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png 1272w, https://substackcdn.com/image/fetch/$s_!d64P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4254864c-a17a-4e80-8ae5-023c33d0cff7_1460x2416.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Burr RAG application (<a href="https://gist.github.com/zilto/22fdcd4fda9293f8c31c1883d0766261">Gist</a>). Function bodies are trimmed for brevity</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qbiq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qbiq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png 424w, https://substackcdn.com/image/fetch/$s_!qbiq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png 848w, https://substackcdn.com/image/fetch/$s_!qbiq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png 1272w, https://substackcdn.com/image/fetch/$s_!qbiq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qbiq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png" width="511" height="333.7644230769231" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:951,&quot;width&quot;:1456,&quot;resizeWidth&quot;:511,&quot;bytes&quot;:169937,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qbiq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png 424w, https://substackcdn.com/image/fetch/$s_!qbiq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png 848w, https://substackcdn.com/image/fetch/$s_!qbiq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png 1272w, https://substackcdn.com/image/fetch/$s_!qbiq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe57dd385-c812-410e-aaed-31f40c78e6c3_2181x1424.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Burr application visualization</figcaption></figure></div><h1>Differences between Haystack and Burr</h1><h2><strong>Centralized state</strong></h2><p>With Haystack, you build a <code>Pipeline</code> by having data flow from a component directly to another. With Burr, your <code>Application </code>has a centralized <code>State</code>, which facilitates writing logic referencing earlier events.</p><p>Practically, it means you can always save the <code>State</code> of an application and load it later to resume. If you encounter a bug, can move through previous states to find what went wrong. Then, you can edit <code>State</code> values or modify the <code>Action</code>&#8217;s code to fix the issue and resume. Burr also provides utilities to create test cases from failed <code>State</code> to avoid this issue in the future.</p><h2><strong>Decisions and transitions</strong></h2><p>To develop an agent capable of complex behaviors, we need to express conditions under which an action should be taken. </p><p>Haystack creates pipelines with set entry and exit points. By using, <a href="https://docs.haystack.deepset.ai/docs/routers">Routers</a> you can implement conditional logic and dispatch data to different components. The <a href="https://docs.haystack.deepset.ai/docs/conditionalrouter">ConditionalRouter</a> uses Jinja2 for safety, but limits the expressiveness of routing conditions.</p><p>Burr was built specifically for agents, state machines and &#8220;decision-making&#8221; applications. You can add a <code>Condition</code> on any transition in your <code>Application.</code> The transition can read the <code>State</code> and execute a decision function to determine the next action (<a href="https://burr.dagworks.io/concepts/transitions/#conditions">documentation</a>).</p><p>The next snippet illustrate an agent that searches the web to generate an answer. By adding a <code>when()</code> condition on the transition between <code>verify_citation</code> and <code>search_the_web</code>, we can loop if the generated answer has factual errors (as detected by the verify_citation) action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Dgt1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Dgt1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png 424w, https://substackcdn.com/image/fetch/$s_!Dgt1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png 848w, https://substackcdn.com/image/fetch/$s_!Dgt1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png 1272w, https://substackcdn.com/image/fetch/$s_!Dgt1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Dgt1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png" width="1456" height="808" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:808,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:136937,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Dgt1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png 424w, https://substackcdn.com/image/fetch/$s_!Dgt1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png 848w, https://substackcdn.com/image/fetch/$s_!Dgt1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png 1272w, https://substackcdn.com/image/fetch/$s_!Dgt1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2dc2f512-b6e6-45f4-86e9-0d53b38d9a1d_1546x858.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Conditional transition to search the web</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NyPg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NyPg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png 424w, https://substackcdn.com/image/fetch/$s_!NyPg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png 848w, https://substackcdn.com/image/fetch/$s_!NyPg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png 1272w, https://substackcdn.com/image/fetch/$s_!NyPg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NyPg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png" width="301" height="332.47184986595175" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:412,&quot;width&quot;:373,&quot;resizeWidth&quot;:301,&quot;bytes&quot;:28109,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NyPg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png 424w, https://substackcdn.com/image/fetch/$s_!NyPg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png 848w, https://substackcdn.com/image/fetch/$s_!NyPg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png 1272w, https://substackcdn.com/image/fetch/$s_!NyPg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fff9bfb84-223f-4405-b3b7-83f2699c9b7d_373x412.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2><strong>Path to production</strong></h2><p>As a pipeline framework, Haystack can be <a href="https://docs.haystack.deepset.ai/docs/deployment">deployed and orchestrated in various ways</a>. The <a href="https://docs.haystack.deepset.ai/docs/hayhooks">Hayhooks</a> library allows to serve your Haystack pipeline as an API endpoint. For monitoring, Haystack <a href="https://docs.haystack.deepset.ai/docs/tracing">can generate OpenTelemetry events</a> (note: an Openlemetry destination is required) and offers structured logging.</p><p>For Burr, the <code>ApplicationBuilder</code> object allows to instrument your application to meet production needs. Here are some examples:</p><ul><li><p><code>.with_tracker()</code> log execution and optionally <a href="https://burr.dagworks.io/concepts/additional-visibility/#opentelref">enable OpenTelemetry events</a>, which can be viewed in the open source and local-first Burr UI.</p></li><li><p><code>.with_hooks()</code> allows to <a href="https://burr.dagworks.io/concepts/hooks/">add custom logic on action execution</a> (e.g., send a Slack notification)</p></li><li><p><code>.with_typing()</code> use <a href="https://burr.dagworks.io/concepts/state-typing/">Pydantic to validate</a> the <code>State</code> and action outputs.</p></li><li><p><code>.with_state_persister()</code> <a href="https://burr.dagworks.io/concepts/state-persistence/">store the State to disk</a> and resume later (e.g., allow a user to resume its session)</p></li><li><p>and more</p></li></ul><p>The following snippet creates an application that will log execution with OpenTelemetry under the <code>burr-rag &gt; demo</code> in the Burr UI and send alerts on Slack when exceptions occur.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fPkg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fPkg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png 424w, https://substackcdn.com/image/fetch/$s_!fPkg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png 848w, https://substackcdn.com/image/fetch/$s_!fPkg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png 1272w, https://substackcdn.com/image/fetch/$s_!fPkg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fPkg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png" width="1306" height="478" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:478,&quot;width&quot;:1306,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:75457,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fPkg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png 424w, https://substackcdn.com/image/fetch/$s_!fPkg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png 848w, https://substackcdn.com/image/fetch/$s_!fPkg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png 1272w, https://substackcdn.com/image/fetch/$s_!fPkg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5a58282-60b6-43f4-9e75-798ba3a43182_1306x478.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Adding production-ready features to your application</figcaption></figure></div><p>The Burr UI allows you to monitor your application in real time and view past application logs created by the tracker and OpenTelemetry. It helps with debugging and provide other insights such as the number of tokens used and the estimated cost. Burr UI also ships with a <a href="https://blog.dagworks.io/p/annotating-data-in-burr">data annotation tool</a>. This tool is free, open source, and comes with Burr, when you install the appropriate target:</p><pre><code>pip install "burr[tracking]"</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Xufk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Xufk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png 424w, https://substackcdn.com/image/fetch/$s_!Xufk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png 848w, https://substackcdn.com/image/fetch/$s_!Xufk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png 1272w, https://substackcdn.com/image/fetch/$s_!Xufk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Xufk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png" width="1456" height="497" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:497,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:245807,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Xufk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png 424w, https://substackcdn.com/image/fetch/$s_!Xufk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png 848w, https://substackcdn.com/image/fetch/$s_!Xufk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png 1272w, https://substackcdn.com/image/fetch/$s_!Xufk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3848e383-bf5b-42ed-9ed9-468a2ab5f64d_3756x1283.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Screenshot of a logged run in Burr UI</figcaption></figure></div><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/subscribe?"><span>Subscribe now</span></a></p><h1><strong>Haystack + Burr integration</strong></h1><p>With the new integration, you can merge the catalog of modular components from Haystack and the application-building features of Burr.</p><p>While this was possible before, it was verbose. Haystack code needed to be wrapped in a Burr action and the <code>Component </code>inputs/outputs mapped to <code>State</code>. To illustrate, this <code>retrieve_documents()</code> action reads values from State, passes them to <code>Component.run()</code>, and outputs are written back to State:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!L3lK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!L3lK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png 424w, https://substackcdn.com/image/fetch/$s_!L3lK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png 848w, https://substackcdn.com/image/fetch/$s_!L3lK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png 1272w, https://substackcdn.com/image/fetch/$s_!L3lK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!L3lK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png" width="1456" height="915" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:915,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:189257,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!L3lK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png 424w, https://substackcdn.com/image/fetch/$s_!L3lK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png 848w, https://substackcdn.com/image/fetch/$s_!L3lK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png 1272w, https://substackcdn.com/image/fetch/$s_!L3lK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9253ae84-61ab-41d7-b25f-13953646bbf0_1546x972.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Using Haystack + Burr without the integration.</figcaption></figure></div><p>The new <code>HaystackAction</code> allows you to the same Burr action succinctly. Simply pass the action name, the Haystack <code>Component</code>, and <code>State</code> fields it reads and writes from/to. Your Burr application can mix <code>HaystackAction </code>and regular actions.</p><p>Here's the same action as above using the <code>HaystackAction</code>:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!X7gH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!X7gH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png 424w, https://substackcdn.com/image/fetch/$s_!X7gH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png 848w, https://substackcdn.com/image/fetch/$s_!X7gH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png 1272w, https://substackcdn.com/image/fetch/$s_!X7gH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!X7gH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png" width="1456" height="808" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:808,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:142458,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!X7gH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png 424w, https://substackcdn.com/image/fetch/$s_!X7gH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png 848w, https://substackcdn.com/image/fetch/$s_!X7gH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png 1272w, https://substackcdn.com/image/fetch/$s_!X7gH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1d2f52c7-90ae-4e7c-8494-176fcc184395_1546x858.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Using Haystack + Burr via the `HaystackAction`</figcaption></figure></div><p>Now, you&#8217;re able to benefit from Haystack's catalog of components to build Burr applications quickly and reliably. All Burr features become available at almost no additional cost compared to a regular Haystack <code>Pipeline</code> definition. For existing Haystack users, you can fully reuse your custom components for building agents.</p><h2>What if you already have Haystack pipelines?</h2><p>You can convert your Haystack <code>Pipeline</code> into a Burr <code>Application</code> in a few lines of code. The function <code>haystack_pipeline_to_burr_graph()</code> converts the pipeline into a Burr <code>Graph</code> that you can use to build the application.</p><p>The next snippet converts the pipeline defined at the beginning of this blog:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wTU0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wTU0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png 424w, https://substackcdn.com/image/fetch/$s_!wTU0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png 848w, https://substackcdn.com/image/fetch/$s_!wTU0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png 1272w, https://substackcdn.com/image/fetch/$s_!wTU0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wTU0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png" width="1392" height="554" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:554,&quot;width&quot;:1392,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:98333,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wTU0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png 424w, https://substackcdn.com/image/fetch/$s_!wTU0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png 848w, https://substackcdn.com/image/fetch/$s_!wTU0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png 1272w, https://substackcdn.com/image/fetch/$s_!wTU0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a03b6af-d2dc-4c1d-8628-0b8da16a2695_1392x554.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Convert a Haystack `Pipeline` into a Burr `Application` with a single function</figcaption></figure></div><h2>What if I want to integrate other frameworks?</h2><p>You can always use your favorite framework (Haystack, Hamilton, LangChain, LlamaIndex, etc.) within a Burr <code>Action</code>. We&#8217;re looking forward to add similar integrations to streamline Burr development. Let us know which one to implement next!</p><p>As your project evolve, you can swap the Haystack <code>Component</code> used in your <code>HaystackAction</code>, use a custom Haystack <code>Component</code>, or replace the <code>HaystackAction</code> by a regular Burr action with arbitrary Python code. This is a common step as you adjust and upgrade production Burr applications. With Burr you&#8217;re not backed into a corner, you&#8217;re free to leverage any framework you like as requirements evolve. </p><h1><strong>Conclusion</strong></h1><p>On your next project, determine if you&#8217;re building a pipeline or an agent and think about your future requirements for production. Haystack and Burr are two complimentary frameworks that can help and their clean integration can provide a lot of value at a low cost. Should you need to customize and extend beyond your initial application, Burr has the constructs and the flexibility so you can iterate with confidence.</p><h1>We want to hear from you!</h1><p>If you&#8217;re excited by any of this, or have strong opinions:</p><p>&#128227;  Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a><a href="https://hamilton-opensource.slack.com/join/shared_invite/zt-1bjs72asx-wcUTgH7q7QX1igiQ5bbdcg#/shared-invite/email">&#8202;</a></p><p>&#11088;&#65039; us on <a href="https://github.com/dagworks-inc/burr">GitHub</a></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;ef315240-8fc0-4384-9b1d-2278a7d7df94&quot;,&quot;caption&quot;:&quot;Building Reliable AI&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Annotating Data in Burr&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:151994830,&quot;name&quot;:&quot;Elijah ben Izzy&quot;,&quot;bio&quot;:&quot;CTO of DAGWorks, Inc. Co-creator of Hamilton (github.com/dagworks-inc/hamilton).&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06374da8-19cd-418a-bf2a-e5fa5ae2bf6f_375x335.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:73006291,&quot;name&quot;:&quot;Stefan Krawczyk&quot;,&quot;bio&quot;:&quot;MLOps + Data + LLMOps; creator of https://github.com/dagworks-inc/hamilton.\nFormerly of: Stitch Fix, Idibon, Nextdoor, LinkedIn, HRI, IBM. \nCEO @ DAGWorks - dagworks.io&quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/43b2b624-13e6-44f7-be46-ccedd3246482_3002x3002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-10-22T18:38:19.814Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e653220f-f35f-4dcb-a6d2-35097260a73c_2526x1319.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/annotating-data-in-burr&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:150547109,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:3,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;c7cba23d-0407-4c69-964f-865b2864f29f&quot;,&quot;caption&quot;:&quot;Off-the-shelf LLMs are excellent at manipulating and generating text, but they only know general facts about the world and probably very little about your use case. Retrieval augmented generation (RAG) refers not to a single algorithm, but rather a broad approach to provide rel&#8230;&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Retrieval augmented generation (RAG) with Streamlit, FastAPI, Weaviate, and Hamilton!&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:73006291,&quot;name&quot;:&quot;Stefan Krawczyk&quot;,&quot;bio&quot;:&quot;MLOps + Data + LLMOps; creator of https://github.com/dagworks-inc/hamilton.\nFormerly of: Stitch Fix, Idibon, Nextdoor, LinkedIn, HRI, IBM. \nCEO @ DAGWorks - dagworks.io&quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/43b2b624-13e6-44f7-be46-ccedd3246482_3002x3002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2023-09-08T13:57:01.758Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e75b5f-6621-4f40-a919-2a777cb26832_1600x1225.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/retrieval-augmented-generation-reference-arch&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:136820551,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:6,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[Annotating Data in Burr]]></title><description><![CDATA[Iterate on your application, gather evaluation data, and review production runs with your team]]></description><link>https://blog.dagworks.io/p/annotating-data-in-burr</link><guid isPermaLink="false">https://blog.dagworks.io/p/annotating-data-in-burr</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Tue, 22 Oct 2024 18:38:19 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/e653220f-f35f-4dcb-a6d2-35097260a73c_2526x1319.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Building Reliable AI</h1><p>Why is it so hard to get AI systems into production? Among many reasons, you may be haunted by the fear of catastrophic hallucinations and strange behavior. While AI is dressed up to seem human-like, it is prone to errors similar to any other computer program. Specifically, if you&#8217;re not <em>exact</em> about what you want, it can produce troubling behavior. Cases of this have resulted in high-profile stories about companies that have proudly released their AI-driven features to production, only to be on the receiving end of lawsuits and unhappy customers. See, for example, the recent <a href="https://www.forbes.com/sites/marisagarcia/2024/02/19/what-air-canada-lost-in-remarkable-lying-ai-chatbot-case/">Air Canada lawsuit</a>.</p><p>The downside is that it may never be possible to solve these problems perfectly &#8211; AI, at its current state, is neither precise enough nor appropriately incentivized to reliably *not* mess things up. The upside, however, is that you can be both <em>proactive</em> and <em>reactive</em> to these issues enough to feel confident in releasing your product. While there are multiple approaches to be <em>proactive</em> with Burr, we&#8217;re going to be talking about effectively <em>reacting </em>in this post.</p><p>The following strategies are table-stakes for anyone who wants to leverage AI <em>seriously</em>, E.G. in any part of their business that produces some value:</p><ol><li><p>Full monitoring &#8211; know everything that happens, when it happens, and to whom</p></li><li><p>Further investigation &#8211; be able to dig into the data and react/save for later if anything goes wrong</p></li><li><p>Intervention &#8211; make alterations to the data/reach out to the impacted users</p></li><li><p>Retuning &#8211; take the mistakes an app made and ensure it doesn&#8217;t happen again</p></li></ol><p>We&#8217;re going to be focusing on (2), (3), and (4). <strong>Specifically, how to mark data for further review, react to it, and use that data to retune the behavior of your application.</strong> For (1), see our <a href="https://blog.dagworks.io/p/burr-develop-stateful-ai-applications">original post on Burr</a> and <a href="https://blog.dagworks.io/p/burr-ui">the Burr UI</a>. No need to read these, however, as we&#8217;ll first conduct a quick overview of Burr.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for the latest updates.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h1>Burr</h1><p><a href="https://github.com/DAGWorks-Inc/burr/">Burr</a> is a lightweight Python library you use to build applications as state machines. You construct your application out of a series of <em>actions</em> (these can be either decorated functions or objects), which declare inputs from <em>state</em>, as well as <em>inputs</em> from the user. These specify custom logic (delegating to any framework), as well as instructions on how to update state. State is immutable, which allows you to inspect it at any given point. Burr handles orchestration, monitoring, persistence, etc&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aVVt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" width="723" height="65" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:65,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30725,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Hello world counter action. Gist <a href="https://gist.github.com/elijahbenizzy/c295c2578685867996577733b8005f59">here</a></figcaption></figure></div><p>You run your Burr actions as part of an application &#8211; this allows you to string them together with a series of (optionally) conditional transitions from action to action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ejRj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" width="1444" height="568" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:568,&quot;width&quot;:1444,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:119779,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Using the application builder. Gist <a href="http://238196b05d123353999b9263c3c1a76f/">here</a></figcaption></figure></div><p>Burr comes with a user-interface that enables monitoring/telemetry, as well as hooks to persist state/execute arbitrary code during execution.</p><p>You can visualize this as a flow chart, i.e. graph / state machine:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lYVz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" width="216" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;State Machine&quot;,&quot;title&quot;:&quot;State Machine&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="State Machine" title="State Machine" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>And monitor it using the local telemetry debugger:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yfZx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png" width="1456" height="750" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:750,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:194056,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yfZx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 424w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 848w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1272w, https://substackcdn.com/image/fetch/$s_!yfZx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F654ca62d-3e3d-4423-bd27-931768582847_2544x1310.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>While the above example is a simple illustration, Burr is commonly used for AI assistants (like in this example), RAG applications, and human-in-the-loop AI interfaces. See the repository <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples">examples</a> for a (more exhaustive) set of use-cases.</p><h1>Annotations in Burr</h1><p>For the sake of this post, we&#8217;ll be using the &#8220;tool-calling&#8221; example <a href="https://blog.dagworks.io/p/agentic-design-pattern-1-tool-calling?utm_source=publication-search">from a prior blog post</a>. No need to read it &#8211; the high-level is that we used the tool/function APIs to build an agent that chose between response modes and used prebuilt functions to answer as intended. We will be marking data we think is funky, reviewing it, then turning it back into a tuning set. One of the tools we will use will be <code>query_weather</code>, which takes in a latitude/longitude and gives out a free-form description of the weather &#8211; we&#8217;ll be using this as an example.</p><h1>Reviewing</h1><p>The new annotations feature in the UI allows you to mark steps in an application for any reason &#8211; E.G. say they&#8217;re a hallucination, flag them for review, marking the response as a good decision, etc&#8230; To do this, you click on the + symbol in the annotations column in a trace view, which opens up a dialog:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uqs7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uqs7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png 424w, https://substackcdn.com/image/fetch/$s_!uqs7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png 848w, https://substackcdn.com/image/fetch/$s_!uqs7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png 1272w, https://substackcdn.com/image/fetch/$s_!uqs7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uqs7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png" width="728" height="135" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/954405fa-dbba-4133-981e-095a64a7179e_1600x297.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:270,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uqs7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png 424w, https://substackcdn.com/image/fetch/$s_!uqs7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png 848w, https://substackcdn.com/image/fetch/$s_!uqs7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png 1272w, https://substackcdn.com/image/fetch/$s_!uqs7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F954405fa-dbba-4133-981e-095a64a7179e_1600x297.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">The annotation dialog &#8212; click on the + symbol to add one (or edit with the annotations symbol)</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!O0cI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!O0cI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png 424w, https://substackcdn.com/image/fetch/$s_!O0cI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png 848w, https://substackcdn.com/image/fetch/$s_!O0cI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png 1272w, https://substackcdn.com/image/fetch/$s_!O0cI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!O0cI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png" width="728" height="287.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:575,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!O0cI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png 424w, https://substackcdn.com/image/fetch/$s_!O0cI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png 848w, https://substackcdn.com/image/fetch/$s_!O0cI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png 1272w, https://substackcdn.com/image/fetch/$s_!O0cI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc736ae26-da0f-4fd6-9c55-11a141fb023a_1600x632.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Annotating with your opinions on SF weather&#8230;</figcaption></figure></div><p>Annotations are identifiable by tags &#8211; these are free-form strings (with a set of common default values), that can help identify/query the data. An annotation consists of one or more <em>observations</em>, each on a specific data point (attribute, state field, etc&#8230;). These observations have a thumbs up/thumbs down capability, as well as free-form text and an (optional) ground truth. This allows for multiple observations (each associated with a datapoint).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!V13B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!V13B!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png 424w, https://substackcdn.com/image/fetch/$s_!V13B!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png 848w, https://substackcdn.com/image/fetch/$s_!V13B!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png 1272w, https://substackcdn.com/image/fetch/$s_!V13B!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!V13B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png" width="728" height="203.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:407,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!V13B!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png 424w, https://substackcdn.com/image/fetch/$s_!V13B!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png 848w, https://substackcdn.com/image/fetch/$s_!V13B!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png 1272w, https://substackcdn.com/image/fetch/$s_!V13B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4be15e23-7d4d-4b5e-9abf-067aa55cd9bb_1600x447.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Sometimes the user is just trying to mess with you&#8230;</figcaption></figure></div><p>You can then browse the annotations you created for your application with the &#8220;annotations&#8221; tab on the right hand side</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ir6n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ir6n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png 424w, https://substackcdn.com/image/fetch/$s_!Ir6n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png 848w, https://substackcdn.com/image/fetch/$s_!Ir6n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!Ir6n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ir6n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png" width="1456" height="760" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:760,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:407078,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ir6n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png 424w, https://substackcdn.com/image/fetch/$s_!Ir6n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png 848w, https://substackcdn.com/image/fetch/$s_!Ir6n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png 1272w, https://substackcdn.com/image/fetch/$s_!Ir6n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b13b558-c619-49ad-980f-2c6d124cba40_2526x1319.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Reacting</h1><p>In the case of troubling behavior, you want to be able to react quickly. Burr&#8217;s annotation feature lets you query data by tags/action name, enabling you to use the tags as a <em>queuing system </em>for handling annotations. Say, for the sake of argument, that someone named <em>Elijah</em> is your trusty QA associate:</p><p>Back to the prior example, say we decide on a tag schema with the following tags:</p><ol><li><p><code>hallucination</code></p></li><li><p><code>incorrect</code></p></li><li><p><code>correct</code></p></li><li><p><code>to-review:&lt;name&gt; </code>(E.G. <code>to-review:elijah</code>)<code> or reviewed-by:&lt;name&gt; </code>(E.G. <code>reviewed-by:elijah</code>)</p></li><li><p><code>urgent</code></p></li></ol><p>In order to quickly react (and thus provide quality customer service), we can filter all the created annotations by tag at a project level. You can further review, modify tags, and edit annotations.</p><p>So, the workflow we anticipate is:</p><ol><li><p>The developer/on-call person gets a complaint (or does a routine audit)</p></li><li><p>They immediately mark as<code> to-review:elijah&nbsp;</code></p></li><li><p>Elijah then goes through annotations marked as to-review, and reviews accordingly (marking them as <code>reviewed-by:elijah</code></p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sMHX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sMHX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png 424w, https://substackcdn.com/image/fetch/$s_!sMHX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png 848w, https://substackcdn.com/image/fetch/$s_!sMHX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png 1272w, https://substackcdn.com/image/fetch/$s_!sMHX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sMHX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png" width="1456" height="579" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:579,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sMHX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png 424w, https://substackcdn.com/image/fetch/$s_!sMHX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png 848w, https://substackcdn.com/image/fetch/$s_!sMHX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png 1272w, https://substackcdn.com/image/fetch/$s_!sMHX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F732a98d4-e91a-41fe-9896-cf5e862b9072_1600x636.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Looking over the set of assigned tasks (tag=to-review:elijah)</figcaption></figure></div><h1>Retuning</h1><p>While we&#8217;ve talked about how to react to errors in your AI applications, annotating Burr application runs also gives you the capability to proactively change the behavior for later.</p><p>You can do this through two sets of provided tools:</p><h4><strong>Adding unit tests</strong></h4><p>To do so, you can click on the annotation in the project view, and you&#8217;ll get a full application view. You can then click on the &#8220;reproduce&#8221; tab, which will give you a command to create a test case.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Lyen!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Lyen!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png 424w, https://substackcdn.com/image/fetch/$s_!Lyen!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png 848w, https://substackcdn.com/image/fetch/$s_!Lyen!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png 1272w, https://substackcdn.com/image/fetch/$s_!Lyen!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Lyen!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png" width="1456" height="561" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:561,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Lyen!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png 424w, https://substackcdn.com/image/fetch/$s_!Lyen!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png 848w, https://substackcdn.com/image/fetch/$s_!Lyen!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png 1272w, https://substackcdn.com/image/fetch/$s_!Lyen!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9c9b3519-1e11-4cdc-a4fe-a95b674c06b7_1600x616.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Generating unit tests from annotated steps</figcaption></figure></div><p>See further documentation <a href="https://burr.dagworks.io/examples/guardrails/creating_tests/">here</a> on how to tune this.</p><h4><strong>Downloading data for fine-tuning</strong></h4><p>Click on the &#8220;Download&#8221; button next to the search bar to download the CSV of all relevant data! You can massage that to fine-tune your next model, train a new model from scratch, or have a dataset to send for debugging.</p><h1>Wrapping up</h1><p>In this post we showed how to leverage the Burr UI to quickly <em>react</em> to problematic behavior in your AI applications. We showed:</p><ol><li><p>How to annotate/tag data</p></li><li><p>How to review that data</p></li><li><p>How to use that annotation data for evaluation/fine-tuning down the line</p></li></ol><p>Leveraging these approaches can give you confidence on your application &#8212; both that you can quickly react to any negative user experiences and use that data to ensure they don&#8217;t happen in the future.</p><h2>Next Steps</h2><p>While the annotations feature is currently very powerful, we plan to implement the following:</p><ol><li><p>Centralized schemas for tags, so that teams can more effectively collaborate</p></li><li><p>More advanced search capabilities for annotations</p></li><li><p>User-aware/team-specific queuing (related to (1))</p></li></ol><p>And we&#8217;re building quick! Please reach out if you need any of these features or want to provide feedback, we&#8217;re building with use-cases in mind.</p><h2>Further Reading</h2><p>In the meanwhile:</p><ul><li><p>Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a> for help or if you have questions!</p></li><li><p><a href="https://www.youtube.com/@dagworks-inc">Subscribe to our youtube</a> to watch some in-depth tutorials/overviews</p></li><li><p>Star our <a href="https://github.com/dagworks-inc/burr">Github repository</a> if you like what you see</p></li><li><p>Check out the recent <a href="https://burr.dagworks.io/reference/integrations/opentelemetry/">OpenTelemetry integration</a> for additional observability</p></li><li><p>See the code for this post among <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/tool-calling">our examples</a></p></li></ul><h1></h1>]]></content:encoded></item><item><title><![CDATA[Feature release: Caching]]></title><description><![CDATA[How to develop faster and more reliably with Hamilton caching]]></description><link>https://blog.dagworks.io/p/feature-release-caching</link><guid isPermaLink="false">https://blog.dagworks.io/p/feature-release-caching</guid><dc:creator><![CDATA[Thierry Jean]]></dc:creator><pubDate>Fri, 11 Oct 2024 00:28:37 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!XgZd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XgZd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XgZd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp 424w, https://substackcdn.com/image/fetch/$s_!XgZd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp 848w, https://substackcdn.com/image/fetch/$s_!XgZd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp 1272w, https://substackcdn.com/image/fetch/$s_!XgZd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XgZd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp" width="618" height="412" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b90156e0-0495-4b50-a383-88ceef53e778_540x360.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:360,&quot;width&quot;:540,&quot;resizeWidth&quot;:618,&quot;bytes&quot;:22012,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XgZd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp 424w, https://substackcdn.com/image/fetch/$s_!XgZd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp 848w, https://substackcdn.com/image/fetch/$s_!XgZd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp 1272w, https://substackcdn.com/image/fetch/$s_!XgZd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb90156e0-0495-4b50-a383-88ceef53e778_540x360.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Caching is actually more akin to the tortoise than the hare. Its consistency and reliability makes you win the race in the long run!</figcaption></figure></div><p>With release <code>1.79.0 </code>Hamilton now offers caching of execution results! With caching enabled, executing a node will store results on disk along with some metadata. On subsequent executions, it will automatically skip execution of any previously executed steps by loading results. To enable it, simply add <code>.with_cache()</code> to your <code>Builder</code></p><pre><code>from hamilton import driver
import my_pipeline

dr = (
&nbsp; &nbsp; driver.Builder()
&nbsp; &nbsp; .with_modules(my_pipeline)
&nbsp; &nbsp; .with_cache()
&nbsp; &nbsp; .build()
)</code></pre><p>Here are some scenarios where caching is a clear win:</p><ol><li><p>Faster development iterations (in scripts or notebooks)</p></li><li><p>Avoid cost of repeated LLM calls and embeddings during agent development</p></li><li><p>Incrementally load data by skipping previously processed files</p></li><li><p>Recover from errors during debugging a data pipeline, starting where you left off</p></li></ol><p>This blog will detail why we built caching and how it works. Then, we&#8217;ll illustrate some of these use cases that caching can help you with! First, let&#8217;s go over the basics of Hamilton (skip the next section if you&#8217;re already familiar).</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/subscribe?"><span>Subscribe now</span></a></p><h1>Hamilton 101</h1><p>Hamilton is a standardized way of building data pipelines in Python. The core concepts are simple &#8211; you write each data transformation step as a single Python function with the following rules:</p><ol><li><p>The name of the function corresponds to the output variable it computes.</p></li><li><p>The parameter names (and types) correspond to inputs. These can be either passed-in parameters or names of other upstream functions.</p></li></ol><p>This approach allows you to represent assets in ways that correspond closely to code, naturally self-documenting, and portable across infrastructure.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tcXe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tcXe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 424w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 848w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 1272w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tcXe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png" width="583" height="363.2141592920354" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:704,&quot;width&quot;:1130,&quot;resizeWidth&quot;:583,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tcXe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 424w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 848w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 1272w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The definition of a Hamilton dataflow and its visualization</figcaption></figure></div><p>Then, you create a <code>Driver</code> from this dataflow definition and you can use it to execute code. In the next snippet, we request the node <code>C</code> for <code>external_input=12.</code></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TZit!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TZit!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png 424w, https://substackcdn.com/image/fetch/$s_!TZit!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png 848w, https://substackcdn.com/image/fetch/$s_!TZit!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png 1272w, https://substackcdn.com/image/fetch/$s_!TZit!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TZit!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png" width="1168" height="326" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:326,&quot;width&quot;:1168,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:50672,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TZit!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png 424w, https://substackcdn.com/image/fetch/$s_!TZit!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png 848w, https://substackcdn.com/image/fetch/$s_!TZit!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png 1272w, https://substackcdn.com/image/fetch/$s_!TZit!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58e6c166-1ada-4581-8d78-b8e6ffbee230_1168x326.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>The pain of expensive operations</h1><p>If you're working in data (e.g., data science, machine learning, ETL, BI, LLM applications) you know the feeling of launching a script or a notebook cell, and having a minute+ to get results.</p><p>Unless there's a bug midway that makes the job fail... Hopefully, it happened before that expensive operation (SQL join, model training, downloading large data, sending a batch of paid LLM requests) &#128184;&#128184; Or maybe the job did complete, but there are obvious mistakes in the produced data... Unsure, you prefer running the job twice to check if results match &#129310;</p><blockquote><p>load dataset &gt;&gt; chunk &gt;&gt; embed &gt;&gt; evaluate RAG</p></blockquote><p>To alleviate this pain, you can start to create custom <strong>checkpoints</strong> by saving intermediary results and adding some logic to load checkpoints if available.</p><blockquote><p>load dataset &gt;&gt; chunk &gt;&gt; embed  &gt; <strong>checkpoint </strong>&gt; evaluate RAG</p></blockquote><p>However, as your project grows in complexity, so does your checkpointing code. It&#8217;s more to manage. Also, checkpointing logic can be difficult to generalize between dev/prod and across projects in general.</p><div class="pullquote"><p>Did this properly overwrite the previous checkpoint?</p><p>Which checkpoint was loaded exactly?</p></div><h1>What is caching?</h1><p>Caching broadly means "reusing stored results instead of repeating operations&#8221;, in other words, it is automated checkpointing. To make this possible, Hamilton versions the <strong>code that defines the node</strong> and the <strong>values passed to it</strong>.</p><p>For example, let&#8217;s take this 3 node dataflow and focus on <code>processed_data()</code></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!b_pb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!b_pb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png 424w, https://substackcdn.com/image/fetch/$s_!b_pb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png 848w, https://substackcdn.com/image/fetch/$s_!b_pb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png 1272w, https://substackcdn.com/image/fetch/$s_!b_pb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!b_pb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png" width="1456" height="672" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:672,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:163580,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!b_pb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png 424w, https://substackcdn.com/image/fetch/$s_!b_pb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png 848w, https://substackcdn.com/image/fetch/$s_!b_pb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png 1272w, https://substackcdn.com/image/fetch/$s_!b_pb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66a0d4a8-bb0e-49eb-b182-2d7ec3960b5f_1530x706.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JmIG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JmIG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png 424w, https://substackcdn.com/image/fetch/$s_!JmIG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png 848w, https://substackcdn.com/image/fetch/$s_!JmIG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png 1272w, https://substackcdn.com/image/fetch/$s_!JmIG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JmIG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png" width="537" height="291.03413940256047" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:381,&quot;width&quot;:703,&quot;resizeWidth&quot;:537,&quot;bytes&quot;:24326,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JmIG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png 424w, https://substackcdn.com/image/fetch/$s_!JmIG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png 848w, https://substackcdn.com/image/fetch/$s_!JmIG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png 1272w, https://substackcdn.com/image/fetch/$s_!JmIG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16912226-8e8f-4cf4-8e44-e21e11cdadfa_703x381.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Visualization of the dataflow defined just before.</figcaption></figure></div><p>After executing it once, its result will be stored. On the second execution, the node will be skipped (cache hit) if it receives the same values for <code>raw_data</code> or <code>cutoff_date</code>.</p><p>It would be a cache miss if:</p><ul><li><p>the value for <code>raw_data</code> is different</p></li><li><p>the value for <code>cutoff_date</code> is different</p></li><li><p>the function <code>processed_data()</code> was edited (e.g., change the currency conversion from <strong>0.73</strong> to <strong>0.75</strong>)</p></li></ul><h1>Caching in Hamilton</h1><p>To get started with caching in Hamilton, just add <code>.with_cache()</code> to your <code>Driver</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w9El!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w9El!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png 424w, https://substackcdn.com/image/fetch/$s_!w9El!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png 848w, https://substackcdn.com/image/fetch/$s_!w9El!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png 1272w, https://substackcdn.com/image/fetch/$s_!w9El!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w9El!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png" width="1306" height="288" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:288,&quot;width&quot;:1306,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:42121,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!w9El!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png 424w, https://substackcdn.com/image/fetch/$s_!w9El!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png 848w, https://substackcdn.com/image/fetch/$s_!w9El!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png 1272w, https://substackcdn.com/image/fetch/$s_!w9El!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3a2ea4-ad9e-431b-842e-ff2d97518b55_1306x288.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>To get more information about execution, you can retrieve the logger and set the level to <code>INFO</code> or <code>DEBUG</code></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ic5I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ic5I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png 424w, https://substackcdn.com/image/fetch/$s_!Ic5I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png 848w, https://substackcdn.com/image/fetch/$s_!Ic5I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png 1272w, https://substackcdn.com/image/fetch/$s_!Ic5I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ic5I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png" width="1306" height="440" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:440,&quot;width&quot;:1306,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:76791,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ic5I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png 424w, https://substackcdn.com/image/fetch/$s_!Ic5I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png 848w, https://substackcdn.com/image/fetch/$s_!Ic5I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png 1272w, https://substackcdn.com/image/fetch/$s_!Ic5I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7cb8e3f9-478d-4b69-afc1-448c5bd02aa5_1306x440.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>There's also a new visualization included via the <code>Driver.cache</code> attribute</p><pre><code>dr.cache.view_run()</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2f-D!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2f-D!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png 424w, https://substackcdn.com/image/fetch/$s_!2f-D!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png 848w, https://substackcdn.com/image/fetch/$s_!2f-D!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png 1272w, https://substackcdn.com/image/fetch/$s_!2f-D!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2f-D!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png" width="405" height="304.1820768136558" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:528,&quot;width&quot;:703,&quot;resizeWidth&quot;:405,&quot;bytes&quot;:29811,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2f-D!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png 424w, https://substackcdn.com/image/fetch/$s_!2f-D!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png 848w, https://substackcdn.com/image/fetch/$s_!2f-D!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png 1272w, https://substackcdn.com/image/fetch/$s_!2f-D!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2de1e9cd-07be-4f67-9a8c-c35ac7ef2f47_703x528.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Output of <strong>dr.cache.view_run()</strong> highlighting values retrieved from cache</figcaption></figure></div><p>Hamilton&#8217;s caching comes with effective defaults, its behavior can also be tuned node-by-node:</p><ul><li><p>the &#8220;caching behavior&#8221;: default, always recompute, default, ignore (and more)</p></li><li><p>how to version data for specific Python types</p></li><li><p>how to create cache key</p></li><li><p>where to store metadata and results (could be different places, by project, globally)</p></li></ul><p>Providing this amount of control to the user allows for optimal execution. </p><blockquote><p>To learn more about caching in Hamilton, feel free to complete the tutorial (<a href="https://github.com/DAGWorks-Inc/hamilton/blob/main/examples/caching/tutorial.ipynb">GitHub</a>, <a href="https://colab.research.google.com/github/DAGWorks-Inc/hamilton/blob/main/examples/caching/tutorial.ipynb">Colab</a>) or review the <a href="https://hamilton.dagworks.io/en/latest/concepts/caching/">documentation</a>.</p></blockquote><h1>Caching in notebooks</h1><p>Caching pairs nicely with the Hamilton notebook extension, which allows you to define your dataflow in a notebook cell (<a href="https://github.com/DAGWorks-Inc/hamilton/blob/main/examples/jupyter_notebook_magic/example.ipynb">see tutorial</a>).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xQzf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xQzf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png 424w, https://substackcdn.com/image/fetch/$s_!xQzf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png 848w, https://substackcdn.com/image/fetch/$s_!xQzf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png 1272w, https://substackcdn.com/image/fetch/$s_!xQzf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xQzf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png" width="1236" height="283" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b9790d57-0002-4557-a887-c02d546e758e_1236x283.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:283,&quot;width&quot;:1236,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27568,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xQzf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png 424w, https://substackcdn.com/image/fetch/$s_!xQzf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png 848w, https://substackcdn.com/image/fetch/$s_!xQzf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png 1272w, https://substackcdn.com/image/fetch/$s_!xQzf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9790d57-0002-4557-a887-c02d546e758e_1236x283.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Say you're developing the above retrieval-augmented generation (RAG) application. It involves multiple steps (loading, parsing, chunking, etc.) with many potential approach for each step. If you try a new <code>embedding</code> step, you'll be able to automatically skip the upstream loading, parsing, and chunking!</p><p>Another benefit of caching is that you can safely restart the notebook kernel and shutdown your computer after a long day of work. When you'll come back, you can resume from where you left!</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/subscribe?"><span>Subscribe now</span></a></p><h1>Caching with dynamic dataflows</h1><p>Hamilton provides the constructs <code>Parallelizable </code>and <code>Collect </code>to create multiple branches of the same processing steps (<a href="https://hamilton.dagworks.io/en/latest/concepts/parallel-task/">learn more</a>). For example, you can retrieve HTML pages for multiple URLs and extract articles from it.</p><p>The image below shows a dataflow where <code>url </code>&#8220;expands&#8221; in many branches that will be collected at <code>collect_chunked_url_text. </code>Each branch will execute: <code>article_text</code>, <code>chunked_text</code>, and <code>url_result</code></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kxGA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kxGA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png 424w, https://substackcdn.com/image/fetch/$s_!kxGA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png 848w, https://substackcdn.com/image/fetch/$s_!kxGA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png 1272w, https://substackcdn.com/image/fetch/$s_!kxGA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kxGA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png" width="1456" height="509" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:509,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:83806,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kxGA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png 424w, https://substackcdn.com/image/fetch/$s_!kxGA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png 848w, https://substackcdn.com/image/fetch/$s_!kxGA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png 1272w, https://substackcdn.com/image/fetch/$s_!kxGA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faedfc2e6-a80d-4707-aabf-37d0418fc217_1972x689.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>When using <code>Parallelizable/Collect</code> with caching, branches are cached individually. Consequently if there's an error with the 7th URL, the first 6 sucessful branches will skipped on retry. Similarly, if you successfully executed 10 URLs and add 2 more, only the new ones will be executed. This can be a useful pattern for incremental loading.</p><h1>Caching for debugging</h1><p>Caching can also be a helpful tool for debugging your Hamilton dataflow. Let&#8217;s say you&#8217;re running your dataflow via a script and it fails midway through. If you have caching enabled, you can open an interactive session or a notebook, create a new <code>Driver</code> and start debugging.</p><pre><code>from hamilton import driver
import my_module

dr = (
&nbsp; &nbsp; driver.Builder()
&nbsp; &nbsp; .with_modules(my_module)
&nbsp; &nbsp; .with_cache(path=...) &nbsp;# point to the cache used by the script
&nbsp; &nbsp; .build()
)</code></pre><p>You can call <code>dr.execute()</code> to see if the error is reproduced. From there, you can modify the dataflow in <code>my_module</code> and try re-executing, and steps unchanged will be automatically skipped! Hamilton also provides structured logs and entry points to manually inspect metadata and results produced by the cache (<a href="https://github.com/DAGWorks-Inc/hamilton/blob/main/examples/caching/tutorial.ipynb">learn more</a>).</p><blockquote><p>We&#8217;ll soon be supporting caching on AWS, GCP, Azure, and more. This will allow the same debugging pattern of dataflows deployed via Airflow et al. Reach out to us if you&#8217;re interested in this feature - find us in <a href="https://join.slack.com/t/hamilton-opensource/shared_invite/zt-1bjs72asx-wcUTgH7q7QX1igiQ5bbdcg">Hamilton&#8217;s slack</a>.</p></blockquote><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/p/feature-release-caching?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Know someone who&#8217;d be interested in this? Share it with them.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/p/feature-release-caching?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/p/feature-release-caching?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><h1>We want to hear from you!</h1><p>Caching is a new core feature of Hamilton that we want to improve and expand. It already benefits many use cases, but we want to know your experience and ideas!</p><p>If you&#8217;re excited or have strong opinions, <a href="https://join.slack.com/t/hamilton-opensource/shared_invite/zt-1bjs72asx-wcUTgH7q7QX1igiQ5bbdcg">join our Hamilton community on Slack</a>&#8202;. It&#8217;s also a great place to get help with Hamilton!</p><p>&#128221; leave us an <a href="https://github.com/DAGWorks-Inc/hamilton/issues">issue</a> if you find something</p><p>&#11088; give us a star on the <a href="https://github.com/dagworks-inc/hamilton">Hamilton repository</a> if you like what we&#8217;re working on!</p><p>We recently launched <a href="https://github.com/dagworks-inc/burr">Burr to create LLM agents and applications</a>.<br></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;e121f2a2-b3b4-49b4-98b8-2d7201d54a9a&quot;,&quot;caption&quot;:&quot;In this post we discuss the new MLFlow integration we built for Hamilton. We begin with a quick overview of the two libraries. Then, we present the new features and share how you can use it to manage your experiments. This is meant to complement&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Tracking Pipelines with MLFLow &amp; Hamilton&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:151994830,&quot;name&quot;:&quot;Elijah ben Izzy&quot;,&quot;bio&quot;:&quot;CTO of DAGWorks, Inc. Co-creator of Hamilton (github.com/dagworks-inc/hamilton).&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06374da8-19cd-418a-bf2a-e5fa5ae2bf6f_375x335.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-06-27T14:39:12.819Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fa6220e3-3aea-4845-9af3-77f303342034_1123x881.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/tracking-pipelines-with-mlflow-and&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:146020514,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:3,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;ebc934a6-e78c-47e2-b080-a18e283b5719&quot;,&quot;caption&quot;:&quot;For the past three years, Best Egg has been on a journey to find the ideal machine learning feature engineering platform. As a fintech company offering lending products ranging from personal loans to flexible rent solutions, machine learning and data are at the heart of our business. Providing our customers with the resources they need to be money confi&#8230;&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Building a Better Feature Platform with Hamilton&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:145120843,&quot;name&quot;:&quot;Ryan Whitten&quot;,&quot;bio&quot;:&quot;Director, ML Data Engineering at Best Egg&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F127aebc7-534b-49d1-afbe-f9fc997c285d_800x800.jpeg&quot;,&quot;is_guest&quot;:true,&quot;bestseller_tier&quot;:null,&quot;primaryPublicationSubscribeUrl&quot;:&quot;https://ryanwhitten.substack.com/subscribe?&quot;,&quot;primaryPublicationUrl&quot;:&quot;https://ryanwhitten.substack.com&quot;,&quot;primaryPublicationName&quot;:&quot;Ryan&#8217;s Substack&quot;,&quot;primaryPublicationId&quot;:3111906},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-10-02T16:56:43.080Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/building-a-better-feature-platform&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:149718114,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:5,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;0dc28258-8aad-4ec6-8e5a-4c08aa34b0a1&quot;,&quot;caption&quot;:&quot;If you&#8217;ve ever built any pipelines / workflows that deal with data and had to manage them, you&#8217;ve surely encountered &#8220;data quality&#8221; issues.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Data Quality with Hamilton and Pandera&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:73006291,&quot;name&quot;:&quot;Stefan Krawczyk&quot;,&quot;bio&quot;:&quot;MLOps + Data + LLMOps; creator of https://github.com/dagworks-inc/hamilton.\nFormerly of: Stitch Fix, Idibon, Nextdoor, LinkedIn, HRI, IBM. \nCEO @ DAGWorks - dagworks.io&quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/43b2b624-13e6-44f7-be46-ccedd3246482_3002x3002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-08-01T22:47:56.033Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/data-quality-with-hamilton-and-pandera&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:147018397,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:5,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[Building a Better Feature Platform with Hamilton]]></title><description><![CDATA[A guest post by Ryan Whitten, Director of ML Data Engineering @ Best Egg]]></description><link>https://blog.dagworks.io/p/building-a-better-feature-platform</link><guid isPermaLink="false">https://blog.dagworks.io/p/building-a-better-feature-platform</guid><dc:creator><![CDATA[Ryan Whitten]]></dc:creator><pubDate>Wed, 02 Oct 2024 16:56:43 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!-Lk7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>For the past three years, <a href="https://www.bestegg.com/">Best Egg</a> has been on a journey to find the ideal machine learning feature engineering platform. As a fintech company offering lending products ranging from <a href="https://www.bestegg.com/personal-loans/">personal loans</a> to <a href="https://www.bestegg.com/flexible-rent-for-renters/">flexible rent</a> solutions, machine learning and data are at the heart of our business. Providing our customers with the resources they need to be money confident requires us to constantly refine our processes. Upon closer examination, we found that our data scientists spend a large part of any new model&#8217;s development time manually curating and analyzing training data. We also recognized the challenge when the training data doesn&#8217;t match what the model sees at inference time (the dreaded <em><a href="https://developers.google.com/machine-learning/guides/rules-of-ml#training-serving_skew">train-serve skew</a></em>).&nbsp;</p><p>A typical development workflow for each model includes pulling features from our Snowflake data warehouse, engineering some features manually, and implementing a standard set of pandas dataframe transformations. This leads to a lot of time spent modifying Snowflake queries and repeated code that results in a very isolated feature engineering pipeline that&#8217;s not easily accessible to other data scientists. The reusability of our features is low, and the relative universe of features considered for feature selection is small due to the overhead in trying to explore new features.&nbsp;</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts on data, AI, &amp; ML</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>We knew we could increase efficiency for our data scientists, minimize train-serve skew, and unlock new use cases that hadn&#8217;t been explored yet. Our goal was clear: we needed a centralized platform to support and promote the reuse of ML features across multiple models. This is not a problem unique to our business, and feature stores and commercial feature platforms clearly tout themselves as the solution to these problems.&nbsp;</p><p>We evaluated and completed proof-of-concepts with the top five commercial and open-source providers in the market.&nbsp; While each platform had its strengths, none were able to fully meet our needs. Ultimately, we chose to build our own in-house solution, leveraging existing infrastructure and integrating open-source tools including <a href="https://github.com/dagworks-inc/hamilton">Hamilton</a>.&nbsp;</p><h2><strong>Our Feature Platform Requirements</strong></h2><p>As we set out to find the right feature platform, we developed a list of requirements to help us focus on what we really needed and to evaluate each platform consistently. At a high level, the list included capabilities like:&nbsp;</p><ul><li><p>Connects to our existing data sources (Snowflake, S3, Postgres, etc.), provides flexibility for any other source we may have, and allows joining across data sources</p></li><li><p>Enables calculating on-demand features for real time inference</p></li><li><p>Supports pre-computing features to both an online and offline feature store, in batch and streaming contexts&nbsp;</p></li><li><p>Generates accurate training data using point-in-time joins&nbsp;</p></li><li><p>Supports windowed aggregations&nbsp;</p></li><li><p>Handles complex chained transformations&nbsp;</p></li><li><p>Is Python-native and makes it easy to express features as code</p></li></ul><h2><strong>Why No Platform Checked All the Boxes</strong></h2><p>Our requirements are fairly standard and what you&#8217;d expect any feature platform to provide. However, the main lesson we learned was that while a platform may check the boxes on paper, it often fell short during our proof-of-concept. Specifically, we had challenges with:</p><ol><li><p><strong>Flexibility</strong>: Some platforms supported only a limited set of data sources, or restricted us to a single data source at a time. Several platforms allowed only a narrow range of Python packages for transformation logic, with rigid support for custom packages and environments. As our business grows, we didn&#8217;t feel we&#8217;d be able to adapt quickly enough by waiting on a third party to add necessary functionality.</p></li><li><p><strong>Scalability</strong>: Our data tends to be very wide (1000s of columns), and no platform was able to process it more efficiently than our existing infrastructure and pipelines. Our on-demand feature engineering requires very low latency, and there was often additional serving overhead compared to what we achieved with our DIY prototypes.&nbsp;</p></li><li><p><strong>Complex Transformations</strong>: We currently manage tens of thousands of features, and calculating them often involves a complex directed acyclic graph (DAG) of operations to transform raw data into output features. Only one platform we tried really solved this problem, and we realized how key it was to the solution we needed.&nbsp;</p></li></ol><h2><strong>Why We Chose to Build In-House</strong></h2><p>As a company with a strong foundation in data engineering, we believed we had the expertise to build a better, more tailored solution in-house. The key factors that drove this decision were:</p><ol><li><p><strong>Control and Flexibility</strong>: We needed to be able to design and evolve the system to meet the specific requirements of our models. By building it ourselves, we can iterate and optimize as needed without waiting on a vendor&#8217;s roadmap.&nbsp;</p></li><li><p><strong>Integration with Existing Infrastructure</strong>: We already have a complete set of tools at our disposal. Building in-house allows for seamless integration with our Kubernetes clusters, Snowflake data warehouse, and enterprise event bus, without requiring us to refactor everything to fit into a rigid commercial solution.<strong>&nbsp;</strong></p></li><li><p><strong>No Vendor Lock-in</strong>: We were honestly hoping to find a perfect solution we&#8217;d feel comfortable locking in to. Building a feature platform is no easy feat, and we recognize that every vendor is solving difficult problems, but for now, retaining flexibility is a key advantage.</p></li></ol><h2><strong>Enter Hamilton: The Right Framework for the Job</strong></h2><p>During our evaluation, we discovered <strong><a href="https://hamilton.dagworks.io/en/latest/">Hamilton</a></strong>, an open-source Python framework designed for creating flexible, modular, and portable data pipelines (think everything from data transforms, to ML, to GenAI). It has a <a href="https://join.slack.com/t/hamilton-opensource/shared_invite/zt-2niepkra8-DGKGf_tTYhXuJWBTXtIs4g">growing community on slack</a>, with weekly releases and <a href="https://www.meetup.com/global-hamilton-open-source-user-group-meetup/">a meet-up group</a>, and is driven by the <a href="https://www.dagworks.io/">DAGWorks Inc.</a> team that built the internal ML Platform at Stitch Fix. What caught our attention was how Hamilton&#8217;s approach to expressing transformations, i.e. features in our context, aligned perfectly with our goals of flexibility and scalability.</p><ol><li><p><strong>Modular and Declarative</strong>: Hamilton allows us to define extremely complex feature transformations in a modular way. We have several pipelines already which compute 500 &#8211; 2,000 features each, including multi-layered dependencies between features.&nbsp; Each feature is defined as a function, with clear dependencies and no hidden state. This makes our pipelines far more maintainable, testable, and faster to build.</p></li><li><p><strong>Efficient Feature Projection</strong>: While our pipelines may each support providing thousands of features, the average model may use 20-100 features for inference. Hamilton lets us dynamically prune the DAG to run only the nodes needed to produce the features requested by a model. This reduces our overall latency, especially when coupled with Hamilton&#8217;s <a href="https://blog.dagworks.io/p/async-dataflows-in-hamilton">async integration</a> which lets us only fetch from data sources that are needed for the request.&nbsp;</p></li><li><p><strong>Write Once, Run Anywhere</strong>: As mentioned, a key concern in feature engineering is to eliminate train-serve skew. Hamilton lets us write transformations for on-demand inference which may have a single record at a time. We can then reuse the same transformation code, swap out how data is loaded (e.g., Snowflake instead of a Redis cache used on-demand), and run large-scale backfills to generate training data. We can orchestrate our Python code anywhere without needing a JVM environment or any other specialized infrastructure.&nbsp;</p></li><li><p><strong>Compatibility with Our Existing Tools</strong>: Hamilton integrates well with our current machine learning ecosystem, which primarily includes pandas and Snowpark. This made adopting it a smoother process compared to other platforms that require complete infrastructure overhauls.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-Lk7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-Lk7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png 424w, https://substackcdn.com/image/fetch/$s_!-Lk7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png 848w, https://substackcdn.com/image/fetch/$s_!-Lk7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png 1272w, https://substackcdn.com/image/fetch/$s_!-Lk7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-Lk7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png" width="1456" height="907" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:907,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-Lk7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png 424w, https://substackcdn.com/image/fetch/$s_!-Lk7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png 848w, https://substackcdn.com/image/fetch/$s_!-Lk7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png 1272w, https://substackcdn.com/image/fetch/$s_!-Lk7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa42d7371-d92a-4d23-a8ee-8c337984e93f_1600x997.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>High-level architecture diagram</em></figcaption></figure></div><h2><strong>Building the Platform Around Hamilton</strong></h2><p>We built our entire platform around Hamilton, which is responsible for calculating features in four contexts:</p><ol><li><p><strong>On-Demand Feature Calculation</strong>: When models require features for individual records, the system can calculate these features in real time. We execute Hamilton DAGs as Ray tasks within a FastAPI server running on Kubernetes.&nbsp;</p></li><li><p><strong>Batch Processing</strong>: Many of our features, especially lifetime or long-windowed aggregations (e.g., last two years), can be calculated in batch. We use Hamilton to help modularize pipelines for both pandas and Snowpark. These features are then loaded into our offline feature store (Snowflake) for training and batch inference, but they can also be cached in our online store (DynamoDB) for online inference.</p></li><li><p><strong>Stream Processing</strong>: While we haven&#8217;t fully integrated stream processing yet, we plan to use Hamilton to help write dataframe transformations that could be used with a streaming database like <a href="https://risingwave.com/">Rising Wave</a>, thanks to Hamilton&#8217;s <a href="https://blog.dagworks.io/p/portable-dataflows-with-ibis-and">integration with Ibis</a>. These streaming features would be available in both the online and offline stores for inference and training.&nbsp;</p></li><li><p><strong>Backfills</strong>: We support backfills across the three main execution contexts, and spin up ephemeral Kubernetes jobs to handle the processing (ideally pushing down the execution to Snowflake). Hamilton lets us use reuse the same code to backfill, but also helps structure our DAGs to perform temporally-accurate backfills to compute features as-of a specific point in time, which could be unique for each entity in the selected population (i.e., millions of unique observation times to compute).</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jD-i!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jD-i!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png 424w, https://substackcdn.com/image/fetch/$s_!jD-i!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png 848w, https://substackcdn.com/image/fetch/$s_!jD-i!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png 1272w, https://substackcdn.com/image/fetch/$s_!jD-i!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jD-i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png" width="1435" height="999" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:999,&quot;width&quot;:1435,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jD-i!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png 424w, https://substackcdn.com/image/fetch/$s_!jD-i!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png 848w, https://substackcdn.com/image/fetch/$s_!jD-i!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png 1272w, https://substackcdn.com/image/fetch/$s_!jD-i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7b00cd39-1477-4e35-9cc6-98fdb11833c3_1435x999.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><em>Hamilton allows dynamically switching the data source depending on the context, while keeping calculation logic the same.</em></figcaption></figure></div><p>By using Hamilton as the core execution engine of our platform, we&#8217;ve been able to maintain a high degree of flexibility while supporting the complex requirements of feature engineering at scale. Pipelines that used to take months to build can now be onboarded in days or weeks. We&#8217;ve also reduced silos across departments and created a centralized place to engineer new features.&nbsp;</p><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/p/building-a-better-feature-platform?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Know anyone building feature platforms? Share it with them!</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/p/building-a-better-feature-platform?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/p/building-a-better-feature-platform?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><h2><strong>Looking Forward</strong></h2><p>The decision to build our own feature engineering platform was not made lightly, but it has proven to be the right choice for us so far. With Hamilton, we&#8217;ve created a system that:</p><ul><li><p>Scales efficiently with our data</p></li><li><p>Is flexible enough to adapt to changing business needs</p></li><li><p>Ensures consistency between training and production environments</p></li></ul><p>And most importantly, we&#8217;ve built a platform that gives us complete control, allowing us to continue innovating to meet the growing demands of our machine learning initiatives, all with the goal of better serving our customers.&nbsp;&nbsp;</p><p>Some of our future roadmap items include evaluating the companion <a href="https://blog.dagworks.io/p/hamilton-ui-streamlining-metadata">self-hostable UI that Hamilton comes with</a> to cover:</p><ul><li><p>Observability - making sure we catch and find data issues quickly will be key to ensuring reliability of the platform. With Hamilton we have feature provenance by default, and can <a href="https://blog.dagworks.io/p/customizing-hamiltons-execution-with">inject data observability</a> easily. Hamilton has features here that we&#8217;re looking to leverage.</p></li><li><p>Catalog - a UI to search for, find, and understand features. We expect that as our platform grows, curation &amp; understanding of the feature platform system will become more important, e.g. data dependencies, governance, cost, etc. We&#8217;re looking to invest in this area as time goes.</p></li></ul><h2><strong>Resources</strong></h2><ul><li><p><a href="https://github.com/dagworks-inc/hamilton">https://github.com/dagworks-inc/hamilton</a></p></li><li><p><a href="https://hamilton.dagworks.io/en/latest/">https://hamilton.dagworks.io/en/latest/</a></p></li><li><p><a href="https://www.tryhamilton.dev/">https://www.tryhamilton.dev/</a> </p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Agentic Design Pattern #1: Tool Calling]]></title><description><![CDATA[The first in our series of agentic design patterns with Burr]]></description><link>https://blog.dagworks.io/p/agentic-design-pattern-1-tool-calling</link><guid isPermaLink="false">https://blog.dagworks.io/p/agentic-design-pattern-1-tool-calling</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Sat, 28 Sep 2024 02:34:07 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rkso!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rkso!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rkso!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!rkso!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!rkso!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!rkso!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rkso!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2152043,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rkso!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!rkso!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!rkso!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!rkso!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23642977-cde1-4b79-9912-6ef48588241b_1024x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>Agentic Design Patterns</h2><p>LLMs have people&#8217;s heads spinning. The sheer freedom afforded by an API call is intoxicating &#8211; not only can you now *talk* to a computer, but you can use that computer to execute (and even write) code for you!</p><p>This has led to an influx of Burr users, many of whom want help modeling their systems. After building a successful chatbot, they inevitably migrate towards building agents. While the word <em>agent</em> is buzzy, we define it as follows: an <em>agent</em> is anything that uses the output of an LLM to do something on a users behalf (rather than just parroting it back to the user).</p><p>Although agents are generally seen as new-fangled and chaotic, we&#8217;ve noticed the emergence of a few common patterns that enable reliable usage of them in a production setting. In this series of posts, we will explore those &#8211; walk through basic dos/don&#8217;t's of agent development, and show how to implement them with Burr!</p><p>In this post we&#8217;ll be talking about how to use &#8220;<em>tool-calling&#8221;</em> to build an agent that responds to a query by selecting a &#8220;<em>tool&#8221;</em> to call from a list of &#8220;<em>prebuilt tools&#8221;</em>, then &#8220;<em>using</em>&#8221; it.&nbsp; We&#8217;ll go over some sample code, then talk about how Burr can help bring this system to production. We assume OpenAI as our LLM, but this example is straightforward to extend to other LLMs.</p><p>Note: you can see the code for the demo <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/tool-calling">here</a> and run it yourself/copy+paste to get started!</p><p>Before we start, let&#8217;s just get some grounding around language&#8230;</p><h2>&#8220;<em>Tools</em>&#8221; vs &#8220;functions&#8221; (vs &#8220;structured outputs&#8221;)</h2><p>It can be somewhat confusing what these mean. Do agents physically use tools? or do they call functions? or? Are they interchangeable? Are they not? What do they actually mean? </p><blockquote><p>TL;DR: a &#8220;<em>tool&#8221;</em> and a &#8220;<em>function&#8221;</em> are synonyms.</p></blockquote><p>We think people make this sound more complex than it really is. For the vast majority of purposes, a &#8220;<em>tool&#8221;</em> maps to a &#8220;<em>function</em>&#8221;, where function is the software engineering concept of function. That&#8217;s because we&#8217;re talking agents that are built via code, and so the simplest way to do something on a user&#8217;s behalf, is to invoke (i.e. call/ execute) a <em>function</em>.  However, since agents are a higher level concept, we&#8217;ll also use a higher level concept, i.e. &#8220;<em>tool&#8221;</em>, to describe what they can do / use.  So in short they&#8217;re synonyms and is why you&#8217;ll hear a phrase like &#8220;tool call&#8221; instead of &#8220;tool use&#8221; because it&#8217;s merging &#8220;function call&#8221; with &#8220;tool use&#8221;.</p><p>To make this more confusing, OpenAI recently deprecated its <em>function-calling</em> API in favor of its <em>tool-calling</em> API (really&#8230;) while Anthropic&#8217;s documentation refers to it as the entirely unambiguous <em>Tool use (function calling) </em>feature&#8230; So the industry has yet to align.</p><p>To simplify for the rest of this post, we&#8217;ll generally use &#8220;<em>tool</em>&#8221; to describe the general agent pattern. But where appropriate use the term &#8220;<em>function</em>&#8221; to actually explain what&#8217;s going on (we&#8217;ll also drop the quotes).</p><p></p><h3>But what are &#8220;structured outputs&#8221; then?</h3><p>When asking  an LLM to pick or choose a tool to use, what is returned in the response is usually a JSON representation of the name of the tool and what should be provided to the tool to make it work. Because it is JSON versus free text, it is <em>structured</em>. What people have figured out is that you can co-opt this behavior (e.g. <a href="https://platform.openai.com/docs/guides/structured-outputs/introduction">OpenAI&#8217;s structured outputs</a>) to make the LLM provide a response that is entirely JSON based, without having an actual <em>tool</em> to use. This can help you generalize outside of specific tool-calling APIs.</p><p>While we elect to directly use the tool-calling APIs in this post, adding a library like <a href="http://instructor/instructor at main &#183; jxnl/instructor">instructor</a> can help abstract this distinction from you. We leave this as an exercise for the reader&#8230;</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe to receive up-to-date posts on what we&#8217;re building!</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>Burr</h2><p>First, let&#8217;s go over the framework. <a href="https://github.com/DAGWorks-Inc/burr/">Burr</a> is a lightweight Python library you use to build applications as state machines. You construct your application out of a series of <em>actions</em> (these can be either decorated functions or objects), which declare inputs from <em>state</em>, as well as <em>inputs</em> from the user. These specify custom logic (delegating to any framework), as well as instructions on how to update state. State is immutable, which allows you to inspect it at any given point. Burr handles orchestration, monitoring, persistence, etc&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aVVt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" width="723" height="65" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:65,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30725,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Hello world counter action. Gist <a href="https://gist.github.com/elijahbenizzy/c295c2578685867996577733b8005f59">here</a></figcaption></figure></div><p>You run your Burr actions as part of an application &#8211; this allows you to string them together with a series of (optionally) conditional transitions from action to action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ejRj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png" width="1444" height="568" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:568,&quot;width&quot;:1444,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:119779,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!ejRj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 424w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 848w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1272w, https://substackcdn.com/image/fetch/$s_!ejRj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b0bff82-310e-4106-8d1a-52ad9bcf1230_1444x568.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Using the application builder. Gist <a href="http://238196b05d123353999b9263c3c1a76f/">here</a></figcaption></figure></div><p>Burr comes with a user-interface that enables monitoring/telemetry, as well as hooks to persist state/execute arbitrary code during execution.</p><p>You can visualize this as a flow chart, i.e. graph / state machine:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lYVz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png" width="216" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;State Machine&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="State Machine" title="State Machine" srcset="https://substackcdn.com/image/fetch/$s_!lYVz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!lYVz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc28ab6aa-57ec-423b-b9c9-fc1637150b86_216x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>And monitor it using the local telemetry debugger:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!k3JA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!k3JA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png 424w, https://substackcdn.com/image/fetch/$s_!k3JA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png 848w, https://substackcdn.com/image/fetch/$s_!k3JA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png 1272w, https://substackcdn.com/image/fetch/$s_!k3JA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!k3JA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png" width="1456" height="836" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:836,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:433872,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!k3JA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png 424w, https://substackcdn.com/image/fetch/$s_!k3JA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png 848w, https://substackcdn.com/image/fetch/$s_!k3JA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png 1272w, https://substackcdn.com/image/fetch/$s_!k3JA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8bdd5937-9a2a-425e-8b14-89a3805920b1_1706x979.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>While the above example is a simple illustration, Burr is commonly used for AI assistants (like in this example), RAG applications, and human-in-the-loop AI interfaces. See the repository <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples">examples</a> for a (more exhaustive) set of use-cases. </p><h2>Knowing which tool to use</h2><p>LLMs have emerged as a way to determine a user&#8217;s intent and also carry that intent out. For instance, say you have a query as simple as:</p><blockquote><p><em>What is the weather in San Francisco?</em></p></blockquote><p>Aside from hardcoding the response <em>foggy</em>, this used to be a hard problem. Nowadays, this seems fairly easy &#8211; you can just ask an LLM! &nbsp;</p><p>State of the art models, however, do not have the capability to answer a question like&nbsp; this as they are largely closed off from the internet&nbsp; (although some tooling has begun to bridge that gap). Instead, their superpower is determining the user&#8217;s intent and telling you how to figure it out yourself (LLMs can&#8217;t run code, but they can tell you what you should do). So, rather than asking the LLM what the weather is in San Francisco and expecting a result, you should ask the LLM <em>how do I determine the weather in San Francisco, given that I can do X, Y, and Z.&nbsp; </em>X, Y, and Z could be whatever preset <em>tools (i.e. functions)</em> you have. If you&#8217;re lucky, X could be &#8220;use a simple weather API, given JSON parameters&#8221;, and the LLM would know about it &#8211; providing the JSON parameters so you can do the call. Providers such as <a href="https://docs.anthropic.com/en/docs/build-with-claude/tool-use">Anthropic</a> and <a href="https://platform.openai.com/docs/guides/function-calling">OpenAI</a> have sophisticated APIs to make this easy &#8212; they select from a list of tools and generate the parameters.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uqQf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uqQf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png 424w, https://substackcdn.com/image/fetch/$s_!uqQf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png 848w, https://substackcdn.com/image/fetch/$s_!uqQf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png 1272w, https://substackcdn.com/image/fetch/$s_!uqQf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uqQf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png" width="1007" height="165" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:165,&quot;width&quot;:1007,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uqQf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png 424w, https://substackcdn.com/image/fetch/$s_!uqQf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png 848w, https://substackcdn.com/image/fetch/$s_!uqQf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png 1272w, https://substackcdn.com/image/fetch/$s_!uqQf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48858fce-e060-4b81-bf6d-054ae6a4998d_1007x165.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Simple illustration of the call-path. Note that this is one path <em>through</em> a flowchart that a system like Burr will provide</figcaption></figure></div><p>Zooming in on the &#8220;Ask LLM for tool parameters&#8221; part of the flow chart above. For the LLM to know that a tool exists, you need to explain the tool to the LLM as part of the context that is sent. Different LLM providers can do this differently, but in general you are going to be doing the following:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IOwD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IOwD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png 424w, https://substackcdn.com/image/fetch/$s_!IOwD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png 848w, https://substackcdn.com/image/fetch/$s_!IOwD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png 1272w, https://substackcdn.com/image/fetch/$s_!IOwD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IOwD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png" width="1456" height="1117" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1117,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Function Calling diagram&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Function Calling diagram" title="Function Calling diagram" srcset="https://substackcdn.com/image/fetch/$s_!IOwD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png 424w, https://substackcdn.com/image/fetch/$s_!IOwD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png 848w, https://substackcdn.com/image/fetch/$s_!IOwD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png 1272w, https://substackcdn.com/image/fetch/$s_!IOwD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3e5a7858-f064-4d22-8396-7bad45ba98fa_1908x1464.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://platform.openai.com/docs/guides/function-calling/lifecycle">Image from the OpenAI docs</a> on function/tool calling. </figcaption></figure></div><p>Let&#8217;s now dive into how you&#8217;d set up an agent written in Burr to use an LLM to determine what tool to use and submit a response to the user.</p><h2>A Straightforward Tool Calling Pattern with Burr</h2><p>Implementing tool-calling with Burr is just a thin layer on top of any provided LLM API that supports tool/function calling a.k.a. &#8220;structured outputs&#8221;.&nbsp;</p><p>Let&#8217;s generalize our use case slightly and move from <em>answering a specific &#8220;what the weather is question&#8221; </em>to <em>answering any question in general</em>. To set this up, we need to provide the LLM the set of <em>tools</em> that you use to get an answer with. E.G. you have <em>functions</em> that wrap APIs to query the weather, order coffee, text your wife that you love her, etc&#8230; And all you want to do is convert natural language (i.e. user queries) to input parameters to use one of those tools.&nbsp;</p><p>We will also add a fallback tool that allows the LLM to attempt to answer using its own knowledge (you don&#8217;t need a tool to know what 10 x 10 is&#8230;).</p><p>First, let&#8217;s define some functions, i.e. tools. For brevity here we only show our weather_tool.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZWv0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZWv0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png 424w, https://substackcdn.com/image/fetch/$s_!ZWv0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png 848w, https://substackcdn.com/image/fetch/$s_!ZWv0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png 1272w, https://substackcdn.com/image/fetch/$s_!ZWv0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZWv0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png" width="722" height="262" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:262,&quot;width&quot;:722,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:111820,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZWv0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png 424w, https://substackcdn.com/image/fetch/$s_!ZWv0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png 848w, https://substackcdn.com/image/fetch/$s_!ZWv0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png 1272w, https://substackcdn.com/image/fetch/$s_!ZWv0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d10eaf7-6ea0-41ee-a6ca-328bb9234de9_722x262.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/b687de29b2a91f06115e49b307015967/">here</a>. This tool is using <a href="https://www.tomorrow.io/">tomorrow.io</a> &#8212; it is free to sign up for/test out and has a very powerful API.</figcaption></figure></div><p>Not shown but we can also have <code>_text_wife_tool, _order_coffee_tool, </code>and any others we want. We will also have a <code>_fallback </code>function that gives out a simple statement in case we can&#8217;t answer using the desired tools or the LLM fails to answer otherwise.</p><p>Let&#8217;s gather these into a prebuilt list. What we&#8217;re doing here is simple &#8212; we&#8217;re formatting function signatures as the OpenAI compatible type; we&#8217;re doing a clever trick of using Python&#8217;s inspect module to tell us about the function itself. This means that it&#8217;s easy to add new functions, i.e. tools, for the LLM to know about. Alternatively, you could <a href="https://platform.openai.com/docs/guides/function-calling/function-calling-with-structured-outputs">use pydantic here</a> to define the tools. Note: there is additional validation of signatures that we have not shown in the code below.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5DhF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5DhF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png 424w, https://substackcdn.com/image/fetch/$s_!5DhF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png 848w, https://substackcdn.com/image/fetch/$s_!5DhF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png 1272w, https://substackcdn.com/image/fetch/$s_!5DhF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5DhF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png" width="734" height="724" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:724,&quot;width&quot;:734,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:90645,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5DhF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png 424w, https://substackcdn.com/image/fetch/$s_!5DhF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png 848w, https://substackcdn.com/image/fetch/$s_!5DhF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png 1272w, https://substackcdn.com/image/fetch/$s_!5DhF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F53f1a6ce-7432-4749-94c4-f1d04a86dbbd_734x724.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/33a43994a44af33e591f6c3361740a39">here</a></figcaption></figure></div><p>We now call OpenAI to choose the tool. We model this as specific Burr action. The input is state with the user question, and the output will be the details of what tools should be run and with what values.  Note the LLM call was finicky &#8212; it didn&#8217;t always want to choose a tool, and sometimes got lost in the instructions&#8230; But, with a little bit of prompt engineering (experimented on with Burr&#8217;s UI), we were able to get reasonable behavior:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Hfj2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Hfj2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png 424w, https://substackcdn.com/image/fetch/$s_!Hfj2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png 848w, https://substackcdn.com/image/fetch/$s_!Hfj2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png 1272w, https://substackcdn.com/image/fetch/$s_!Hfj2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Hfj2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png" width="719" height="855" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:855,&quot;width&quot;:719,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:147510,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Hfj2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png 424w, https://substackcdn.com/image/fetch/$s_!Hfj2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png 848w, https://substackcdn.com/image/fetch/$s_!Hfj2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png 1272w, https://substackcdn.com/image/fetch/$s_!Hfj2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8860be1-f03d-43c7-85ce-4e98c0e5d1c8_719x855.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/55c0bd29eab2323db6fc6d21a67007a4">here</a></figcaption></figure></div><p>The next step is to create a Burr action to exercise the chosen tool.  We could model this as a single Burr action that would execute whatever the tool call was. Or, we can use a cool trick to make specific Burr actions for each tool, but still keep the code concise. We can do that with Burr&#8217;s <code>.bind()</code> feature, that allows you to define a single action with a parameter and turn that into multiple actions, by &#8220;binding&#8221; different values for that parameter. In this case, we can parameterize the tool-calling function, binding the tool (i.e. function) to create a Burr action for each tool we have defined (skip to the application builder code to see how). Each of these will take in the tool parameters provided by OpenAI, and output the raw response in some raw (dictionary) format:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4fc6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4fc6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png 424w, https://substackcdn.com/image/fetch/$s_!4fc6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png 848w, https://substackcdn.com/image/fetch/$s_!4fc6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png 1272w, https://substackcdn.com/image/fetch/$s_!4fc6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4fc6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png" width="718" height="89" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/abe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:89,&quot;width&quot;:718,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27613,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4fc6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png 424w, https://substackcdn.com/image/fetch/$s_!4fc6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png 848w, https://substackcdn.com/image/fetch/$s_!4fc6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png 1272w, https://substackcdn.com/image/fetch/$s_!4fc6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabe5b421-6550-4d58-9f58-2235b820b2bc_718x89.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/6e1af19f964dcef692fc64e6ebfdc4f4">here</a></figcaption></figure></div><p>We could also have this be a single action that chooses between tools (given the tool set in state), but the nice thing about the one-tool-per-node approach is that we can view all the tools in the graph (see below).</p><p>Finally, we&#8217;ll have an action that formats the results using OpenAI &#8212; this just takes the raw result and puts it in a format the user might like. Note you will likely want to restrict this to some structured object to make it friendly for web rendering, e.g. with a tool like <a href="http://instructor.io">instructor</a>. Below we just return the output straight from OpenAI.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bHjb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bHjb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png 424w, https://substackcdn.com/image/fetch/$s_!bHjb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png 848w, https://substackcdn.com/image/fetch/$s_!bHjb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png 1272w, https://substackcdn.com/image/fetch/$s_!bHjb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bHjb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png" width="710" height="546" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:546,&quot;width&quot;:710,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:80953,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bHjb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png 424w, https://substackcdn.com/image/fetch/$s_!bHjb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png 848w, https://substackcdn.com/image/fetch/$s_!bHjb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png 1272w, https://substackcdn.com/image/fetch/$s_!bHjb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faeb56bb7-a21a-4eca-ba55-806a58c19115_710x546.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/e63ef4425d94c57ee7377f1aa33e366f">here</a></figcaption></figure></div><p>Finally, we tie this all together to create the Burr Application. In this case we&#8217;re hardcoding tool names for simplicity, but we could easily use a single dictionary throughout this and the above code to make this code DRYer:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dvgQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dvgQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png 424w, https://substackcdn.com/image/fetch/$s_!dvgQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png 848w, https://substackcdn.com/image/fetch/$s_!dvgQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png 1272w, https://substackcdn.com/image/fetch/$s_!dvgQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dvgQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png" width="715" height="548" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:548,&quot;width&quot;:715,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:94283,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dvgQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png 424w, https://substackcdn.com/image/fetch/$s_!dvgQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png 848w, https://substackcdn.com/image/fetch/$s_!dvgQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png 1272w, https://substackcdn.com/image/fetch/$s_!dvgQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F167a8405-73a7-4e8e-a3a7-b4bc3d7d4779_715x548.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/4b1c82720c95e258fdd7e8ffa9615dafa">here</a></figcaption></figure></div><p>This creates a very reasonable looking graph &#8212; we loop back to the input when we&#8217;re done so the user can ask another question:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aOBb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aOBb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png 424w, https://substackcdn.com/image/fetch/$s_!aOBb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png 848w, https://substackcdn.com/image/fetch/$s_!aOBb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png 1272w, https://substackcdn.com/image/fetch/$s_!aOBb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aOBb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png" width="575" height="409" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:409,&quot;width&quot;:575,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:31339,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!aOBb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png 424w, https://substackcdn.com/image/fetch/$s_!aOBb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png 848w, https://substackcdn.com/image/fetch/$s_!aOBb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png 1272w, https://substackcdn.com/image/fetch/$s_!aOBb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15cf33ed-4616-4050-944e-c6a004c4fd43_575x409.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Let&#8217;s test this out&#8230;</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dl_H!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dl_H!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png 424w, https://substackcdn.com/image/fetch/$s_!dl_H!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png 848w, https://substackcdn.com/image/fetch/$s_!dl_H!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png 1272w, https://substackcdn.com/image/fetch/$s_!dl_H!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dl_H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png" width="718" height="133" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:133,&quot;width&quot;:718,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:19578,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dl_H!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png 424w, https://substackcdn.com/image/fetch/$s_!dl_H!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png 848w, https://substackcdn.com/image/fetch/$s_!dl_H!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png 1272w, https://substackcdn.com/image/fetch/$s_!dl_H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe452cd2e-4b8c-4308-b28a-3d90efa0aeb3_718x133.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/8a68a673fd16be521e802db47c369d80">here</a></figcaption></figure></div><p>And the result is:</p><pre><code>The current weather in San Francisco is clear with no cloud cover, a temperature around 24.81&#176;C (76.66&#176;F), and a humidity of approximately 51%. Wind speeds are mild at about 5.13 km/h, with gusts up to 6.31 km/h. Visibility is excellent at 16 km. There is no precipitation expected, and the UV index is at 0, indicating no immediate health concerns from UV exposure.</code></pre><p>Yeah, not foggy. Hmm, not sure I trust this whole AI thing&#8230;</p><h2>Is Burr more than I need?</h2><p>While the API calls are simple, and the code above <em>could</em> be written without Burr, the orchestration + capabilities Burr provides add significant benefits to both development and production. </p><h3>Modeling with Extensibility</h3><p>As everything is represented by a graph, the workflow is self-documenting. You can view the graph, read through the application builder and get a good sense of how your LLM is thinking. Furthermore, as you inevitably add more tools (and adjust prompts), you have the guarantee that changes are located in specific Burr actions, and compare code across runs.</p><p>Furthermore, should you want to add additional graph-level concerns (error conditions, etc&#8230;) you can do so simply by adding actions &amp; edges without touching any of your other code.</p><h3>Monitoring + Visibility</h3><p>In addition to ensuring your graph is more readable, Burr comes with a one-line change to add observability that is paired with an open-source user interface. This allows you to debug as you progress. With tool-calling (LLMs can be fickle and occasionally have a tough time matching intent with the tool to use), this is debugging insight is very useful. Should the LLM <em>not </em>give what you desire, you can:</p><ol><li><p>Examine the state</p></li><li><p>Look through the <a href="https://burr.dagworks.io/reference/integrations/opentelemetry/">opentelemetry</a> data for chat completions</p></li><li><p>Recreate with specific <a href="https://burr.dagworks.io/examples/creating_tests/">test-cases</a> to iterate and fix the issue</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wSPd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wSPd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png 424w, https://substackcdn.com/image/fetch/$s_!wSPd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png 848w, https://substackcdn.com/image/fetch/$s_!wSPd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png 1272w, https://substackcdn.com/image/fetch/$s_!wSPd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wSPd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png" width="1456" height="769" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:769,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:490134,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wSPd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png 424w, https://substackcdn.com/image/fetch/$s_!wSPd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png 848w, https://substackcdn.com/image/fetch/$s_!wSPd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png 1272w, https://substackcdn.com/image/fetch/$s_!wSPd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc25eaa1b-25ed-4e8e-80f7-596841b54ea9_3400x1796.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">View traces + metadata in the <a href="https://blog.dagworks.io/p/burr-ui">Burr UI</a>, watch it show up live</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!a-Iy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!a-Iy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png 424w, https://substackcdn.com/image/fetch/$s_!a-Iy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png 848w, https://substackcdn.com/image/fetch/$s_!a-Iy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png 1272w, https://substackcdn.com/image/fetch/$s_!a-Iy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!a-Iy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png" width="1456" height="813" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:813,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:441994,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!a-Iy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png 424w, https://substackcdn.com/image/fetch/$s_!a-Iy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png 848w, https://substackcdn.com/image/fetch/$s_!a-Iy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png 1272w, https://substackcdn.com/image/fetch/$s_!a-Iy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f44bb5a-0642-44e4-8eea-3e08eb1f9747_1688x943.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">View token count by step/span</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!d7Xx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!d7Xx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png 424w, https://substackcdn.com/image/fetch/$s_!d7Xx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png 848w, https://substackcdn.com/image/fetch/$s_!d7Xx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png 1272w, https://substackcdn.com/image/fetch/$s_!d7Xx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!d7Xx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png" width="1456" height="825" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:825,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:453438,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!d7Xx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png 424w, https://substackcdn.com/image/fetch/$s_!d7Xx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png 848w, https://substackcdn.com/image/fetch/$s_!d7Xx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png 1272w, https://substackcdn.com/image/fetch/$s_!d7Xx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8cb3da9b-d0d5-4eec-9ccb-277b4f4f8d1b_1687x956.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Examine the state at any given point and watch how it changes</figcaption></figure></div><p>Should your actual tool, i.e. function call, be giving you errors, you can also annotate these tools with the <a href="https://burr.dagworks.io/reference/visibility/#burr.visibility.tracing.trace">`@trace()` decorator</a> (and even the code inside those functions). What this will do is have those function invocations also logged to the Burr UI!</p><h3>Additional Production Concerns</h3><p>Using Burr also makes it easier to ship to/manage your app in production. You can:</p><ol><li><p>Add persistence/track sessions with Burr&#8217;s <a href="https://burr.dagworks.io/concepts/state-persistence/">persistence API </a>&#8211; another one-line change to hook into the database of your choice</p></li><li><p>Deploy in a <a href="https://app.daily.dev/posts/how-to-build-a-streaming-agent-with-burr-fastapi-and-react-xozdmrscy">FastAPI server </a>using Burr&#8217;s <a href="https://burr.dagworks.io/concepts/state-typing/">state-typing capabilities</a></p></li><li><p>Gather data for evaluation datasets (more documentation on this coming soon&#8230;)</p></li></ol><h2>Wrapping up/Further Reading</h2><p>In this post we talked about how to build a simple tool-calling app with Burr + OpenAI.</p><p>While this is more of a toy application, we&#8217;ve found a lot more profound/powerful agentic patterns that we&#8217;ll be talking about in the coming weeks/months. Up next:</p><ol><li><p>How to string together a chain of tools to answer a question/carry out an action</p></li><li><p>How to query and call a set tools in parallel (E.G. for research)</p></li><li><p>How to leverage multiple agents to answer a question</p></li><li><p>How to have agents that work together constructively to answer a question/complete a task</p></li></ol><p>And more! We&#8217;re always looking for new use-cases, so if you have one you&#8217;re curious about, reach out and we can show you how it would work with Burr!</p><p>In the meanwhile,&nbsp;</p><ul><li><p>Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a> for help or if you have questions!</p></li><li><p>Star our <a href="https://github.com/dagworks-inc/burr">Github repository</a> if you like what you see</p></li><li><p>Check out the recent <a href="https://burr.dagworks.io/reference/integrations/opentelemetry/">OpenTelemetry integration</a> for additional observability</p></li><li><p>See the code for this post among <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/tool-calling">our examples</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Hamilton supports OpenLineage]]></title><description><![CDATA[Hamilton is very extensible - here we explain how Hamilton is now an OpenLineage Producer and can help you wrangle your data lineage efforts.]]></description><link>https://blog.dagworks.io/p/hamilton-supports-openlineage</link><guid isPermaLink="false">https://blog.dagworks.io/p/hamilton-supports-openlineage</guid><dc:creator><![CDATA[DAGWorks Inc.]]></dc:creator><pubDate>Wed, 18 Sep 2024 17:08:17 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!azph!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!azph!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!azph!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png 424w, https://substackcdn.com/image/fetch/$s_!azph!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png 848w, https://substackcdn.com/image/fetch/$s_!azph!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png 1272w, https://substackcdn.com/image/fetch/$s_!azph!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!azph!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png" width="337" height="227.9553158705701" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:439,&quot;width&quot;:649,&quot;resizeWidth&quot;:337,&quot;bytes&quot;:77609,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!azph!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png 424w, https://substackcdn.com/image/fetch/$s_!azph!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png 848w, https://substackcdn.com/image/fetch/$s_!azph!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png 1272w, https://substackcdn.com/image/fetch/$s_!azph!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F531c902f-c779-4571-8450-0be82bc1d8cd_649x439.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Hamilton + OpenLineage</figcaption></figure></div><blockquote><p>You don&#8217;t know you need it, until you need it. </p></blockquote><p>When data teams are small, it&#8217;s simple enough to ask the person next to you,&nbsp; &#8220;hey what produced this table <em>prod.customer_orders</em>&#8221;, or &#8220;what data created this particular predictive churn model?&#8221; But as teams grow, and more data is produced, keeping track of how it all relates becomes a challenge.&nbsp;</p><p>In this post, we&#8217;ll go over how you can track all the data that you produce with Hamilton &amp; OpenLineage. Specifically we will cover what Hamilton &amp; OpenLineage are, and how Hamilton&#8217;s new OpenLineage adapter integrates with the OpenLineage ecosystem.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/subscribe?"><span>Subscribe now</span></a></p><h1>What is Hamilton?</h1><p>Hamilton is a standardized way of building dataflows, a.k.a. &#8220;pipelines&#8221;, in Python. The core concepts are simple &#8211; you write each data transformation step as a single Python function with the following rules:</p><ol><li><p>The name of the function corresponds to the output variable it computes.</p></li><li><p>The parameter names (and types) correspond to inputs. These can be either passed-in parameters or names of other upstream functions.</p></li></ol><p>This approach allows you to represent <em>assets</em> in ways that correspond closely to code, naturally self-documenting, and portable across infrastructure.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tcXe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tcXe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 424w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 848w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 1272w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tcXe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png" width="1130" height="704" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:704,&quot;width&quot;:1130,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!tcXe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 424w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 848w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 1272w, https://substackcdn.com/image/fetch/$s_!tcXe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F28444873-6c89-47e1-b27e-a0e8e69f3925_1130x704.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>After writing your functions, you call a driver to execute them &#8211; in most cases this is a simple import/run (specifying the assets you want computed and letting the framework do the rest), but it provides options to customize execution:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!A5xg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!A5xg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png 424w, https://substackcdn.com/image/fetch/$s_!A5xg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png 848w, https://substackcdn.com/image/fetch/$s_!A5xg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png 1272w, https://substackcdn.com/image/fetch/$s_!A5xg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!A5xg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png" width="1438" height="398" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:398,&quot;width&quot;:1438,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:66172,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!A5xg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png 424w, https://substackcdn.com/image/fetch/$s_!A5xg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png 848w, https://substackcdn.com/image/fetch/$s_!A5xg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png 1272w, https://substackcdn.com/image/fetch/$s_!A5xg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7ce22604-9960-4590-9095-b32b4b0b6d46_1438x398.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/c5f46a612bf498d3100936b84d693ea3">gist</a></figcaption></figure></div><p>Hamilton powers a wide range of use cases including <a href="https://blog.dagworks.io/p/feature-engineering-with-hamilton">feature engineering</a>, <a href="https://github.com/DAGWorks-Inc/hamilton/tree/main/examples/model_examples/scikit-learn">ML training/inference pipelines</a> (relevant to this post), <a href="https://blog.dagworks.io/p/rag-ingestion-and-chunking-using">RAG pipelines</a>, and more. </p><blockquote><p>Visit <a href="https://www.tryhamilton.dev/">tryhamilton.dev</a> for a quick interactive introduction in the browser.  </p></blockquote><h1>What is OpenLineage?</h1><p><a href="https://openlineage.io/">OpenLineage</a> is a standard for tracking the flow of data (e.g. <a href="https://en.wikipedia.org/wiki/Data_lineage">data lineage</a>) through different tools and systems in an organization. It is a form of <a href="https://en.wikipedia.org/wiki/Observability_(software)">observability</a>. </p><p>If this is new to you, a shipping tracking system is a good analogy. Imagine you order a product online and you want to know where it is at any moment &#8212; from the warehouse to the delivery truck to your doorstep. OpenLineage does something similar, it tracks data as it moves through various stages of processing and transformation within an organization. By having this tracking in place, teams can understand where the data came from, what happened to it, and where it ended up. This helps with:</p><ul><li><p>troubleshooting issues</p></li><li><p>ensuring data quality</p></li><li><p>complying with regulations</p></li><li><p>and more</p></li></ul><p>It becomes easy to understand the data&#8217;s journey, like knowing exactly where your package is and when it will arrive. </p><h2>The OpenLineage standard</h2><p>OpenLineage is a standard, meaning it is supported by multiple tools, allowing you to have precise lineage as data move through different components of your system (ETL, machine learning training and inference, predictions, etc.). The standard is implemented as a JSON schema that describe &#8220;data events&#8221; (<a href="https://github.com/OpenLineage/OpenLineage/blob/main/spec/OpenLineage.md">read more</a>).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mA9d!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mA9d!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg 424w, https://substackcdn.com/image/fetch/$s_!mA9d!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg 848w, https://substackcdn.com/image/fetch/$s_!mA9d!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg 1272w, https://substackcdn.com/image/fetch/$s_!mA9d!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mA9d!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg" width="1456" height="754" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:754,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Model&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Model" title="Model" srcset="https://substackcdn.com/image/fetch/$s_!mA9d!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg 424w, https://substackcdn.com/image/fetch/$s_!mA9d!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg 848w, https://substackcdn.com/image/fetch/$s_!mA9d!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg 1272w, https://substackcdn.com/image/fetch/$s_!mA9d!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1480e98c-e90e-48e5-bf60-d1659473061d_769x398.svg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Visualization of the core data model of OpenLineage</figcaption></figure></div><p>The OpenLineage ecosystem is composed of <a href="https://openlineage.io/ecosystem">producers</a>, which are tools that transform data and generate OpenLineage events (e.g., Hamilton, Airflow, dbt, Dagster, Snowflake, Great Expectations, etc.), and <a href="https://openlineage.io/ecosystem">consumers</a> which are platforms to observe and catalog data transformations across producers (Amundsen, Marquez, OpenMetadata, etc.).</p><h2>Who needs lineage?</h2><p>Everyone wants lineage, but nobody wants to implement it. In sectors where auditing and governance are requirements, OpenLineage is critical to understand data impacts and comply with regulation. However, even when it&#8217;s not critical, OpenLineage is can be an enormous boost for productivity because it allows you to monitor what data within your organization is used and plan changes that won&#8217;t break someone else&#8217;s pipeline. Because lineage is hard to implement, teams avoid extra effort to integrate it, but Hamilton makes it easy for you! <strong>In fact,</strong> you get a lot of &#8220;<a href="https://blog.dagworks.io/p/lineage-hamilton-in-10-minutes-c2b8a944e2e6?utm_source=publication-search">lineage</a>&#8221; with Hamilton, even more than what&#8217;s specified in the OpenLineage specification: you get logical lineage and provenance with Hamilton, and then observability with a single line if you&#8217;re using <a href="https://blog.dagworks.io/p/hamilton-ui-streamlining-metadata">the HamiltonTracker with the Hamilton UI</a>. In this post we&#8217;re leveraging this to make it easy to emit OpenLineage events.</p><h1>How Hamilton produces OpenLineage events</h1><p>To work, OpenLineage needs to know about what data was loaded &amp; saved. When writing your Hamilton code, can generate the required metadata by using the <a href="https://hamilton.dagworks.io/en/latest/concepts/materialization/">materializer</a> feature. There are several ways to use it:</p><ol><li><p>Use the @<a href="https://hamilton.dagworks.io/en/latest/reference/decorators/dataloader/">dataloader</a> and @<a href="https://hamilton.dagworks.io/en/latest/reference/decorators/datasaver/">datasaver</a> decorators to load/save your data and produce metadata (see example below).</p></li><li><p>Materializer <a href="https://hamilton.dagworks.io/en/latest/concepts/function-modifiers/#loader-saver-decorators">decorators</a> with <code>.execute()</code></p></li><li><p>Materializer classes with either .<a href="https://hamilton.dagworks.io/en/latest/concepts/materialization/#static-materializers">with_materializers</a>() or .<a href="https://hamilton.dagworks.io/en/latest/concepts/materialization/#dynamic-materializers">materialize</a>().</p></li></ol><p>Below we show the first approach (1):</p><pre><code>import pickle
from typing import Tuple

import pandas as pd

from hamilton.function_modifiers import dataloader, datasaver
from hamilton.io import utils

<strong>@dataloader()</strong>
def user_dataset(file_ds_path: str) -&gt; Tuple[pd.DataFrame, dict]:
    df = pd.read_csv(file_ds_path)
    return df, <strong>utils.get_file_and_dataframe_metadata(file_ds_path, df)</strong>

...

<strong>@datasaver()</strong>
def saved_file(fit_model: ModelObject, file_path: str) -&gt; dict:
    with open(file_path, "wb") as f:
        pickle.dump(fit_model, f)
    return <strong>utils.get_file_metadata(file_path)</strong>
</code></pre><p>Importantly, you don&#8217;t need to import anything related to OpenLineage when defining your data transformations. Your code remains platform agnostic, as shown in the above example. </p><p>To integrate with OpenLineage, we use Hamilton&#8217;s very extensible <a href="https://blog.dagworks.io/p/customizing-hamiltons-execution-with">lifecycle API system</a>. The lifecycle API allows you to quickly write custom &#8220;adapters&#8221; that can observe things before and after graph &amp; node execution. The OpenLineage adapter will produce lineage events as you execute your dataflow. To enable this feature, simply add the adapter to your Hamilton Driver:</p><pre><code>import my_dataflow
from openlineage.client import OpenLineageClient

# write to HTTP, e.g. marquez; there are others like Kafka, File, etc.
client = OpenLineageClient(url="http://localhost:5000")

# create the adapter
adapter = OpenLineageAdapter(client, "my_namespace", "my_job_name")

# add to Hamilton
# import your pipeline code
dr = (
  driver.Builder()
  .with_modules(my_dataflow)
  .with_adapters(adapter) # &lt;-- add the adapter here
  .build()
)
# execute as normal -- and openlineage events will be emitted
dr.execute(...)</code></pre><p>In terms of OpenLineage specifics, currently Hamilton emits the following <a href="https://openlineage.io/docs/spec/facets/">facets</a>:</p><ol><li><p><code>SourceCodeJobFacet </code>- with the entire source code of your Hamilton dataflow.</p></li><li><p><code>JobTypeJobFacet </code>- specifying a BATCH job.</p></li><li><p>A custom <code>HamiltonFacet </code>- that specifies the parameterization of the Hamilton dataflow.</p></li><li><p>A <code>StorageDatasetFacet </code>&amp; <code>DatasourceDatasetFacet </code>- for files loaded &amp; saved</p></li><li><p>A <code>SQLJobFacet </code>- if SQL is detected as being used.</p></li><li><p>A <code>ErrorMessageRunFacet </code>- if your Hamilton dataflow execution fails.</p></li></ol><p>If you need more facets, please open up an issue / open up a PR to contribute!</p><h2>Example code</h2><p>If you&#8217;re after some sample code to get started, we&#8217;ve got <a href="https://github.com/DAGWorks-Inc/hamilton/tree/main/examples/openlineage">an example here to help you get started</a>.</p><h1>Use case: Boost Airflow pipeline observability with Hamilton</h1><p>If you&#8217;re using Airflow&#8217;s <a href="https://airflow.apache.org/docs/apache-airflow/stable/howto/operator/python.html">Python</a> &amp; <a href="https://airflow.apache.org/docs/apache-airflow-providers-cncf-kubernetes/stable/operators.html">Kubernetes</a> operator &#8212; you can&#8217;t emit lineage events from arbitrary Python code. But if it&#8217;s running Hamilton(!), you can now easily make sure that all your data, ML, and AI workflows provide lineage and visibility over what&#8217;s happening.</p><p>A sketch of the code would be the following:</p><ol><li><p>Put Hamilton within the Python / Kubernetes task.</p></li><li><p>Add the OpenLineage adapter when constructing the Driver.</p></li><li><p>Execute as normal &#8212; and gain OpenLineage insights everywhere!</p></li></ol><pre><code>@task
def my_python_task(some_argument):
    """This is a function that will run within Airflow"""
    from openlineage.client import OpenLineageClient

    # write to HTTP, e.g. marquez
    client = OpenLineageClient(url="http://localhost:5000")

    # create the adapter
    <strong>adapter = OpenLineageAdapter(client, "my_namespace", "my_job_name")</strong>

    # add to Hamilton
    # import your pipeline code
    dr = (driver
      .Builder()
      .with_modules(YOUR_MODULES)
      <strong>.with_adapters(adapter) # &lt;-- add the adapter here</strong>
      .build()
    )
    # execute as normal -- and openlineage events will be emitted
    dr.execute(...)</code></pre><h1>Does the Hamilton UI consume OpenLineage events?</h1><p>Not yet; an integration is on the roadmap.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.dagworks.io/subscribe?"><span>Subscribe now</span></a></p><h1>Summary</h1><p>This post introduced Hamilton, OpenLineage, and how they can power your data lineage efforts. <a href="https://github.com/dagworks-inc/hamilton">Hamilton</a> helps fill observability and lineage gaps in Python code via its graph structure and OpenLineage event emission.</p><p>Hamilton is now an OpenLineage producer, and the Hamilton UI should become an OpenLineage consumer soon! This will provide the single pane of glass connecting data, ML, and AI observability.</p><h1>We Want to Hear from You</h1><p>If you&#8217;re excited by any of this, or have strong opinions, drop by our Slack channel / or leave some comments here! Some resources to get you help:</p><p>&#128227; <a href="https://join.slack.com/t/hamilton-opensource/shared_invite/zt-1bjs72asx-wcUTgH7q7QX1igiQ5bbdcg">join our community on Slack</a>&#8202;&#8212;&#8202;we&#8217;re more than happy to help answer questions you might have or get you started.</p><p>&#11088;&#65039; Hamilton on <a href="https://github.com/DAGWorks-Inc/hamilton">GitHub</a></p><p>&#128221; leave us an <a href="https://github.com/DAGWorks-Inc/hamilton/issues">issue</a> if you find something</p><p>Other Hamilton posts you might be interested in:</p><ul><li><p><a href="https://blog.dagworks.io/publish/post/130538397">Hamilton + Airflow</a> (<a href="https://github.com/DAGWorks-Inc/hamilton/tree/main/examples/airflow">GitHub repo</a>)<br></p></li></ul><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;0d35da5e-e9d6-47a1-abf6-76aa22235028&quot;,&quot;caption&quot;:&quot;Introduction&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;From Dev to Prod: a ML Pipeline Reference Post&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:73006291,&quot;name&quot;:&quot;Stefan Krawczyk&quot;,&quot;bio&quot;:&quot;MLOps + Data + LLMOps; creator of https://github.com/dagworks-inc/hamilton.\nFormerly of: Stitch Fix, Idibon, Nextdoor, LinkedIn, HRI, IBM. \nCEO @ DAGWorks - dagworks.io&quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/43b2b624-13e6-44f7-be46-ccedd3246482_3002x3002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-01-02T14:15:30.968Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b26810a-c1c6-429e-a903-5d0b5879194d_1024x1024.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/from-dev-to-prod-a-ml-pipeline-reference&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:140188325,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:7,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;fcc518dc-2215-4c8f-b1ce-c8a416d39abb&quot;,&quot;caption&quot;:&quot;In this post we discuss the inherent tradeoff between moving quickly and (not) breaking things. While it is geared towards those in the data space, it can be read and enjoyed by anyone who writes code or builds systems, and feels that they are constantly under pressure to move quickly. We use the framing of a Data Scientist as someone that works in a se&#8230;&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;How well-structured should your data code be?&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:151994830,&quot;name&quot;:&quot;Elijah ben Izzy&quot;,&quot;bio&quot;:&quot;CTO of DAGWorks, Inc. Co-creator of Hamilton (github.com/dagworks-inc/hamilton).&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06374da8-19cd-418a-bf2a-e5fa5ae2bf6f_375x335.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:73006291,&quot;name&quot;:&quot;Stefan Krawczyk&quot;,&quot;bio&quot;:&quot;MLOps + Data + LLMOps; creator of https://github.com/dagworks-inc/hamilton.\nFormerly of: Stitch Fix, Idibon, Nextdoor, LinkedIn, HRI, IBM. \nCEO @ DAGWorks - dagworks.io&quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/43b2b624-13e6-44f7-be46-ccedd3246482_3002x3002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2024-01-09T14:01:38.235Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/494ed180-8641-4d0f-8e29-e01ee34f2671_582x502.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/how-well-structured-should-your-data&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:140336523,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:8,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;548c5437-a45d-4e9a-a582-b94f720480ca&quot;,&quot;caption&quot;:&quot;In this post, we&#8217;re going to share how Hamilton can help you write modular and maintainable code for your large language model (LLM) application stack. Hamilton is great for describing any type of dataflow, which is exactly what you&#8217;re doing when building an LLM powered application. With Hamilton you get strong&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Building a maintainable and modular LLM application stack with Hamilton&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:153186724,&quot;name&quot;:&quot;Thierry Jean&quot;,&quot;bio&quot;:&quot;Developer Advocate @Hamilton/DAGWorks&quot;,&quot;photo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F21573f95-ad56-4222-9498-9e36d063d6e7_1360x1361.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:73006291,&quot;name&quot;:&quot;Stefan Krawczyk&quot;,&quot;bio&quot;:&quot;MLOps + Data + LLMOps; creator of https://github.com/dagworks-inc/hamilton.\nFormerly of: Stitch Fix, Idibon, Nextdoor, LinkedIn, HRI, IBM. \nCEO @ DAGWorks - dagworks.io&quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/43b2b624-13e6-44f7-be46-ccedd3246482_3002x3002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2023-07-11T15:29:39.841Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed9a9654-fbc4-4b1d-9b39-92b459a91f88_1384x1600.jpeg&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/building-a-maintainable-and-modular&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:133496329,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:4,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[From blog to bot: build a RAG app to chat with your favorite blogs]]></title><description><![CDATA[Step-by-step RAG guide, from data ingestion to production monitoring (Burr, dlt, LanceDB, OpenTelemetry)]]></description><link>https://blog.dagworks.io/p/from-blog-to-bot-build-a-rag-app</link><guid isPermaLink="false">https://blog.dagworks.io/p/from-blog-to-bot-build-a-rag-app</guid><dc:creator><![CDATA[Thierry Jean]]></dc:creator><pubDate>Mon, 09 Sep 2024 13:45:30 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/3ff3efab-7260-4bb2-a7aa-658c0f44f5b7_1456x1048.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Around 41% of Python developers rely on blog articles as a learning resource according to the <a href="https://lp.jetbrains.com/python-developers-survey-2023/">Python Developer Survey 2023 by JetBrains</a>! As a format, blogs are great at delivering up-to-date insights, diverse perspective, and cover niche topics.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fsjp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fsjp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png 424w, https://substackcdn.com/image/fetch/$s_!fsjp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png 848w, https://substackcdn.com/image/fetch/$s_!fsjp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png 1272w, https://substackcdn.com/image/fetch/$s_!fsjp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fsjp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png" width="1350" height="916" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:916,&quot;width&quot;:1350,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fsjp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png 424w, https://substackcdn.com/image/fetch/$s_!fsjp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png 848w, https://substackcdn.com/image/fetch/$s_!fsjp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png 1272w, https://substackcdn.com/image/fetch/$s_!fsjp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F947b18a7-2f28-4256-83d0-784d9fa6d4e0_1350x916.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Results from the Python Developer Survey 2023 by JetBrains</figcaption></figure></div><p>However, the blogs constitute a fragmented ecosystem (blogging platforms, personal websites, company blogs, etc.) which can make it difficult to browse content or find posts you liked.</p><p>To tackle these problems, we&#8217;ll build a personal knowledge base from our favorite blogs and use retrieval augmented generation (RAG) to search through content using a chat interface. We&#8217;ll use a combination of open-source Python tools to progress towards a production-ready application!</p><p><strong>Outline</strong></p><ol><li><p>Ingest blog articles with <code>dlt</code> and <code>LanceDB</code></p></li><li><p>Build a RAG application with <code>Burr</code> and <code>LanceDB</code></p></li><li><p>Monitor a RAG application with <code>OpenTelemetry</code> and <code>Burr UI</code></p></li></ol><blockquote><p>Follow along via the <a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/rag-lancedb-ingestion">GitHub repository</a></p></blockquote><h1><strong>1. Ingest blog articles</strong></h1><p>While blogs are scattered across the web, most of them adhere to the <a href="https://en.wikipedia.org/wiki/RSS">RSS </a>(or the similar <a href="https://en.wikipedia.org/wiki/Atom_(web_standard)">Atom</a>) standard format for publishing and subscribing to content updates. The RSS specifications define required and optional fields to describe the <em>channel</em> and its <em>entries</em> (i.e., the blog website and its articles). Note that even if the fields are standard, how they&#8217;re used and the information they contain can vary greatly between feeds.</p><h2><strong>Finding the RSS feed</strong></h2><p>Even though not many people interact with it directly, an RSS feed is available on most blogging sites, even personal ones built with popular frameworks! If there&#8217;s no visible RSS icon or link, you can find its URL with the browser&#8217;s developer tools. Hit <code>F12</code>, then under the <code>Elements</code> tab, use <code>CTRL + F</code> to access the search bar and look up <code>rss</code>, <code>atom</code>, and <code>feed</code> to try to the RSS link.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-Axm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-Axm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png 424w, https://substackcdn.com/image/fetch/$s_!-Axm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png 848w, https://substackcdn.com/image/fetch/$s_!-Axm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png 1272w, https://substackcdn.com/image/fetch/$s_!-Axm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-Axm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png" width="1456" height="447" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:447,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:995119,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-Axm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png 424w, https://substackcdn.com/image/fetch/$s_!-Axm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png 848w, https://substackcdn.com/image/fetch/$s_!-Axm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png 1272w, https://substackcdn.com/image/fetch/$s_!-Axm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0b785a7-0bbc-41e0-8599-fcf9821d1862_3573x1096.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Searching for the RSS links on the Instacart engineering blog. Two links are found: the company blog and the engineering blog</figcaption></figure></div><p>When you access that link, you&#8217;ll find a not-so-human-friendly XML page. If you&#8217;re lucky, it will have some formatting and interactivity, but it&#8217;s not always the case.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ybSA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ybSA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png 424w, https://substackcdn.com/image/fetch/$s_!ybSA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png 848w, https://substackcdn.com/image/fetch/$s_!ybSA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png 1272w, https://substackcdn.com/image/fetch/$s_!ybSA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ybSA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png" width="1456" height="1060" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e958878-e041-4a7a-a179-73902853b000_1845x1343.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1060,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:258375,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ybSA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png 424w, https://substackcdn.com/image/fetch/$s_!ybSA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png 848w, https://substackcdn.com/image/fetch/$s_!ybSA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png 1272w, https://substackcdn.com/image/fetch/$s_!ybSA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e958878-e041-4a7a-a179-73902853b000_1845x1343.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">RSS feed for the DAGWorks Substack blog</figcaption></figure></div><h2><strong>Retrieving RSS entries using Python</strong></h2><p>Luckily, no need to manually parse XML because the <a href="https://feedparser.readthedocs.io/en/latest/index.html">feedparser</a> library takes care of it! The documentation is also an awesome resource to learn more about the RSS specifications.</p><p>All you need to do is to make an HTTP request to the RSS feed and give the response to the feed parser.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tSeX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tSeX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png 424w, https://substackcdn.com/image/fetch/$s_!tSeX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png 848w, https://substackcdn.com/image/fetch/$s_!tSeX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png 1272w, https://substackcdn.com/image/fetch/$s_!tSeX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tSeX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png" width="1140" height="288" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:288,&quot;width&quot;:1140,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:42919,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tSeX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png 424w, https://substackcdn.com/image/fetch/$s_!tSeX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png 848w, https://substackcdn.com/image/fetch/$s_!tSeX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png 1272w, https://substackcdn.com/image/fetch/$s_!tSeX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d085a35-f306-4d5c-90d4-7337816cc68b_1140x288.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Then, you can use this object to access information about the RSS channel and entries</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h_2I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h_2I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png 424w, https://substackcdn.com/image/fetch/$s_!h_2I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png 848w, https://substackcdn.com/image/fetch/$s_!h_2I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png 1272w, https://substackcdn.com/image/fetch/$s_!h_2I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h_2I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png" width="1140" height="288" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:288,&quot;width&quot;:1140,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43457,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!h_2I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png 424w, https://substackcdn.com/image/fetch/$s_!h_2I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png 848w, https://substackcdn.com/image/fetch/$s_!h_2I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png 1272w, https://substackcdn.com/image/fetch/$s_!h_2I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b458ae8-a317-440e-bc77-4e83c7d8311d_1140x288.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>For this tutorial, we&#8217;ll be using the Substack RSS feed available at <code>my_substack_url.com/feed</code> because each entry&#8217;s field content contains the full HTML page of the blog article. We can actually see it in the <code>&lt;content:encoded&gt;</code> tag from the browser.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oBKK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oBKK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png 424w, https://substackcdn.com/image/fetch/$s_!oBKK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png 848w, https://substackcdn.com/image/fetch/$s_!oBKK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png 1272w, https://substackcdn.com/image/fetch/$s_!oBKK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oBKK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png" width="1456" height="854" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:854,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:285304,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!oBKK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png 424w, https://substackcdn.com/image/fetch/$s_!oBKK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png 848w, https://substackcdn.com/image/fetch/$s_!oBKK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png 1272w, https://substackcdn.com/image/fetch/$s_!oBKK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff324f919-d67f-47c7-bc14-e0acefd3cf15_1827x1071.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Entry from the blog post &#8220;Trace all parts of your Agentic/AI Applications with Burr&#8221;</figcaption></figure></div><p>For blog sites that don&#8217;t include the full HTML, you will have to use the entry&#8217;s <code>link</code> attribute to make another HTTP GET request and retrieve the HTML page.</p><h2><strong>Storing RSS entries in a database</strong></h2><p>Now, we need to decide how to store blogs. The library <a href="https://dlthub.com/">dlt</a>, the &#8220;data load tool&#8221;, makes it trivial to convert a Python dictionary into a table schema and store objects in a database.</p><p>First, we use the <code>@dlt.resource</code> decorator to create a <code>Resource</code> that gets an RSS feed, iterates over available entries, and <code>yield</code> a dictionary per entry.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Rqua!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Rqua!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png 424w, https://substackcdn.com/image/fetch/$s_!Rqua!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png 848w, https://substackcdn.com/image/fetch/$s_!Rqua!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png 1272w, https://substackcdn.com/image/fetch/$s_!Rqua!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Rqua!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png" width="1030" height="478" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:478,&quot;width&quot;:1030,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:69014,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Rqua!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png 424w, https://substackcdn.com/image/fetch/$s_!Rqua!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png 848w, https://substackcdn.com/image/fetch/$s_!Rqua!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png 1272w, https://substackcdn.com/image/fetch/$s_!Rqua!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c45005f-08c0-49a2-a656-4e28b5e980eb_1030x478.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>To ingest data into a LanceDB database, all we need to do is create a <code>Pipeline</code> object with the destination <code>"lancedb"</code> and set a pipeline name. Then, executing the pipeline by passing the <code>rss_entries</code> to the <code>.run()</code> method will create the database and start populating it.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n1sB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n1sB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png 424w, https://substackcdn.com/image/fetch/$s_!n1sB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png 848w, https://substackcdn.com/image/fetch/$s_!n1sB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png 1272w, https://substackcdn.com/image/fetch/$s_!n1sB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!n1sB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png" width="1410" height="212" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:212,&quot;width&quot;:1410,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:40483,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!n1sB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png 424w, https://substackcdn.com/image/fetch/$s_!n1sB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png 848w, https://substackcdn.com/image/fetch/$s_!n1sB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png 1272w, https://substackcdn.com/image/fetch/$s_!n1sB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe35e617e-38b9-46c1-85f1-da288c7502f7_1410x212.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Simply change the URL given to the function <code>rss_entries(rss_feed_url=)</code> in order to ingest other blogs!</p><h2><strong>Text processing for RAG</strong></h2><p>So far, we stored large HTML blobs. To create a good RAG application, we also need to clean the text and create right-sized chunks to provide meaningful information to the LLM. For this purpose, we create simple functions <code>cleanup_html()</code>, <code>split_text()</code>, and <code>contextualize()</code>. They respectively remove tags from an HTML string, split the text on punctuation (<code>. ! ?</code>), and uses a rolling window to join chunks into larger windows. Having <em>some</em> overlap between chunks is helpful during retrieval.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Tflv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Tflv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png 424w, https://substackcdn.com/image/fetch/$s_!Tflv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png 848w, https://substackcdn.com/image/fetch/$s_!Tflv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png 1272w, https://substackcdn.com/image/fetch/$s_!Tflv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Tflv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png" width="1306" height="1238" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1238,&quot;width&quot;:1306,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:214582,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Tflv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png 424w, https://substackcdn.com/image/fetch/$s_!Tflv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png 848w, https://substackcdn.com/image/fetch/$s_!Tflv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png 1272w, https://substackcdn.com/image/fetch/$s_!Tflv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58f1d0b1-aca4-4f3b-bb2a-485abcd252c4_1306x1238.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><blockquote><p>Note that you can use any text processing library for this step (unstructured, LlamaIndex, LangChain, etc.)</p></blockquote><p>To apply these transformations, we create a simple function <code>text_chunks()</code> with the <code>@dlt.transformer</code>. It takes in an RSS entry produced by the <code>rss_entries</code> resource and yields &#8220;contextualized&#8221; chunks from the entry.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!39oh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!39oh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png 424w, https://substackcdn.com/image/fetch/$s_!39oh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png 848w, https://substackcdn.com/image/fetch/$s_!39oh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png 1272w, https://substackcdn.com/image/fetch/$s_!39oh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!39oh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png" width="1358" height="402" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:402,&quot;width&quot;:1358,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:82976,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!39oh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png 424w, https://substackcdn.com/image/fetch/$s_!39oh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png 848w, https://substackcdn.com/image/fetch/$s_!39oh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png 1272w, https://substackcdn.com/image/fetch/$s_!39oh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f8d3b92-2a14-43a9-9c20-6aa60ff93b64_1358x402.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Compared to the earlier code, we use the pipe operator <code>|</code> to indicate that the data from <code>rss_entries</code> should flow into the <code>text_chunks</code> transform step.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VAAZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VAAZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png 424w, https://substackcdn.com/image/fetch/$s_!VAAZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png 848w, https://substackcdn.com/image/fetch/$s_!VAAZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png 1272w, https://substackcdn.com/image/fetch/$s_!VAAZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VAAZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png" width="1272" height="212" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6c947488-67b1-496d-a300-37593d55763b_1272x212.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:212,&quot;width&quot;:1272,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:26002,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!VAAZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png 424w, https://substackcdn.com/image/fetch/$s_!VAAZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png 848w, https://substackcdn.com/image/fetch/$s_!VAAZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png 1272w, https://substackcdn.com/image/fetch/$s_!VAAZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c947488-67b1-496d-a300-37593d55763b_1272x212.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h2><strong>Embedding text and storing vectors</strong></h2><p>An embedding is a vector representation of a text string. For RAG, we want to store each text chunk with its vector representation to enable <em>vector search</em> (also called <em>semantic</em> or <em>similarity</em> search). When the user asks a question our application, we&#8217;ll embed its query (i.e., create a vector), search for nearby vectors, and retrieve their associated text chunk.</p><p>For this purpose, we&#8217;ll use the vector database LanceDB. One key feature is the ability to delegate it the responsibility to compute embeddings. This simplifies RAG applications because it avoids having to write code to generate vectors and move them around. Other benefits will become apparent in the section <strong>2. Build a RAG application</strong>. Also, the <a href="https://dlthub.com/devel/dlt-ecosystem/destinations/lancedb">LanceDB + dlt integration</a> means we can embed our text chunks at ingestion with a single line of code.</p><p>Compared to the previous snippets, we give the <code>rss_entries(...) | text_chunks</code> object to the <code>lancedb_adapter</code> an specify to embed the field <code>text</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xNo0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xNo0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png 424w, https://substackcdn.com/image/fetch/$s_!xNo0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png 848w, https://substackcdn.com/image/fetch/$s_!xNo0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png 1272w, https://substackcdn.com/image/fetch/$s_!xNo0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xNo0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png" width="1254" height="402" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:402,&quot;width&quot;:1254,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:52701,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xNo0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png 424w, https://substackcdn.com/image/fetch/$s_!xNo0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png 848w, https://substackcdn.com/image/fetch/$s_!xNo0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png 1272w, https://substackcdn.com/image/fetch/$s_!xNo0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9c9af2f-0fab-4a33-8b6f-41fa3d8e25cc_1254x402.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><blockquote><p>Note that LanceDB + dlt will require a <a href="https://dlthub.com/devel/dlt-ecosystem/destinations/lancedb">few lines of configurations</a> to specify which embedding provider and model to use, and the necessary API keys.</p></blockquote><h2><strong>Next steps: Scheduling data ingestion</strong></h2><p>Next step would be to deploy and schedule the dlt pipeline to run every day. While this sound daunting, <code>dlt</code> has a <a href="https://dlthub.com/docs/walkthroughs/deploy-a-pipeline/deploy-with-github-actions">straightforward walkthrough</a> in their documentation. Also, the support for <a href="https://dlthub.com/docs/general-usage/incremental-loading">incremental loading</a> means it can automatically avoid ingesting the same document multiple time and wasting API calls for embeddings, which can be costly at scale. We leave this exercise to the reader!</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Subscribe to the DAGWorks Substack to learn more about LLM and ML engineering</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h1><strong>2. Build a RAG application</strong></h1><p>&#8220;Retrieval augmented generation&#8221; is a set of techniques rather than a specific algorithm. Burr is a framework to write the logic of RAG applications, and LLM agents more generally, as a graph. By using the concepts of <code>action</code> and <code>state</code>, the behavior of complex agents can always be visualized and debugging becomes easier.</p><p>Burr also solves many challenges to productionize agents including monitoring, storing interactions, streaming, and more, and comes with a rich open-source UI for observability (see <strong>3. Monitor a RAG application</strong>).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2WQc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2WQc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png 424w, https://substackcdn.com/image/fetch/$s_!2WQc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png 848w, https://substackcdn.com/image/fetch/$s_!2WQc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png 1272w, https://substackcdn.com/image/fetch/$s_!2WQc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2WQc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png" width="846" height="584" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:584,&quot;width&quot;:846,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2WQc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png 424w, https://substackcdn.com/image/fetch/$s_!2WQc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png 848w, https://substackcdn.com/image/fetch/$s_!2WQc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png 1272w, https://substackcdn.com/image/fetch/$s_!2WQc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F398c2aae-7d59-4cd9-a906-9db00ef65715_846x584.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Graph of an example Burr chatbot</figcaption></figure></div><h2><strong>Writing RAG logic</strong></h2><p>For this tutorial, we&#8217;ll write a simple chatbot that receives a user query, retrieves relevant blog chunks, and returns an LLM-generated answer.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BVaU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BVaU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png 424w, https://substackcdn.com/image/fetch/$s_!BVaU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png 848w, https://substackcdn.com/image/fetch/$s_!BVaU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png 1272w, https://substackcdn.com/image/fetch/$s_!BVaU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BVaU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png" width="267" height="236" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a95db717-ebdf-479f-8e37-884d2a57f716_267x236.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:236,&quot;width&quot;:267,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BVaU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png 424w, https://substackcdn.com/image/fetch/$s_!BVaU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png 848w, https://substackcdn.com/image/fetch/$s_!BVaU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png 1272w, https://substackcdn.com/image/fetch/$s_!BVaU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa95db717-ebdf-479f-8e37-884d2a57f716_267x236.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Visualizing the Burr RAG chatbot</figcaption></figure></div><p>To define actions, we use the <code>@action</code> decorator, which specifies the values it <code>reads</code> from and <code>writes</code> to the <code>State</code>. Also, the function must take a <code>State</code> as the first argument and return a <code>State</code> object.</p><p>The action <code>relevant_chunk_retrieval()</code> takes in a text input <code>user_query</code>, searches for most relevant chunks, and updates the state with the retrieved chunks and user query. Notice how simple the LanceDB code is. The embedding for the user&#8217;s query is automatically computed and used for similarity search.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fBpG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fBpG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png 424w, https://substackcdn.com/image/fetch/$s_!fBpG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png 848w, https://substackcdn.com/image/fetch/$s_!fBpG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png 1272w, https://substackcdn.com/image/fetch/$s_!fBpG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fBpG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png" width="1456" height="1145" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1145,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:230220,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fBpG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png 424w, https://substackcdn.com/image/fetch/$s_!fBpG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png 848w, https://substackcdn.com/image/fetch/$s_!fBpG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png 1272w, https://substackcdn.com/image/fetch/$s_!fBpG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa645e772-8b9f-443a-88c2-04549b7349af_1478x1162.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The second action <code>bot_turn()</code> uses the OpenAI Python client to send a chat completion request to <code>gpt-4o-mini</code>. The key element of RAG is including the relevant chunks of information in the prompt sent to the LLM. Using Burr makes very clear how data moves through the application and the observability features allow to inspect in detail each step (see <strong>3. Monitor a RAG application</strong>).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r5kU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r5kU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png 424w, https://substackcdn.com/image/fetch/$s_!r5kU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png 848w, https://substackcdn.com/image/fetch/$s_!r5kU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png 1272w, https://substackcdn.com/image/fetch/$s_!r5kU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r5kU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png" width="1456" height="1092" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1092,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:284303,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!r5kU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png 424w, https://substackcdn.com/image/fetch/$s_!r5kU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png 848w, https://substackcdn.com/image/fetch/$s_!r5kU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png 1272w, https://substackcdn.com/image/fetch/$s_!r5kU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F879c7360-0e45-4bd3-b13f-a2498ae21c64_1702x1276.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2><strong>Assembling the RAG application</strong></h2><p>To build a Burr <code>Application</code>, you need to pass it actions and define valid transitions as tuples <code>(from, to)</code>. The application must also define an <code>entrypoint</code> from where to begin execution. In this case, the RAG chatbot can only go from <code>relevant_chunk_retrieval -&gt; bot_turn</code> and <code>bot_turn -&gt; relevant_chunk_retrieval</code>. Finally, calling the <code>.build()</code> method on the <code>ApplicationBuilder()</code> will return the <code>Application</code> object.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!o6-Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!o6-Z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png 424w, https://substackcdn.com/image/fetch/$s_!o6-Z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png 848w, https://substackcdn.com/image/fetch/$s_!o6-Z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png 1272w, https://substackcdn.com/image/fetch/$s_!o6-Z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!o6-Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png" width="1098" height="554" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:554,&quot;width&quot;:1098,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:76698,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!o6-Z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png 424w, https://substackcdn.com/image/fetch/$s_!o6-Z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png 848w, https://substackcdn.com/image/fetch/$s_!o6-Z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png 1272w, https://substackcdn.com/image/fetch/$s_!o6-Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e49ce4e-67a4-415e-92c9-bf1d992140ef_1098x554.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2><strong>Launching the RAG application</strong></h2><p>Since a Burr <code>Application</code> is a simple Python object, you can launch and try it from a notebook or a script during development <a href="https://burr.dagworks.io/concepts/state-machine/#running">one of these options</a>:</p><ul><li><p><code>.run(...)</code> will execute the application until it hits a specific condition</p></li><li><p><code>.iterate(...)</code> allows you to execute it in a <code>for</code> loop where you can manually handle conditions</p></li><li><p><code>.step(...)</code> will execute a single action and wait for further instructions (great for debugging)</p></li></ul><blockquote><p>Note there exists <code>async</code> alternatives <code>.arun()</code>, <code>.aiterate()</code>, <code>.astep()</code></p></blockquote><p>Below, we launch the application with <code>.run()</code> and make it halt after the action <code>bot_turn</code>. We must provide a dictionary of <code>inputs</code> that includes a value for <code>user_query</code> since it&#8217;s required by the <code>relevant_chunk_retrieval</code> action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!s_94!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!s_94!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png 424w, https://substackcdn.com/image/fetch/$s_!s_94!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png 848w, https://substackcdn.com/image/fetch/$s_!s_94!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png 1272w, https://substackcdn.com/image/fetch/$s_!s_94!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!s_94!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png" width="1012" height="516" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:516,&quot;width&quot;:1012,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:66103,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!s_94!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png 424w, https://substackcdn.com/image/fetch/$s_!s_94!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png 848w, https://substackcdn.com/image/fetch/$s_!s_94!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png 1272w, https://substackcdn.com/image/fetch/$s_!s_94!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3beca1fa-87e7-466b-9ee0-be99656ca500_1012x516.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This will complete one loop <code>user_query -&gt; relevant_chunk_retrieval -&gt; bot_turn</code> and return a <code>state</code> object that contains the <code>chat_history</code> with the chatbot&#8217;s reply.</p><p>Now, converting this to an &#8220;open-ended&#8221; conversation is trivial! All you need is a <code>while</code> loop to call <code>application.run(...)</code> multiple times. Make sure to have a mechanism to exit the loop (&#128517;) and to provide a new <code>user_query</code> on each iteration (here, we get a new input at the end of the loop)</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!x25Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!x25Z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png 424w, https://substackcdn.com/image/fetch/$s_!x25Z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png 848w, https://substackcdn.com/image/fetch/$s_!x25Z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png 1272w, https://substackcdn.com/image/fetch/$s_!x25Z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!x25Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png" width="1356" height="782" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:782,&quot;width&quot;:1356,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:130665,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!x25Z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png 424w, https://substackcdn.com/image/fetch/$s_!x25Z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png 848w, https://substackcdn.com/image/fetch/$s_!x25Z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png 1272w, https://substackcdn.com/image/fetch/$s_!x25Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F550b1b6a-cb81-4862-96a0-f01a44a8610d_1356x782.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2><strong>Next steps: deploying Burr as a web service</strong></h2><p>As you&#8217;ve seen, writing an application with Burr is a matter of defining <code>action</code> and <code>state</code>. It makes developing reliable RAG and LLM agents with predictable and debuggable behaviors much simpler.</p><p>Yet, Burr provides also provides a lot of value when it comes to moving your application to production. Via the <code>ApplicationBuilder</code>, it is possible to add many functionalities:</p><ul><li><p>track execution and gather telemetry (which we cover next)</p></li><li><p>persist the state, allowing to resume later</p></li><li><p>hooks to send alert and trigger other systems</p></li></ul><p>A next step for the reader would be to deploy the Burr <code>Application</code> as a web service accessible to other users. Here&#8217;s a guide on this topic from the <a href="https://burr.dagworks.io/examples/deployment/web-server/">official Burr documentation</a>.</p><h1><strong>3. Monitor a RAG application</strong></h1><p>This simple RAG application already involves multiple components (agent, vector store, LLM, user interface) and this number could grow (multiple LLMs, caching, routers, web searches). An <em>observable</em> RAG system should help you answer questions about:</p><ul><li><p>User behavior patterns (frequent topics, difficult queries)</p></li><li><p>Application performance (guardrails, LLM randomness, user ratings)</p></li><li><p>System performance (latency, throughput, resource usage, API calls)</p></li><li><p>System errors (bugs from code or the interaction between code and data)</p></li></ul><h2><strong>Instrumentation with OpenTelemetry</strong></h2><p><a href="https://opentelemetry.io/">OpenTelemetry</a> is an open-source cross-language tool that allows to instrument, generate, collect, and export telemetry data (metrics, logs, traces), and constitute an industry-recognized standard (<a href="https://github.com/magsther/awesome-opentelemetry">learn more</a>).</p><p>Once you enable OpenTelemetry, you need to <em>instrument</em> your code, which means patching your code to produce and report telemetry. Then, <em>auto-instrumentation</em> refers to adding a few lines of code to fully instrument a library. The Python open-source community implemented <a href="https://opentelemetry-python-contrib.readthedocs.io/en/latest/">auto-instrumentation for many popular libraries</a>.</p><p>For example, add these 2 lines of code to instrument the <code>requests</code> library:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zlDX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zlDX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png 424w, https://substackcdn.com/image/fetch/$s_!zlDX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png 848w, https://substackcdn.com/image/fetch/$s_!zlDX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png 1272w, https://substackcdn.com/image/fetch/$s_!zlDX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zlDX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png" width="1392" height="326" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:326,&quot;width&quot;:1392,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:55101,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!zlDX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png 424w, https://substackcdn.com/image/fetch/$s_!zlDX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png 848w, https://substackcdn.com/image/fetch/$s_!zlDX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png 1272w, https://substackcdn.com/image/fetch/$s_!zlDX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2998daf-376a-45e2-9ae6-54872ecfbce0_1392x326.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><a href="https://github.com/traceloop/openllmetry">OpenLLMetry</a> is an open-source Python library that automatically instruments with OpenTelemetry components of your LLM stack including LLM providers (OpenAI, Anthropic, HuggingFace, Cohere, etc.), vector databases (Weaviate, Qdrant, Chroma, etc.), and frameworks (<a href="https://github.com/dagworks-inc/burr">Burr</a>, Haystack, LangChain, LlamaIndex). Concretely, it means you automatically get detailed traces of API calls, retrieval operations, or text transformations for example.</p><h2><strong>Monitor your application with Burr UI</strong></h2><p>OpenTelemetry is a middleware, meaning it generates data, but doesn&#8217;t provide a storage or dashboard. When using Burr, it can automatically track and store OpenTelemetry data for you, but you can also set up your own <a href="https://opentelemetry.io/ecosystem/vendors/">OpenTelemetry destination</a>.</p><p>To do so, simply add the clause <code>.with_tracker(use_otel_tracing=True)</code> to the <code>ApplicationBuilder</code>. Below, we also instrument the <code>lancedb</code> and the <code>openai</code> libraries used by our RAG application.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gfZF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gfZF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png 424w, https://substackcdn.com/image/fetch/$s_!gfZF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png 848w, https://substackcdn.com/image/fetch/$s_!gfZF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png 1272w, https://substackcdn.com/image/fetch/$s_!gfZF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gfZF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png" width="1340" height="706" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:706,&quot;width&quot;:1340,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:117019,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gfZF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png 424w, https://substackcdn.com/image/fetch/$s_!gfZF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png 848w, https://substackcdn.com/image/fetch/$s_!gfZF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png 1272w, https://substackcdn.com/image/fetch/$s_!gfZF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0d7a792-4a52-4b04-871c-9823b89b250b_1340x706.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Afterwards, launching and using the <code>Application</code> will generate telemetry for Burr to track. Then, using the command <code>burr</code> in your terminal will launch the Burr UI!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Elqx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Elqx!,w_424,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif 424w, https://substackcdn.com/image/fetch/$s_!Elqx!,w_848,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif 848w, https://substackcdn.com/image/fetch/$s_!Elqx!,w_1272,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif 1272w, https://substackcdn.com/image/fetch/$s_!Elqx!,w_1456,c_limit,f_webp,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Elqx!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif" width="1031" height="862" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:862,&quot;width&quot;:1031,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Elqx!,w_424,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif 424w, https://substackcdn.com/image/fetch/$s_!Elqx!,w_848,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif 848w, https://substackcdn.com/image/fetch/$s_!Elqx!,w_1272,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif 1272w, https://substackcdn.com/image/fetch/$s_!Elqx!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc35087e4-4937-41cc-89da-db07d3e0b81f_1031x862.gif 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Burr UI showing RAG telemetry with LanceDB and OpenAI instrumentation</figcaption></figure></div><p>Importantly, it allows us to observe our RAG application and precisely track the user requests, the retrieved chunks, the generated responses, etc. The Burr UI is continually improving and has many more features, including:</p><ul><li><p>monitor execution in real time, see it move through states</p></li><li><p>track attributes such as token counts, latency,</p></li><li><p>inspect code code failures</p></li><li><p>create test fixtures from specific states with one click</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8A1I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8A1I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png 424w, https://substackcdn.com/image/fetch/$s_!8A1I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png 848w, https://substackcdn.com/image/fetch/$s_!8A1I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png 1272w, https://substackcdn.com/image/fetch/$s_!8A1I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8A1I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png" width="1384" height="810" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:810,&quot;width&quot;:1384,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8A1I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png 424w, https://substackcdn.com/image/fetch/$s_!8A1I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png 848w, https://substackcdn.com/image/fetch/$s_!8A1I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png 1272w, https://substackcdn.com/image/fetch/$s_!8A1I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd3d66b34-19e5-4954-a57f-768737929f4d_1384x810.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Burr UI showing the number of prompt tokens of a RAG request to OpenAI</figcaption></figure></div><h1><strong>Conclusion</strong></h1><p>This blog showed how to kickstart an observable Retrieval-Augmented Generation application over blog articles. Building towards production-readiness, Sections <strong>1. </strong>and <strong>2. </strong>include next steps to schedule data ingestion and deploy your RAG application via a web service!</p><h2>More Resources</h2><ul><li><p>Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a> for help or if you have questions!</p></li><li><p><a href="http://github.com/dagworks-inc/burr">Github repository for Burr</a> (give us a star if you like what you see!)</p></li><li><p><a href="https://opentelemetry.io/">OpenTelemetry</a></p></li><li><p><a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/streaming-fastapi">Example + README</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[OS Libraries Building on Hamilton]]></title><description><![CDATA[An overview of recent libraries that are built on top of/for Hamilton]]></description><link>https://blog.dagworks.io/p/os-libraries-building-on-hamilton</link><guid isPermaLink="false">https://blog.dagworks.io/p/os-libraries-building-on-hamilton</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Fri, 06 Sep 2024 13:31:09 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Q1CW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Let&#8217;s take a step back to reflect. When we open-sourced <a href="http://github.com/dagworks-inc/burr">Hamilton</a>, we did not really know what to expect. All we thought was that people would find it valuable. While we were right about that, the deluge of innovative new use-cases, feature requests, publicity, etc&#8230; that followed completely blew us away. In this post we&#8217;re going to be talking about a few of the recent additions to the Hamilton ecosystem from our community.</p><p>First, however, let&#8217;s go over the basics of Hamilton.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe to access the latests posts.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h1>Hamilton</h1><p>Hamilton is a lightweight python library for building <em>dataflows</em> (any computation requiring data) out of python functions. It can run wherever Python does, and is widely used for anything from simple statistical modeling (this post) to more complex ML, to online RAG in web services and more complex ingestion pipelines for AI systems.</p><p>The core concept is&nbsp;simple &#8211; you write each data transformation step as a single Python function, with the following rules:</p><ol><li><p>The name of the function corresponds to the output variable it computes.</p></li><li><p>The parameter names (and types) correspond to inputs. These can be either passed-in parameters or names of other upstream functions.</p></li></ol><p>This approach allows you to represent your data in ways that correspond closely to code, are naturally self-documenting, and portable across infrastructure.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q1CW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q1CW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 424w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 848w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 1272w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png" width="1456" height="832" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:832,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Q1CW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 424w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 848w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 1272w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>After writing your functions (assets), you write a driver that executes them &#8211; in most cases this is a simple import/run (specifying the assets you want computed and letting the framework do the rest), but it provides options to customize execution:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HYEh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HYEh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 424w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 848w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 1272w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HYEh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png" width="1450" height="434" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:434,&quot;width&quot;:1450,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165972,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!HYEh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 424w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 848w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 1272w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/c5f46a612bf498d3100936b84d693ea3#file-hamilton_1-py">gist</a></figcaption></figure></div><p>Hamilton has a <a href="https://hamilton.dagworks.io/en/latest/how-tos/use-in-jupyter-notebook/">notebook integration</a> that we&#8217;ll be using in our post, allowing you to define your modules in a cell and reference them in drivers later. You can do this with the <code>%%cell_to_module</code> command, which will update a variable with a module pointer and plot the dataflow defined by the module.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HJ9w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HJ9w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 424w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 848w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 1272w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png" width="1438" height="428" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:428,&quot;width&quot;:1438,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:153080,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!HJ9w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 424w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 848w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 1272w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/5453a717e2807ce592cc11ba1cfd1148#file-cell_to_module-py">gist</a></figcaption></figure></div><p>Once you define your module, you will have access to the module pointer as a variable with the name of the module, allowing you to build the driver, just as we did above. See <a href="https://medium.com/@thijean/the-perks-of-creating-dataflows-with-hamilton-36e8c56dd2a">this post</a> for more information on how the integration works.</p><h2>Ecosystem Additions</h2><h3>Hypster + Hypernodes</h3><p><span class="mention-wrap" data-attrs="{&quot;name&quot;:&quot;Gilad Rubin&quot;,&quot;id&quot;:25322884,&quot;type&quot;:&quot;user&quot;,&quot;url&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e74e235-456f-47ff-96d8-cb7285eb4a65_96x96.jpeg&quot;,&quot;uuid&quot;:&quot;291d84a8-547c-406c-a458-7c3e27471eeb&quot;}" data-component-name="MentionToDOM"></span> recently open-sourced his library <a href="https://github.com/gilad-rubin/hypster">hypster</a> &#8212; a lightweight configuration system for interacting with, iterating on, and managing AI/ML workflows. Together with <a href="https://github.com/gilad-rubin/hypernodes">Hypernodes</a>, these form a <em>frontend</em> of sorts for Hamilton &#8212; enabling quick iteration + narrowing the dev &#8594; prod gap. While it is independent of Hamilton, it draws from the same concepts and can be used to configure/manage Hamilton DAGs. Hypernodes, while still in early days, allows you to use Hamilton DAGs within Hypster configurations. He recently talked at the Hamilton community meetup about his work &#8212; sharing how he used these tools to build and iterate on a powerful, extensible RAG Q/A system. Have a listen &#8212; there&#8217;s a lot to learn! He&#8217;s really paving the way on leveraging hierarchical DAGs (hamilton DAGs as black-box steps in his pipeline) to lower cognitive burden in developing complex workflows.</p><div id="youtube2-3LREcaewZbo" class="youtube-wrap" data-attrs="{&quot;videoId&quot;:&quot;3LREcaewZbo&quot;,&quot;startTime&quot;:null,&quot;endTime&quot;:null}" data-component-name="Youtube2ToDOM"><div class="youtube-inner"><iframe src="https://www.youtube-nocookie.com/embed/3LREcaewZbo?rel=0&amp;autoplay=0&amp;showinfo=0&amp;enablejsapi=0" frameborder="0" loading="lazy" gesture="media" allow="autoplay; fullscreen" allowautoplay="true" allowfullscreen="true" width="728" height="409"></iframe></div></div><p>Gilad writes about the philosophy behind these libraries and more in his recent post <em>5 Pillars for a Hyper-Optimized AI Workflow</em>.</p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:148447976,&quot;url&quot;:&quot;https://giladrubin.substack.com/p/5-pillars-for-a-hyper-optimized-ai&quot;,&quot;publication_id&quot;:2060529,&quot;publication_name&quot;:&quot;Gilad&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b219523-d1ed-4b87-a4c4-bb7947978f8e_1191x1191.png&quot;,&quot;title&quot;:&quot;5 Pillars for a Hyper-Optimized AI Workflow&quot;,&quot;truncated_body_text&quot;:&quot;Intro In the last decade, I carried with me a deep question in the back of my mind in every project I've worked on: &#8220;How (the hell) am I supposed to structure and develop my AI &amp; ML projects?&#8221;&quot;,&quot;date&quot;:&quot;2024-09-03T16:47:02.367Z&quot;,&quot;like_count&quot;:3,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:25322884,&quot;name&quot;:&quot;Gilad Rubin&quot;,&quot;handle&quot;:&quot;giladrubin&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4e74e235-456f-47ff-96d8-cb7285eb4a65_96x96.jpeg&quot;,&quot;bio&quot;:null,&quot;profile_set_up_at&quot;:&quot;2023-10-26T14:16:41.607Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:2062381,&quot;user_id&quot;:25322884,&quot;publication_id&quot;:2060529,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:2060529,&quot;name&quot;:&quot;Gilad&#8217;s Substack&quot;,&quot;subdomain&quot;:&quot;giladrubin&quot;,&quot;custom_domain&quot;:null,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;My personal Substack&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b219523-d1ed-4b87-a4c4-bb7947978f8e_1191x1191.png&quot;,&quot;author_id&quot;:25322884,&quot;theme_var_background_pop&quot;:&quot;#FF9900&quot;,&quot;created_at&quot;:&quot;2023-10-26T14:16:43.998Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;Gilad Rubin&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;disabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false,&quot;is_personal_mode&quot;:false}}],&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://giladrubin.substack.com/p/5-pillars-for-a-hyper-optimized-ai?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!oH0Y!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b219523-d1ed-4b87-a4c4-bb7947978f8e_1191x1191.png" loading="lazy"><span class="embedded-post-publication-name">Gilad&#8217;s Substack</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">5 Pillars for a Hyper-Optimized AI Workflow</div></div><div class="embedded-post-body">Intro In the last decade, I carried with me a deep question in the back of my mind in every project I've worked on: &#8220;How (the hell) am I supposed to structure and develop my AI &amp; ML projects&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">2 years ago &#183; 3 likes &#183; Gilad Rubin</div></a></div><h3>Flower Power</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pbGb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pbGb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png 424w, https://substackcdn.com/image/fetch/$s_!pbGb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png 848w, https://substackcdn.com/image/fetch/$s_!pbGb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png 1272w, https://substackcdn.com/image/fetch/$s_!pbGb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pbGb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png" width="1024" height="499" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:499,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1292859,&quot;alt&quot;:&quot;Bild&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Bild" title="Bild" srcset="https://substackcdn.com/image/fetch/$s_!pbGb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png 424w, https://substackcdn.com/image/fetch/$s_!pbGb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png 848w, https://substackcdn.com/image/fetch/$s_!pbGb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png 1272w, https://substackcdn.com/image/fetch/$s_!pbGb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc593cd4-e325-4fbc-ba22-da608db71b5a_1024x499.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Flower-power logo!</figcaption></figure></div><p><a href="https://www.linkedin.com/in/volker-lorrmann-61b923162/?lipi=urn%3Ali%3Apage%3Ad_flagship3_search_srp_all%3BgsS%2F9KtISbq0uTzSD%2FsAeA%3D%3D">Volker Lorrmann</a> released <a href="https://github.com/legout/flowerpower">FlowerPower</a>, an lightweight orchestration library built to run Hamilton workflows! It leverages <a href="https://github.com/agronholm/apscheduler">APScheduler</a> to run Hamilton workflows, allowing you to configure Hamilton workflows and launch/run them on a cadence! Together with the Hamilton UI you can now run, track, and iterate on your pipelines in a distributed setting.</p><h3>Wren AI</h3><p>Wren AI is leveraging Hamilton + Async mode to power their core product. You can read their original post on how they used Hamilton to scale through 1500+ concurrent requests <a href="https://blog.getwren.ai/how-do-we-rewrite-wren-ai-llm-service-to-support-1500-concurrent-users-online-9ba5c121afc3">here</a>, and our co-post with them on new async features + async upgrades: </p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;753c3c16-2e41-4523-a872-31e78677686d&quot;,&quot;caption&quot;:&quot;Wren AI + Hamilton&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;lg&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Async Dataflows in Hamilton&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:151994830,&quot;name&quot;:&quot;Elijah ben Izzy&quot;,&quot;bio&quot;:&quot;CTO of DAGWorks, Inc. Co-creator of Hamilton (github.com/dagworks-inc/hamilton).&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06374da8-19cd-418a-bf2a-e5fa5ae2bf6f_375x335.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:141841981,&quot;name&quot;:&quot;DAGWorks Inc.&quot;,&quot;bio&quot;:&quot;DAGWorks Inc. substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:49140497,&quot;name&quot;:&quot;Howard&quot;,&quot;bio&quot;:&quot;Startup co-founder &amp; CEO @ Canner.  I share my random thoughts and notes on Substack.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/82f05c89-6569-47c0-a98d-531ed8cdc539_980x951.jpeg&quot;,&quot;is_guest&quot;:true,&quot;bestseller_tier&quot;:null,&quot;primaryPublicationSubscribeUrl&quot;:&quot;https://chilijung.com/subscribe?&quot;,&quot;primaryPublicationUrl&quot;:&quot;https://chilijung.com&quot;,&quot;primaryPublicationName&quot;:&quot;Howard's Newsletter&quot;,&quot;primaryPublicationId&quot;:356680}],&quot;post_date&quot;:&quot;2024-07-08T22:32:26.374Z&quot;,&quot;cover_image&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0afdebc8-09ec-4e27-8745-3fd142970da2_775x591.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://blog.dagworks.io/p/async-dataflows-in-hamilton&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:146324821,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:4,&quot;comment_count&quot;:0,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;DAGWorks&#8217;s Substack&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6e8acf7f-c494-41c8-9a7a-6dd4f4fff88f_2083x2083.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p>We&#8217;re really excited about this &#8212; while there are a lot of new text-to-SQL tools out there, Wren&#8217;s OS implementation is rising above the rest!</p><h3>DSP Decision Engine</h3><p>Capitec open-sourced their decision engine library, <a href="https://github.com/capitec/dsp-decision-engine">spockflow</a> &#8212; meant to make automating decision trees easy and traceable. They built it using Hamilton for traceability, creating both custom decorators *and* wrapping Hamilton execution/visibility.  </p><p>Specifying and executing decision engines is easy with the <code>@Tree.condition </code>decorator, which dynamically constructs a Hamilton DAG representing a decision tree:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!bF2I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!bF2I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png 424w, https://substackcdn.com/image/fetch/$s_!bF2I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png 848w, https://substackcdn.com/image/fetch/$s_!bF2I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png 1272w, https://substackcdn.com/image/fetch/$s_!bF2I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!bF2I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png" width="1456" height="946" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:946,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:208729,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!bF2I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png 424w, https://substackcdn.com/image/fetch/$s_!bF2I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png 848w, https://substackcdn.com/image/fetch/$s_!bF2I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png 1272w, https://substackcdn.com/image/fetch/$s_!bF2I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffb353a6e-5b00-48fe-af57-129048fadb64_1822x1184.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You can get started using the library by visiting their repository.</p><h3>NaturF Model</h3><p>Researchers out of Oak Ridge National Laboratory and Pacific Northwest National Laboratory published the NaturF (Neighborhood Adaptive Tissues for Urban Resilience Futures) model in the Journal of Open Source Software (JOSS). This is a 132 building parameter model that uses building topology to measure the impact of existing/proposed developments on urban microclimates. NaturF produces parameters the the <a href="https://github.com/wrf-model/WRF">WRF (weather research forecast)</a> model can ingest.</p><p>Under the hood, NaturF leverages Hamilton to compute the parameters &#8212; this makes it easier to visualize, trace/debug, and recompute specific portions of the DAG. You can see the graph that produces parameters here &#8212; it&#8217;s part of the paper!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!o1pV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!o1pV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png 424w, https://substackcdn.com/image/fetch/$s_!o1pV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png 848w, https://substackcdn.com/image/fetch/$s_!o1pV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png 1272w, https://substackcdn.com/image/fetch/$s_!o1pV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!o1pV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png" width="1456" height="458" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:458,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:161787,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!o1pV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png 424w, https://substackcdn.com/image/fetch/$s_!o1pV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png 848w, https://substackcdn.com/image/fetch/$s_!o1pV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png 1272w, https://substackcdn.com/image/fetch/$s_!o1pV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa782189d-5651-4ea3-95fc-139bee2575a1_1512x476.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You can read through the documentation <a href="https://immm-sfa.github.io/naturf/user_guide.html">here</a>. NaturF also uses <a href="https://github.com/geopandas/geopandas">GeoPandas</a> to run geographic computation in addition to the <a href="https://github.com/DAGWorks-Inc/hamilton/blob/004ac5e4efd8aefa45a1888b3c2df375f2843370/hamilton/plugins/geopandas_extensions.py">geopandas extension for Hamilton</a>.</p><h1>And more&#8230;</h1><p>Along with the all the exiting libraries outlined above, we are constantly accepting user contributions, promoting blog posts, and sharing out new libraries &#8212; reach out if you have/want to build on top of Hamilton!</p><h1>We want to hear from you!</h1><p>If you&#8217;re excited by any of this, or have strong opinions, drop by our Slack channel / leave some comments here! Some resources to help you get started:</p><p>&#128227; <a href="https://join.slack.com/t/hamilton-opensource/shared_invite/zt-1bjs72asx-wcUTgH7q7QX1igiQ5bbdcg">join our Hamilton community on Slack</a>&#8202;&#8212;&#8202;need help with Hamilton? Ask here.</p><p>&#11088; <a href="https://github.com/dagworks-inc/hamilton">give Hamilton a star on github</a></p><p>&#128221; <a href="https://github.com/DAGWorks-Inc/hamilton/issues">open an issue if you find any bugs/want new features</a></p><p>We recently launched <a href="https://github.com/dagworks-inc/burr">Burr to create LLM agents and applications</a>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Burr UI ++]]></title><description><![CDATA[Burr's Open Source UI that comes with: Traces, Attributes, Insights, and More]]></description><link>https://blog.dagworks.io/p/burr-ui</link><guid isPermaLink="false">https://blog.dagworks.io/p/burr-ui</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Fri, 30 Aug 2024 13:03:25 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This week we completed (and started) a major UI upgrade for Burr. We&#8217;re really excited about this, so we&#8217;re writing a quick post to share out the new features in the hope that you&#8217;ll be inspired to play around.</p><p>First, let&#8217;s quickly go over Burr.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe to receive new posts as they come out.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h1>Burr</h1><p>Burr is a lightweight Python library you use to build applications as stateful graphs. You construct your application out of a series of actions (these can be either decorated functions or objects), which declare inputs from state, as well as inputs from the user. These specify custom logic (delegating to any framework), as well as instructions on how to update state. State is immutable, which allows you to inspect it at any given point. Burr handles orchestration, monitoring, persistence, etc.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aVVt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" width="723" height="65" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:65,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30725,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Hello world counter action. Gist <a href="https://gist.github.com/elijahbenizzy/c295c2578685867996577733b8005f59">here</a></figcaption></figure></div><p>You run your Burr actions as part of an application &#8211; this allows you to string them together with a series of (optionally) conditional transitions from action to action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cI0I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cI0I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 424w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 848w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1272w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cI0I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png" width="1436" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:608,&quot;width&quot;:1436,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:130926,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!cI0I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 424w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 848w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1272w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">We stitch the application together, and add a tracker</figcaption></figure></div><p>You can visualize this as a flow chart, i.e. graph / state machine:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RB0k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RB0k!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RB0k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png" width="216" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:8585,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!RB0k!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Burr is often (but not always) used to build interactive LLM applications. State management, visibility, and persistence is all critical with AI, and Burr is meant to ensure that you get those capabilities for free and not have to think about them. To aid in visibility, Burr allows you to log spans in an OpenTelemetry-compatible format as well as any arbitrary attributes during execution. </p><p>Burr comes with a user-interface that enables monitoring/telemetry that we will showcase in this post. To illustrate, we&#8217;ll be borrowing from one of our favorite examples: a multi-modal chatbot. It emulates something like the ChatGPT UI, using a model to check the safety of the response, a model to decide the mode, and a model for each response type (image, code, question-answer, etc&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ieXl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ieXl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png 424w, https://substackcdn.com/image/fetch/$s_!ieXl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png 848w, https://substackcdn.com/image/fetch/$s_!ieXl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png 1272w, https://substackcdn.com/image/fetch/$s_!ieXl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ieXl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png" width="846" height="584" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e1543623-93d1-431d-a79b-0d78adf13872_846x584.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:584,&quot;width&quot;:846,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:61196,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ieXl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png 424w, https://substackcdn.com/image/fetch/$s_!ieXl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png 848w, https://substackcdn.com/image/fetch/$s_!ieXl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png 1272w, https://substackcdn.com/image/fetch/$s_!ieXl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1543623-93d1-431d-a79b-0d78adf13872_846x584.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You can run this with the following command (note you must have an OpenAI API Key set as <code>OPENAI_API_KEY</code>):</p><pre><code>pip install "burr[start]"
burr # opens on port 7241</code></pre><p>Then navigate to &#8220;demos&#8221; on the left hand side, and click on chatbot (or streaming-chatbot, they illustrate the same concepts). Preload the existing chats, or follow the instructions to run your own.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VC97!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VC97!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png 424w, https://substackcdn.com/image/fetch/$s_!VC97!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png 848w, https://substackcdn.com/image/fetch/$s_!VC97!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png 1272w, https://substackcdn.com/image/fetch/$s_!VC97!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VC97!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png" width="1200" height="614.010989010989" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:745,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:257814,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!VC97!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png 424w, https://substackcdn.com/image/fetch/$s_!VC97!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png 848w, https://substackcdn.com/image/fetch/$s_!VC97!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png 1272w, https://substackcdn.com/image/fetch/$s_!VC97!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1460139-5daf-49e4-a3cf-52587b25c06f_2546x1302.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You can watch it run through when you submit (note, it will terminate early on <code>check_openai_key</code> if you don&#8217;t have one), and preloading any of the demo runs will have the full set of visibility available.</p><h1>Traces/Spans</h1><p>Burr functions as a lightweight OpenTelemetry provider (see <a href="https://blog.dagworks.io/p/building-generative-ai-agent-based">this post</a> for more details) &#8212; it can both produce and ingest spans/traces (if they occur within the execution of a burr node).</p><p>To visualize, Burr presents a full waterfall view with timing</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!i9Gr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!i9Gr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png 424w, https://substackcdn.com/image/fetch/$s_!i9Gr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png 848w, https://substackcdn.com/image/fetch/$s_!i9Gr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png 1272w, https://substackcdn.com/image/fetch/$s_!i9Gr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!i9Gr!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png" width="1200" height="343.68131868131866" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:417,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:140456,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!i9Gr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png 424w, https://substackcdn.com/image/fetch/$s_!i9Gr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png 848w, https://substackcdn.com/image/fetch/$s_!i9Gr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png 1272w, https://substackcdn.com/image/fetch/$s_!i9Gr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d26f595-2f3d-4262-8d08-314e873cc151_2529x724.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You can expand all (or individual) actions to view spans, by clicking on the (+) sign next to Action:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!FFYz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!FFYz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png 424w, https://substackcdn.com/image/fetch/$s_!FFYz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png 848w, https://substackcdn.com/image/fetch/$s_!FFYz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png 1272w, https://substackcdn.com/image/fetch/$s_!FFYz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!FFYz!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png" width="1200" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:234054,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!FFYz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png 424w, https://substackcdn.com/image/fetch/$s_!FFYz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png 848w, https://substackcdn.com/image/fetch/$s_!FFYz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png 1272w, https://substackcdn.com/image/fetch/$s_!FFYz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F82f217d4-4071-401d-8b88-20ff0b7cefda_2542x1271.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You can view the corresponding state at any given point in time as well, as well as a host of other debugging information (code, graph shape, test case fixture creation, etc&#8230;):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CZv7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CZv7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png 424w, https://substackcdn.com/image/fetch/$s_!CZv7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png 848w, https://substackcdn.com/image/fetch/$s_!CZv7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png 1272w, https://substackcdn.com/image/fetch/$s_!CZv7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CZv7!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png" width="1200" height="606.5934065934066" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:736,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:321590,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CZv7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png 424w, https://substackcdn.com/image/fetch/$s_!CZv7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png 848w, https://substackcdn.com/image/fetch/$s_!CZv7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png 1272w, https://substackcdn.com/image/fetch/$s_!CZv7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc7a64ca-b8ba-4009-b77b-0dd7cdb8d0ba_2528x1278.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This helps you isolate issues post-hoc &#8212; determining the exact point in code at which, say, a hallucination occurred, or, if code breaks, the exact state that caused the issue.</p><h1>Attributes</h1><p>Burr allows you to go one step deeper &#8212; you can log any number of attributes and attach it to a trace/action. This works especially well with <a href="https://burr.dagworks.io/concepts/additional-visibility/#quickstart">OpenTelemetry auto-instrumentation</a> (see this post for instructions), and you can use <a href="https://burr.dagworks.io/concepts/additional-visibility/#observations">Burr&#8217;s Trace API</a> to log any serializable data.</p><p>Attributes show up inline, allowing you to see the prompt, the chat history, etc&#8230;</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gnq3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gnq3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png 424w, https://substackcdn.com/image/fetch/$s_!gnq3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png 848w, https://substackcdn.com/image/fetch/$s_!gnq3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png 1272w, https://substackcdn.com/image/fetch/$s_!gnq3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gnq3!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png" width="1200" height="601.6483516483516" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:730,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:287524,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gnq3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png 424w, https://substackcdn.com/image/fetch/$s_!gnq3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png 848w, https://substackcdn.com/image/fetch/$s_!gnq3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png 1272w, https://substackcdn.com/image/fetch/$s_!gnq3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8932dd46-2b2b-4933-aaa4-6e5745fc7e1b_2541x1274.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Note this will show up anywhere an instrumented call is made, so for every LLM call you can view attributes. You can also view the number of tokens (prompt/completion), as well as other metadata about the chat itself.</p><p>This helps you dig into the exact context in which any step ran, allowing you insight below the function-level.</p><h1>Insights</h1><p>Burr also enables you to look at the application as a whole &#8212; answering questions on total token usage, broken up by step. The insights tab gives you application-scoped data aggregated by step/span, enabling you to determine which steps cost the most to answer.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0Jmo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0Jmo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png 424w, https://substackcdn.com/image/fetch/$s_!0Jmo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png 848w, https://substackcdn.com/image/fetch/$s_!0Jmo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png 1272w, https://substackcdn.com/image/fetch/$s_!0Jmo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0Jmo!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png" width="1200" height="489.56043956043953" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:594,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:308201,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0Jmo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png 424w, https://substackcdn.com/image/fetch/$s_!0Jmo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png 848w, https://substackcdn.com/image/fetch/$s_!0Jmo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png 1272w, https://substackcdn.com/image/fetch/$s_!0Jmo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F995ccc09-9ed8-4360-b1b0-05d418f2a9e3_2528x1032.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Note we currently have a few LLM-specific insights, but plan to add more shortly &#8212; including direct cost metrics, timing, and aggregations of other (more arbitrary metrics). Stay tuned!</p><h1>Future Plans</h1><p>We&#8217;re just getting started. We&#8217;re particularly excited about OpenTelemetry data &#8212; by  automatically instrumenting LLM calls, we actually have enough data to launch an interactive prompt playground, from any point in the application&#8217;s call-stack! Here&#8217;s a sneak-peak of a streamlit prototype that allows you to load up an LLM call at any point and reproduce/play with it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!snTR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!snTR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png 424w, https://substackcdn.com/image/fetch/$s_!snTR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png 848w, https://substackcdn.com/image/fetch/$s_!snTR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png 1272w, https://substackcdn.com/image/fetch/$s_!snTR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!snTR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png" width="1456" height="771" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:771,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:979653,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!snTR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png 424w, https://substackcdn.com/image/fetch/$s_!snTR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png 848w, https://substackcdn.com/image/fetch/$s_!snTR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png 1272w, https://substackcdn.com/image/fetch/$s_!snTR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F64ad4ace-fe0d-459a-a449-867078b50e45_2478x1312.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>We have a host of other ideas in the works &#8212; but we operate largely on feedback. If you have any feedback/suggestions, please let us know! </p><h1>More Resources</h1><ul><li><p>Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a> for help or if you have questions!</p></li><li><p><a href="http://github.com/dagworks-inc/burr">Github repository for Burr</a> (give us a star if you like what you see!)</p></li><li><p><a href="https://opentelemetry.io/">OpenTelemetry</a></p></li><li><p><a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/streaming-fastapi">Example + README</a>.</p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[Trace all parts of your Agentic/AI Applications with Burr ]]></title><description><![CDATA[Use the @trace decorator to gain visibility into any functions called within Burr]]></description><link>https://blog.dagworks.io/p/trace-all-parts-of-your-agenticai</link><guid isPermaLink="false">https://blog.dagworks.io/p/trace-all-parts-of-your-agenticai</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Fri, 23 Aug 2024 21:41:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!cI0I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Building reliable AI applications without visibility is a herculean task. While any well-designed application framework should include an <a href="https://github.com/DAGWorks-Inc/burr?tab=readme-ov-file#quick-start">open source UI for visibility</a>, <a href="https://blog.dagworks.io/p/travel-back-in-time-with-burr">debugging capabilities</a>, and <a href="https://blog.dagworks.io/p/building-generative-ai-agent-based">integrations with common standards such as OpenTelemetry</a> (Burr provides all of this + more), in our AI development work we have still found ourselves wanting additional visibility on demand.</p><p>Specifically, we usually break our application logic into functions &#8211; these functions call other functions, which call other functions, which eventually call out to a model or a vector DB. In order to understand both <em>what</em> happened and <em>why </em>it happened, we need insight into those functions.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>This is why we built the `@trace` decorator &#8212; it enables us to flip a switch on any function called within a Burr step and gain full visibility into the inputs, the execution time, and the return value of that function.</p><p>In this post we will briefly go over Burr, talk about how to use the new @trace decorator, and how to explore the results in the Burr UI. We will then briefly talk about other instrumentation/visualization capabilities.</p><p>Note that the version of the Burr UI we show in this post is (as of August 23rd) available as an RC &#8211; we will be releasing it properly early next week!</p><h1>Burr</h1><p>Burr is a lightweight Python library you use to build applications as stateful graphs. You construct your application out of a series of actions (these can be either decorated functions or objects), which declare inputs from state, as well as inputs from the user. These specify custom logic (delegating to any framework), as well as instructions on how to update state. State is immutable, which allows you to inspect it at any given point. Burr handles orchestration, monitoring, persistence, etc.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aVVt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" width="723" height="65" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:65,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30725,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw" loading="lazy" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Hello world counter action. Gist <a href="https://gist.github.com/elijahbenizzy/c295c2578685867996577733b8005f59">here</a></figcaption></figure></div><p>You run your Burr actions as part of an application &#8211; this allows you to string them together with a series of (optionally) conditional transitions from action to action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cI0I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cI0I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 424w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 848w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1272w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cI0I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png" width="1436" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:608,&quot;width&quot;:1436,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:130926,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!cI0I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 424w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 848w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1272w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">We stitch the application together, and add a tracker</figcaption></figure></div><p>Burr comes with a user-interface that enables monitoring/telemetry, as well as hooks to persist state/execute arbitrary code during execution.</p><p>You can visualize this as a flow chart, i.e. graph / state machine:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RB0k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RB0k!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RB0k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png" width="216" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:8585,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!RB0k!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can use the local telemetry debugger to view apps (which, as you will see, also provides some OpenTel integrations):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8_eS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8_eS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png 424w, https://substackcdn.com/image/fetch/$s_!8_eS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png 848w, https://substackcdn.com/image/fetch/$s_!8_eS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png 1272w, https://substackcdn.com/image/fetch/$s_!8_eS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8_eS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png" width="1453" height="1242" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1242,&quot;width&quot;:1453,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:139952,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8_eS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png 424w, https://substackcdn.com/image/fetch/$s_!8_eS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png 848w, https://substackcdn.com/image/fetch/$s_!8_eS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png 1272w, https://substackcdn.com/image/fetch/$s_!8_eS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d76fc07-8103-458c-97a7-c8dbcc0b7e7c_1453x1242.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The Burr UI. You will see more interesting traces/instrumentation later on in this post.</figcaption></figure></div><h1>A Simple Agentic Chatbot</h1><p>Let&#8217;s graduate from the hello world example and build something useful &#8212; a simple <em>agentic</em> chatbot that handles multiple response modes. It will be <em>agentic</em> as it makes multiple LLM calls:</p><ol><li><p>A call to determine the model to query. Our model will have a few &#8220;modes&#8221; &#8212; generate a poem, answer a question, etc&#8230;</p></li><li><p>A call to the actual model (in this case prompt + model combination)</p></li></ol><p>With the OpenAI API this is more of a toy example &#8212; their models are impressive jacks of all trades. That said, this pattern of tool delegation shows up in a wide variety of AI applications, and this example can be extrapolated cleanly. You will note this is a similar example to our <a href="https://blog.dagworks.io/p/building-generative-ai-agent-based">prior visibility post</a> &#8212; you can skim through if you&#8217;re on a visibility spree and just came from that one!</p><p>To leverage Burr, we model our application as a graph of actions. The basic flow of logic looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5ntS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5ntS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 424w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 848w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 1272w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5ntS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png" width="856" height="551" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:551,&quot;width&quot;:856,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:64531,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!5ntS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 424w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 848w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 1272w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">We start at a user prompt input (top). Then we check for safety, and if it&#8217;s not safe, we go the specific response for &#8220;unsafe&#8221;. Otherwise we decide on the mode, and switch based on the value of the state field mode. Each of these returns a response. Once they are done, we circle back to the prompt and wait for another user input&#8230;</figcaption></figure></div><p>Let&#8217;s take a look at the chat_response function that powers the nodes answer_question and generate_code, depending on the value of prepend_prompt:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KoOR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KoOR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png 424w, https://substackcdn.com/image/fetch/$s_!KoOR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png 848w, https://substackcdn.com/image/fetch/$s_!KoOR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png 1272w, https://substackcdn.com/image/fetch/$s_!KoOR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KoOR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png" width="1450" height="656" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:656,&quot;width&quot;:1450,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:144362,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KoOR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png 424w, https://substackcdn.com/image/fetch/$s_!KoOR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png 848w, https://substackcdn.com/image/fetch/$s_!KoOR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png 1272w, https://substackcdn.com/image/fetch/$s_!KoOR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8d86256a-6c61-44bb-a1c1-f347c812d061_1450x656.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">A simple Burr action to query OpenAI based on the chat history stored in state. Gist <a href="https://gist.github.com/elijahbenizzy/9519a558279e550508470e82fb8b1a90#file-chat_response-py">here</a>.</figcaption></figure></div><p>You will note that this uses the helper function <code>_query_openai</code>, which can easily be adjusted to query any LLM. We will be instrumenting this in a bit.</p><p>The graph creation + instantiation looks similar to what we showed above (a few pieces left out for brevity). Note we&#8217;re reusing some functions (chat_response), by binding different function parameters to create different nodes in the graph.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UeFG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UeFG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 424w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 848w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 1272w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UeFG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png" width="728" height="785.0980392156863" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1540,&quot;width&quot;:1428,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:304480,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!UeFG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 424w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 848w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 1272w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"> Gist <a href="https://gist.github.com/elijahbenizzy/8c542d1aa291fc19669ae01c7ba82ffe#file-app_basic-py">here</a>.</figcaption></figure></div><h1>Gaining Visibility</h1><p>We can explore how this looks in the UI. The following is from two prompts in a row</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Kk-Y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Kk-Y!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png 424w, https://substackcdn.com/image/fetch/$s_!Kk-Y!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png 848w, https://substackcdn.com/image/fetch/$s_!Kk-Y!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png 1272w, https://substackcdn.com/image/fetch/$s_!Kk-Y!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Kk-Y!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png" width="1200" height="641.7470797359066" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:1053,&quot;width&quot;:1969,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:254971,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Kk-Y!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png 424w, https://substackcdn.com/image/fetch/$s_!Kk-Y!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png 848w, https://substackcdn.com/image/fetch/$s_!Kk-Y!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png 1272w, https://substackcdn.com/image/fetch/$s_!Kk-Y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43b0a52d-88bb-4a3b-af57-17c2fb1844bc_1969x1053.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">UI view of application execution above on questions about Aaron Burr.</figcaption></figure></div><p>As you can see, we have some access to data, input, etc.. through the view, but we don&#8217;t have the internals of how the prompt was manipulated. </p><h2>Using the @trace decorator</h2><p>With the @trace decorator we can augment the data above. Specifically, we&#8217;re going to surround two of our functions with @trace to gain insight into how they work. The _query_openai method because it is useful, and the _get_openai_client method for fun.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GXeH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GXeH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png 424w, https://substackcdn.com/image/fetch/$s_!GXeH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png 848w, https://substackcdn.com/image/fetch/$s_!GXeH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png 1272w, https://substackcdn.com/image/fetch/$s_!GXeH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GXeH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png" width="1440" height="968" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:968,&quot;width&quot;:1440,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:158627,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!GXeH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png 424w, https://substackcdn.com/image/fetch/$s_!GXeH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png 848w, https://substackcdn.com/image/fetch/$s_!GXeH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png 1272w, https://substackcdn.com/image/fetch/$s_!GXeH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb53c65b7-3c8e-402e-be2e-ed68a33038a1_1440x968.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/f8f60fd0c06b6c99780f3b285c33dad9">gist</a></figcaption></figure></div><p>We can view the spans (toggled globally by the +/- button near the action header, or the +/- button near individual actions), we can see that a set of spans have been logged that correspond to a set of attributes (see the inline database icon):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nLFL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nLFL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png 424w, https://substackcdn.com/image/fetch/$s_!nLFL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png 848w, https://substackcdn.com/image/fetch/$s_!nLFL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png 1272w, https://substackcdn.com/image/fetch/$s_!nLFL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nLFL!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png" width="1200" height="673.3516483516484" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d561091a-e65c-41a8-9529-872ca0028c40_1713x961.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:817,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:171652,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nLFL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png 424w, https://substackcdn.com/image/fetch/$s_!nLFL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png 848w, https://substackcdn.com/image/fetch/$s_!nLFL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png 1272w, https://substackcdn.com/image/fetch/$s_!nLFL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd561091a-e65c-41a8-9529-872ca0028c40_1713x961.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Clicking the database icon to the right of a span opens up the attributes logged and gives us insight into the parameters (prompt, model, chat_history), as well as the return value (labeled return):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dCAo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dCAo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png 424w, https://substackcdn.com/image/fetch/$s_!dCAo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png 848w, https://substackcdn.com/image/fetch/$s_!dCAo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png 1272w, https://substackcdn.com/image/fetch/$s_!dCAo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dCAo!,w_2400,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png" width="1200" height="831.5934065934066" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;large&quot;,&quot;height&quot;:1009,&quot;width&quot;:1456,&quot;resizeWidth&quot;:1200,&quot;bytes&quot;:295987,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-large" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dCAo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png 424w, https://substackcdn.com/image/fetch/$s_!dCAo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png 848w, https://substackcdn.com/image/fetch/$s_!dCAo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png 1272w, https://substackcdn.com/image/fetch/$s_!dCAo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F50738a80-1306-4eb0-9112-18b1c92a9bda_1764x1223.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Not only can we see the full prompt (see `<code>prompt</code>` attribute), but we can also tell that we have an additional colon (`<code>::</code>`), and that it took 3.345 seconds to respond. We also have some simple debugging information on the function that was instrumented and the hash of the code. This response glosses over the treason, name change, failed marriages, and financial challenges that plagued him later in life.</p><h2>Further Instrumentation</h2><p>That said, this is just a toy example. The true power of AI does more than provide answers a simple wikipedia article would show, and Burr can be used for a lot more than just a chatbot.</p><p>The <a href="https://burr.dagworks.io/concepts/additional-visibility/#tracing-functions">@trace</a> decorator makes this feasible &#8211; instead of just gaining visibility at the Burr level (state, results), you can dig in as deep as you want.</p><p>In addition (and in complement) to the trace decorator, you can auto-instrument most of the popular (vendor and OS) model providers &amp; vector databases, as well as leverage any other instrumentation. You can view all this data in the Burr UI, in your favorite OTel provider, or both! See <a href="https://blog.dagworks.io/p/building-generative-ai-agent-based">our previous writeup</a> for more information.</p><h1>More Resources</h1><ul><li><p>Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a> for help or if you have questions!</p></li><li><p><a href="http://github.com/dagworks-inc/burr">Github repository for Burr</a> (give us a star if you like what you see!)</p></li><li><p><a href="https://opentelemetry.io/">OpenTelemetry</a></p></li><li><p><a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/streaming-fastapi">Example + README</a></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Building Generative AI / Agent based applications you can monitor with OpenTelemetry ]]></title><description><![CDATA[An overview of OpenTelemetry and the integration with Burr.]]></description><link>https://blog.dagworks.io/p/building-generative-ai-agent-based</link><guid isPermaLink="false">https://blog.dagworks.io/p/building-generative-ai-agent-based</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Fri, 16 Aug 2024 15:56:48 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!tjU9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tjU9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tjU9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png 424w, https://substackcdn.com/image/fetch/$s_!tjU9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png 848w, https://substackcdn.com/image/fetch/$s_!tjU9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png 1272w, https://substackcdn.com/image/fetch/$s_!tjU9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tjU9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png" width="1237" height="444" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:444,&quot;width&quot;:1237,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:117567,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tjU9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png 424w, https://substackcdn.com/image/fetch/$s_!tjU9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png 848w, https://substackcdn.com/image/fetch/$s_!tjU9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png 1272w, https://substackcdn.com/image/fetch/$s_!tjU9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c6c6511-f5d5-4281-b957-847e7e38f9d5_1237x444.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>One of the most challenging aspects of building Generative AI applications is understanding what happened and why it happened. In addition to the standard monitoring concerns (how long did this step take, what caused the exception the program threw, etc&#8230;), we have to deal with a plethora of Generative AI-specific challenges. Did this model get fed a reasonable prompt? Did it produce a reasonable result? If not, why? When you&#8217;re building <em>agentic</em> applications (those that leverage AI calls to make automated decisions), this gets even more complicated.</p><p>In this post, we&#8217;re going to talk about how you can leverage the industry-wide <a href="https://opentelemetry.io/">OpenTelemetry</a> standard to instrument Generative AI applications built with <a href="https://github.com/dagworks-inc/burr">Burr</a> and provide visibility into the aforementioned questions. We will present the basics of OpenTelemetry,&nbsp; walk through a simple application implementation with <a href="https://github.com/dagworks-inc/burr">Burr</a>, and show how you can get visibility over the decisions your &#8220;AI/Agent&#8221; make in a few lines of code, using your preferred OpenTelemetry vendor along with the builtin Burr UI. We will then show how you can utilize custom instrumentation to gain additional monitoring for Generative AI-specific concerns.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe to stay up to date on our work + new releases.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>OpenTelemetry</h2><p>OpenTelemetry, or OTel for short, is a standard that has skyrocketed in popularity in recent years. It is a <a href="https://www.cncf.io/projects/">CNCF incubating project</a>, with an open governance model to ensure no single vendor steers it too much in any specific direction.</p><p>It is now supported by a large array of vendors, ensuring that how you instrument is not a cause of vendor lock in, which forces observability companies, i.e. those that ingest OpenTelemetry data, to compete by building better features.</p><p>OpenTelemetry defines how applications can export the following information:</p><ol><li><p>Traces &#8211; a request&#8217;s journey as it travels through the application&nbsp;&nbsp;</p></li><li><p>Metrics &#8211; various data points (aggregate or individual) that represent some observation of the application at a given point in time</p></li><li><p>Logs &#8211; what the application printed while running</p></li></ol><p>In this post we will be focusing on traces, which OpenTelemetry models with the following concepts:</p><ol><li><p>A span &#8211; an individual component of execution with a start/end time and exception data attached to it. This can be recursive &#8211; spans can have sub-spans, etc&#8230;</p></li><li><p>A trace &#8211; a group of spans that represent a journey through the application</p></li><li><p>Attributes &#8211; data attached to a span to make debugging easier.</p></li></ol><p>OpenTelemetry provides APIs for ingesting this data, as well as client-side tooling that implements this. In python,&nbsp;the<a href="https://pypi.org/project/opentelemetry-api/"> opentelemetry-api</a> package defines high-level interfaces, and the <a href="https://pypi.org/project/opentelemetry-sdk/">opentelemetry-sdk </a>as a default implementation, is provider-agnostic client.</p><p>Using OpenTelemetry tracing in python is simple &#8211; you just need to get the global tracer and exercise it:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ph-i!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ph-i!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png 424w, https://substackcdn.com/image/fetch/$s_!Ph-i!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png 848w, https://substackcdn.com/image/fetch/$s_!Ph-i!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png 1272w, https://substackcdn.com/image/fetch/$s_!Ph-i!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ph-i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png" width="1430" height="566" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/afc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:566,&quot;width&quot;:1430,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:101756,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ph-i!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png 424w, https://substackcdn.com/image/fetch/$s_!Ph-i!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png 848w, https://substackcdn.com/image/fetch/$s_!Ph-i!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png 1272w, https://substackcdn.com/image/fetch/$s_!Ph-i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc5c71f-acc6-4092-ab75-4a56afb6521b_1430x566.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/82b864a627bfe75ddf90870de5734045#file-trace-py">here</a></figcaption></figure></div><p>So, OpenTelemetry is popular and easy to use, but why should you consider using it, and how can it help with AI observability?</p><ol><li><p>OpenTelemetry is vendor (a.k.a. visibility provider) agnostic, meaning that you can easily switch between vendors. In this case we&#8217;ll be using <a href="http://traceloop.com">Traceloop</a> to demonstrate, but you can easily get started on <a href="https://opentelemetry.io/ecosystem/vendors/">any of these.</a></p></li><li><p>OpenTelemetry is openly governed, meaning that you can dig in to understand the decisions they made and even be a part of it!</p></li><li><p>Data visibility is the first step to understanding the questions of <em>why</em> a model made the decision it did &#8212; OpenTelemetry provides this with tracing and attributes (logging the input/output/other model data).</p></li><li><p>There are a host of extensions available to OpenTelemetry &#8212; in this case we will be using Traceloop&#8217;s open source <a href="https://github.com/traceloop/openllmetry">openllmetry</a> library to automatically instrument our LLM calls as it supports many <a href="https://github.com/traceloop/openllmetry/tree/main/packages">LLM &amp; vector DB client SDKs</a>.</p></li></ol><h2>Burr</h2><p>Burr is a lightweight Python library you use to build applications as stateful graphs. You construct your application out of a series of actions (these can be either decorated functions or objects), which declare inputs from state, as well as inputs from the user. These specify custom logic (delegating to any framework), as well as instructions on how to update state. State is immutable, which allows you to inspect it at any given point. Burr handles orchestration, monitoring, persistence, etc&#8230;).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aVVt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png" width="723" height="65" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:65,&quot;width&quot;:723,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30725,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!aVVt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 424w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 848w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1272w, https://substackcdn.com/image/fetch/$s_!aVVt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febcf5d53-41b8-4ba9-8207-a7112d18ce92_723x65.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Hello world counter action. Gist <a href="https://gist.github.com/elijahbenizzy/c295c2578685867996577733b8005f59">here</a></figcaption></figure></div><p>You run your Burr actions as part of an application &#8211; this allows you to string them together with a series of (optionally) conditional transitions from action to action.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cI0I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cI0I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 424w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 848w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1272w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cI0I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png" width="1436" height="608" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:608,&quot;width&quot;:1436,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:130926,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cI0I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 424w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 848w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1272w, https://substackcdn.com/image/fetch/$s_!cI0I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd94ab3d9-3b8b-42cb-9e0b-065b27f63b10_1436x608.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">We stitch the application together, and add a tracker </figcaption></figure></div><p>Burr comes with a user-interface that enables monitoring/telemetry, as well as hooks to persist state/execute arbitrary code during execution.</p><p>You can visualize this as a flow chart, i.e. graph / state machine:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RB0k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RB0k!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RB0k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png" width="216" height="150" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:150,&quot;width&quot;:216,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:8585,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!RB0k!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 424w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 848w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1272w, https://substackcdn.com/image/fetch/$s_!RB0k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F307bfe4a-153c-4f86-a87c-d071fdfc6576_216x150.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can use the local telemetry debugger to view apps (which, as you will see, also provides some OpenTel integrations):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!izkT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!izkT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png 424w, https://substackcdn.com/image/fetch/$s_!izkT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png 848w, https://substackcdn.com/image/fetch/$s_!izkT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png 1272w, https://substackcdn.com/image/fetch/$s_!izkT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!izkT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png" width="1456" height="786" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:786,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!izkT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png 424w, https://substackcdn.com/image/fetch/$s_!izkT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png 848w, https://substackcdn.com/image/fetch/$s_!izkT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png 1272w, https://substackcdn.com/image/fetch/$s_!izkT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d8ef37-4c9f-4d96-9cf1-c687adebd6e6_1456x786.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Burr UI, run locally with <code>pip install burr[start] &amp;&amp; burr</code></figcaption></figure></div><h1>A Simple Agentic Chatbot</h1><p>Let&#8217;s graduate from the hello world example and build something useful &#8212; a simple <em>agentic</em> chatbot that handles multiple response modes. It will be <em>agentic</em> as it makes multiple LLM calls:</p><ol><li><p>A call to determine the model to query. Our model will have a few &#8220;modes&#8221; &#8212; generate a poem, answer a question, etc&#8230;</p></li><li><p>A call to the actual model (in this case prompt + model combination)</p></li></ol><p>With the OpenAI API this is more of a toy example &#8212; their models are impressive jacks of all trades. That said, this pattern of tool delegation shows up in a wide variety of AI applications, and this example can be extrapolated cleanly. You will note this is a similar example to <a href="https://towardsdatascience.com/how-to-build-a-streaming-agent-with-burr-fastapi-and-react-e2459ef527a8">our prior streaming post</a>.&nbsp;</p><h2>Modeling our Application</h2><p>To leverage Burr, we model our application as a graph of actions. The basic flow of logic looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5ntS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5ntS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 424w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 848w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 1272w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5ntS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png" width="856" height="551" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:551,&quot;width&quot;:856,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:64531,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5ntS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 424w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 848w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 1272w, https://substackcdn.com/image/fetch/$s_!5ntS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd05bfe0b-12ee-4bee-a7a2-54c5c2c0869d_856x551.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">We start at a user prompt input (top). Then we check for safety, and if it&#8217;s not safe, we go the specific response for &#8220;unsafe&#8221;. Otherwise we decide on the mode, and switch based on the value of the state field mode. Each of these returns a response. Once they are done, we circle back to the prompt and wait for another user input&#8230;</figcaption></figure></div><p>Let&#8217;s take a look at the decide_mode function &#8211; this is a simple call out to OpenAI (one of a few in the stack).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w8Yz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w8Yz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png 424w, https://substackcdn.com/image/fetch/$s_!w8Yz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png 848w, https://substackcdn.com/image/fetch/$s_!w8Yz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png 1272w, https://substackcdn.com/image/fetch/$s_!w8Yz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w8Yz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png" width="1456" height="1534" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1534,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:307808,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!w8Yz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png 424w, https://substackcdn.com/image/fetch/$s_!w8Yz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png 848w, https://substackcdn.com/image/fetch/$s_!w8Yz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png 1272w, https://substackcdn.com/image/fetch/$s_!w8Yz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a37df4f-a42f-4cc3-a0d8-fac9e959a14e_1460x1538.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Gists <a href="https://gist.github.com/elijahbenizzy/e1e51ea7095fa561d8e3ebcfa9f514bf#file-choose_mode-py">here</a></figcaption></figure></div><p>As you can see, we are directly using the OpenAI API, and parsing the result (note that <a href="https://github.com/jxnl/instructor">instructor</a> or <a href="https://platform.openai.com/docs/guides/structured-outputs">OpenAI structured outputs</a> would likely be a better choice to force the mode to produce&nbsp; what we want, blog post coming soon!).&nbsp;</p><p>The graph creation + instantiation looks similar to what we showed above (a few pieces left out for brevity). Note we&#8217;re reusing some functions (chat_response), by binding different function parameters to create different nodes in the graph.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UeFG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UeFG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 424w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 848w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 1272w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UeFG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png" width="1428" height="1540" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1540,&quot;width&quot;:1428,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:304480,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UeFG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 424w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 848w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 1272w, https://substackcdn.com/image/fetch/$s_!UeFG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F458a0529-4537-417c-8813-8f1b081ed9a4_1428x1540.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/8c542d1aa291fc19669ae01c7ba82ffe#file-app_basic-py">here</a>.</figcaption></figure></div><h2>Manual Instrumentation with OpenTelemetry</h2><p>We have two ways of manually logging custom OpenTelemetry traces with Burr:</p><ol><li><p>The Burr tracing SDK</p></li><li><p>The OpenTelemetry SDK</p></li></ol><p>We&#8217;ll show the Burr API (1), but you can use the OpenTelemetry SDK interchangeably &#8212; it will all get logged to the same place. To add custom traces, we can do something like this manually:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LbDH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LbDH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png 424w, https://substackcdn.com/image/fetch/$s_!LbDH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png 848w, https://substackcdn.com/image/fetch/$s_!LbDH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png 1272w, https://substackcdn.com/image/fetch/$s_!LbDH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LbDH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png" width="1416" height="572" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:572,&quot;width&quot;:1416,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:128164,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LbDH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png 424w, https://substackcdn.com/image/fetch/$s_!LbDH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png 848w, https://substackcdn.com/image/fetch/$s_!LbDH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png 1272w, https://substackcdn.com/image/fetch/$s_!LbDH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66cca7bc-5212-4d22-a80d-0943301c83ce_1416x572.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Using Burr&#8217;s tracing API to log to OpenTelemetry. We log a few attributes, and create a single span for opentelemetry. Gist <a href="https://gist.github.com/elijahbenizzy/b72ba6f20305ffe24ef1c3cb9a4a025a#file-choose_mode_instrumented-py">here</a></figcaption></figure></div><p>Then to run, we add a simple hook. This ensures that framework calls (E.G. to app.run()...) are traced as well.&nbsp;</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eCNp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eCNp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png 424w, https://substackcdn.com/image/fetch/$s_!eCNp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png 848w, https://substackcdn.com/image/fetch/$s_!eCNp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png 1272w, https://substackcdn.com/image/fetch/$s_!eCNp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eCNp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png" width="1444" height="698" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/546e8072-975b-4901-a863-700866251a92_1444x698.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:698,&quot;width&quot;:1444,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:102555,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eCNp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png 424w, https://substackcdn.com/image/fetch/$s_!eCNp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png 848w, https://substackcdn.com/image/fetch/$s_!eCNp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png 1272w, https://substackcdn.com/image/fetch/$s_!eCNp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F546e8072-975b-4901-a863-700866251a92_1444x698.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/808849fba8e5c460501bd3a3c256633d#file-opentelemetry_bridge-py">here</a></figcaption></figure></div><h3>Generative AI-specific OpenTelemetry</h3><p>OpenTelemetry defines a set of attributes specifically for tracking AI applications. This enables us avoid the manual instrumentation we did above, and instead get it for free! </p><p>These <a href="https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/">take the form of semantic conventions that give some very simple model-related parameters</a>. Furthermore, Traceloop has implemented a variety of SDKs that automatically instrument common clients. You can access them with Traceloop <a href="https://www.traceloop.com/docs/openllmetry/tracing/without-sdk">here</a> (and, if you initialize with traceloop, they get automatically set up).</p><p>Thus to automatically instrument most gen AI applications, you simply need to call instrument on the appropriate object:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rgx7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rgx7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png 424w, https://substackcdn.com/image/fetch/$s_!rgx7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png 848w, https://substackcdn.com/image/fetch/$s_!rgx7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png 1272w, https://substackcdn.com/image/fetch/$s_!rgx7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rgx7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png" width="1440" height="126" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:126,&quot;width&quot;:1440,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32303,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!rgx7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png 424w, https://substackcdn.com/image/fetch/$s_!rgx7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png 848w, https://substackcdn.com/image/fetch/$s_!rgx7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png 1272w, https://substackcdn.com/image/fetch/$s_!rgx7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faaf5538c-ed4b-4c52-bbd8-da87de5ad27a_1440x126.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Gist <a href="https://gist.github.com/elijahbenizzy/309ebfbe87172ae140d0af871e793865#file-instrument-py">here</a>. You import the right module and the in one line turn on instrumentation.</figcaption></figure></div><p>While this is not required for the basics of monitoring with Burr, the auto-instrumentation libraries follows the semantic conventions and logs attributes that are useful in giving insight to the model, as well as the cost of execution, e.g. how many tokens were sent and how many were generated.</p><p>Putting this all together, we can see our spans get populated in Traceloop!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QG32!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QG32!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png 424w, https://substackcdn.com/image/fetch/$s_!QG32!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png 848w, https://substackcdn.com/image/fetch/$s_!QG32!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png 1272w, https://substackcdn.com/image/fetch/$s_!QG32!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QG32!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png" width="1456" height="754" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:754,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:933989,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QG32!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png 424w, https://substackcdn.com/image/fetch/$s_!QG32!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png 848w, https://substackcdn.com/image/fetch/$s_!QG32!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png 1272w, https://substackcdn.com/image/fetch/$s_!QG32!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19d04aea-e82d-43e8-ba4d-06a5afaad114_3200x1658.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Spans viewed in the Traceloop UI, focusing in on the OpenAI call</figcaption></figure></div><h3>Logging OpenTelemetry Traces to Burr</h3><p>We can take the same traces we logged above and flip a simple switch to log them via Burr&#8217;s tracking hooks &#8212; this will log to the local Burr server and show the traces in the context of a Burr execution.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XpSr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XpSr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png 424w, https://substackcdn.com/image/fetch/$s_!XpSr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png 848w, https://substackcdn.com/image/fetch/$s_!XpSr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png 1272w, https://substackcdn.com/image/fetch/$s_!XpSr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XpSr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png" width="720" height="281" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:false,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:281,&quot;width&quot;:720,&quot;resizeWidth&quot;:720,&quot;bytes&quot;:32365,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XpSr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png 424w, https://substackcdn.com/image/fetch/$s_!XpSr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png 848w, https://substackcdn.com/image/fetch/$s_!XpSr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png 1272w, https://substackcdn.com/image/fetch/$s_!XpSr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc3f2984-9caa-49af-bce9-ed7f22912a3b_720x281.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">All we have to do to  to enable Burr to capture OpenTelemetry traces is to flip use_otel_tracing to be true. Gist <a href="http://Log to burr by flipping the use_otel_tracing switch to True. Gist here.">here</a>.</figcaption></figure></div><p>We can see traces in the Burr UI with a similar view, as well as associated attributes on a span level:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BXCT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BXCT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png 424w, https://substackcdn.com/image/fetch/$s_!BXCT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png 848w, https://substackcdn.com/image/fetch/$s_!BXCT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png 1272w, https://substackcdn.com/image/fetch/$s_!BXCT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BXCT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png" width="1456" height="746" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:746,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:581132,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BXCT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png 424w, https://substackcdn.com/image/fetch/$s_!BXCT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png 848w, https://substackcdn.com/image/fetch/$s_!BXCT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png 1272w, https://substackcdn.com/image/fetch/$s_!BXCT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F02ebee9c-f357-4ef0-9baf-03e0fc1b81d3_3410x1748.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Same span in the Burr UI</figcaption></figure></div><h2>Wrapping Up</h2><p>We showed how to gain visibility by leveraging OpenTelemetry. In addition to providing insight into system performance, OpenTelemetry (through either the Burr UI or a OpenTel vendor) affords us visibility into every aspect of our application &#8211; the inputs/outputs of models, and how downstream processes leveraged that. So, circling back to what we wanted to know initially:</p><ol><li><p>Did this model get fed a reasonable prompt?&nbsp;</p></li><li><p>Did it produce a reasonable result?&nbsp;</p></li><li><p>If not, why?&nbsp;</p></li></ol><p>(1) and (2) are directly answered by attribute-logging with OpenTelemetry, whereas (3) will always be a bit of a guessing game. That said, knowing the facts (inputs and outputs) is the first step to understanding the <em>why</em>, and <a href="https://blog.dagworks.io/p/travel-back-in-time-with-burr">Burr has features to help you &#8220;replay&#8221; / go back in time</a> to quickly debug or try different code paths, providing an integrated development &amp; observability experience.</p><p>Lastly, OpenTelemetry traces support crossing service boundaries. So, if you are self-hosting your LLM and really want to get into the nitty-gritty, you can instrument your model service and report traces back to, say, Traceloop or Burr, gaining visibility into the model along with the application.</p><h1>More Resources</h1><ul><li><p>Join our <a href="https://discord.gg/6Zy2DwP4f3">Discord</a> for help or if you have questions!</p></li><li><p><a href="http://github.com/dagworks-inc/burr">Github repository for Burr</a> (give us a star if you like what you see!)</p></li><li><p><a href="https://opentelemetry.io/">OpenTelemetry</a></p></li><li><p><a href="https://github.com/DAGWorks-Inc/burr/tree/main/examples/streaming-fastapi">Example + README</a></p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[Modeling Pregnancy Due Dates with Hamilton]]></title><description><![CDATA[How to build an interactive dataflow to represent conditional probability calculation for an expecting mother's due date]]></description><link>https://blog.dagworks.io/p/modeling-pregnancy-due-dates-with</link><guid isPermaLink="false">https://blog.dagworks.io/p/modeling-pregnancy-due-dates-with</guid><dc:creator><![CDATA[Elijah ben Izzy]]></dc:creator><pubDate>Wed, 07 Aug 2024 16:02:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Q1CW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This post was written on July 13th 2024. The baby came on July 22nd. The conditional probability of that was 5.01%, and it was the fourth most-likely date. </p><p>You can find the code (notebook + modules) for the blog post <a href="https://github.com/dagworks-inc/hamilton/tree/main/examples/due_date_probabilities/README.md">here</a>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe to stay up to date on new posts.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h1>The Problem</h1><p>A baby never comes on time. Well, a baby <em>rarely</em> comes on time. In fact, there is a <a href="https://datayze.com/labor-probability-calculator">3% chance</a> that a baby will come on the due date, a 50.5% chance that it will come before, and a 46.5% chance that it will come after.</p><p>For parents expecting to deliver naturally, this can be an unsatisfying answer:</p><ul><li><p><em>When will my baby be here?</em></p></li><li><p><em>Well, given that today is July 14, your due date is July 18, and the baby has not yet come, here is the skew-normal probability distribution that describes it (big curve). Oh, and if it doesn&#8217;t come by the end of July you&#8217;ll want to induce.&nbsp;</em></p></li></ul><p>While I am as frustrated about the lack of certainty as anyone (this lesson applies to more than just simple predictions, by the way), I do have one advantage. I&#8217;m an absolute nerd &#8211; I have a passing fancy for conditional probabilities and pretty plots, as well as an obsession for building elegant data manipulation systems.</p><p>In this post, we&#8217;re going to calculate due date probabilities using a fairly simple statistical model. In doing so, we will show you how to use Hamilton for production-ready EDA inside a notebook, utilize the builtin <em>calendar </em>library to visualize our results, and reverse engineer the parameters of a probability distribution in an extremely hacky but simple way. All this because the room is painted, the crib is assembled, the go-bag is packed (well, hers is but I&#8217;m procrastinating), and really, there is very little else for me to do.</p><h1>Hamilton</h1><p>We will go over visualization/modeling tools when we use them, but let&#8217;s explain Hamilton a bit before diving in. Hamilton is a lightweight python library for building <em>dataflows</em> (any computation requiring data) out of python functions. It can run wherever Python does, and is widely used for anything from simple statistical modeling (this post) to more complex ML, to online RAG in web services and more complex ingestion pipelines for AI systems.</p><p>The core concept is&nbsp;simple &#8211; you write each data transformation step as a single Python function, with the following rules:</p><ol><li><p>The name of the function corresponds to the output variable it computes.</p></li><li><p>The parameter names (and types) correspond to inputs. These can be either passed-in parameters or names of other upstream functions.</p></li></ol><p>This approach allows you to represent your data in ways that correspond closely to code, are naturally self-documenting, and portable across infrastructure.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Q1CW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Q1CW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 424w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 848w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 1272w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png" width="1456" height="832" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:832,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Q1CW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 424w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 848w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 1272w, https://substackcdn.com/image/fetch/$s_!Q1CW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63bcced0-3c4c-43e7-bfb1-96a9c52efa0b_1585x906.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>After writing your functions (assets), you write a driver that executes them &#8211; in most cases this is a simple import/run (specifying the assets you want computed and letting the framework do the rest), but it provides options to customize execution:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HYEh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HYEh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 424w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 848w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 1272w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HYEh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png" width="1450" height="434" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:434,&quot;width&quot;:1450,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165972,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HYEh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 424w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 848w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 1272w, https://substackcdn.com/image/fetch/$s_!HYEh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa0bc4970-559b-4cc8-8918-56d5a188d399_1450x434.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/c5f46a612bf498d3100936b84d693ea3#file-hamilton_1-py">gist</a></figcaption></figure></div><p>Hamilton has a <a href="https://hamilton.dagworks.io/en/latest/how-tos/use-in-jupyter-notebook/">notebook integration</a> that we&#8217;ll be using in our post, allowing you to define your modules in a cell and reference them in drivers later. You can do this with the <code>%%cell_to_module</code> command, which will update a variable with a module pointer and plot the dataflow defined by the module.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HJ9w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HJ9w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 424w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 848w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 1272w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png" width="1438" height="428" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:428,&quot;width&quot;:1438,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:153080,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HJ9w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 424w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 848w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 1272w, https://substackcdn.com/image/fetch/$s_!HJ9w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F862e9ac1-e2cf-456b-8049-bd9d7e1c8593_1438x428.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/5453a717e2807ce592cc11ba1cfd1148#file-cell_to_module-py">gist</a></figcaption></figure></div><p>Once you define your module, you will have access to the module pointer as a variable with the name of the module, allowing you to build the driver, just as we did above. See <a href="https://medium.com/@thijean/the-perks-of-creating-dataflows-with-hamilton-36e8c56dd2a">this post</a> for more information on how the integration works.</p><h1>Modeling Due Dates</h1><p>While the underlying probability distribution of delivery is actually very complicated and not well known, according to <a href="https://datayze.com/labor-probability-chart">dataayze</a> (the source for a lot of this post), a skewed-normal distribution is a reasonable representation. The due date is roughly the median, and the left-flank is longer tailed (5th percentile is 4 weeks before the due date, 95th percentile is 2 weeks after). A skewed-normal distribution has three parameters.&nbsp;</p><p>The first two are the same a standard normal distribution, although they have different meanings</p><ul><li><p>loc &#8211; where the curve is shifted (note due to skewness this is *not* the center of mass)</p></li><li><p>scale &#8211; standard deviation. How wide the curve is.</p></li></ul><p>The final parameter is called &#8220;skewness&#8221; (<em>a </em>in the code below) &#8211; this is how lopsided the curve is. To demonstrate, you can see how the probability density function varies based on the skewness parameter for a simple standard normal distribution centered around 0 with scale of 1.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qVOi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qVOi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png 424w, https://substackcdn.com/image/fetch/$s_!qVOi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png 848w, https://substackcdn.com/image/fetch/$s_!qVOi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png 1272w, https://substackcdn.com/image/fetch/$s_!qVOi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qVOi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png" width="979" height="584" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:584,&quot;width&quot;:979,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qVOi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png 424w, https://substackcdn.com/image/fetch/$s_!qVOi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png 848w, https://substackcdn.com/image/fetch/$s_!qVOi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png 1272w, https://substackcdn.com/image/fetch/$s_!qVOi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ff9005-74e4-4267-b172-d5b5effce5c4_979x584.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Skewness varied between a=1&#8594;10. Note that negative numbers will mirror these on the other side of the axis.</figcaption></figure></div><p>Once we have the right parameters, we should be able to map the calendar dates to the input and use the probability density function (PDF) to calculate probability of delivery *on* a due-date, as well as the cumulative density function (CDF) to calculate the probability of delivery *before* a due date. Simple, right? Almost &#8211; there are two wrinkles:</p><ol><li><p>We don&#8217;t have the parameters, and they&#8217;re weirdly hard to find (in fact, the papers that everyone cites (<a href="https://sci-hub.se/https://doi.org/10.3109/00016349009028681">duration of human singleton pregnancy</a> and <a href="https://link.springer.com/article/10.1007/s00404-016-4153-3">gestational length assignment &#8230;</a>) don&#8217;t represent it as a skewed distribution and instead attempt to estimate the mean/std dev.</p></li><li><p>There are two other factors we need to account for</p><ol><li><p>Given that today is July 14th, the probability of delivering prior to today is zero. So, the probabilities for future dates will change (increase &#8211; they all have to sum to one, and we cut out a big chunk)</p></li><li><p>Gestation is generally not considered safe post 42 weeks &#8211; current medical practice will almost always induce after that.&nbsp;</p></li></ol></li></ol><p>While (1) would be solved in a better way by finding the data and doing our own analysis (or, asking the author of that website nicely), we&#8217;re going to go with maximum effort! We&#8217;ll go over how we solve these problems in the code.</p><h2>Computing with Hamilton</h2><h3>Determining Model Parameters</h3><p>Recall we didn&#8217;t actually know the parameters to the model? Let&#8217;s figure them out! We&#8217;re going to use the data here: <a href="https://datayze.com/labor-probability-chart">https://datayze.com/labor-probability-chart</a> and reverse engineer what they did (we also reached out for their parameters to compare our results). This part is classic ugly data parsing, that through Hamilton is well organized into functions &#8211; we won&#8217;t dig too much into the code, but at a high-level, we will:</p><ol><li><p>Copy/paste the probability data into our notebook in the raw_data function</p></li><li><p>Compute the raw probabilities, using a lot of funky string parsing (avoiding regexes at all cost)</p></li><li><p>Resample by generating a reservoir of data with 1000 total items (this is clean as the probabilities in the chart had it down to .1% granularity)</p></li><li><p>Fit to scipy.stats.skewnorm()</p></li></ol><p>Why the roundabout manner with sampling? Well, really, it&#8217;s not the right way to do things. We should be using <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html">curve_fit</a> (or some similar capability), or even analytically solve it. That&#8217;s hard, but the <em>scipy.stats.skewnorm.fit()</em> function is easy, and it gets us close enough.</p><p>The DAG to compute the parameters looks like this &#8211; we&#8217;ve broken out scale, a, and loc using @<a href="https://hamilton.dagworks.io/en/latest/reference/decorators/extract_fields/">extract_fields</a>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6eHo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6eHo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png 424w, https://substackcdn.com/image/fetch/$s_!6eHo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png 848w, https://substackcdn.com/image/fetch/$s_!6eHo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png 1272w, https://substackcdn.com/image/fetch/$s_!6eHo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6eHo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png" width="1456" height="690" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:690,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6eHo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png 424w, https://substackcdn.com/image/fetch/$s_!6eHo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png 848w, https://substackcdn.com/image/fetch/$s_!6eHo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png 1272w, https://substackcdn.com/image/fetch/$s_!6eHo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ad0a918-cd17-478b-86ea-6d2d1f43a675_1600x758.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">The DAG to compute the probability distributions. Note we extract the three fields that represent a skewed normal, and also create the distribution object itself.</figcaption></figure></div><p>We can run this code as follows:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_wcO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_wcO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png 424w, https://substackcdn.com/image/fetch/$s_!_wcO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png 848w, https://substackcdn.com/image/fetch/$s_!_wcO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png 1272w, https://substackcdn.com/image/fetch/$s_!_wcO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_wcO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png" width="1442" height="128" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:128,&quot;width&quot;:1442,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:36318,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_wcO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png 424w, https://substackcdn.com/image/fetch/$s_!_wcO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png 848w, https://substackcdn.com/image/fetch/$s_!_wcO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png 1272w, https://substackcdn.com/image/fetch/$s_!_wcO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb860d31-1638-487f-97cb-9499f4bd3264_1442x128.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/8e0f02f1877810dec551b5b879734a58">gist</a></figcaption></figure></div><p>Which gives us the following parameters:</p><pre><code>{
 <strong>"a"</strong>: -4.186168447183817,
 <strong>"scale"</strong>: 20.670154416450384,
 <strong>"loc"</strong>: 294.44465059093034
}
This yields a pretty intuitive set of density functions:</code></pre><p>This yields a pretty intuitive set of density functions:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Z7d0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Z7d0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png 424w, https://substackcdn.com/image/fetch/$s_!Z7d0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png 848w, https://substackcdn.com/image/fetch/$s_!Z7d0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png 1272w, https://substackcdn.com/image/fetch/$s_!Z7d0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Z7d0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png" width="1456" height="559" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Z7d0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png 424w, https://substackcdn.com/image/fetch/$s_!Z7d0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png 848w, https://substackcdn.com/image/fetch/$s_!Z7d0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png 1272w, https://substackcdn.com/image/fetch/$s_!Z7d0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfa2b0fa-2ab0-4184-b29a-7cb12bd499c6_1600x614.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Again note that while 40 days is the median, the mode is actually around 41 weeks. This also looks close to the data in the website, meaning we&#8217;ve reverse-engineered the distribution correctly!</p><h3>Managing Dates</h3><p>Before we get around to computing probabilities using the model above, let&#8217;s set up a few date-related variables we can use. In this case, we will model the due date from the start date (the first day of the mother&#8217;s period), an input to our dataflow. The due date is defined as 40 weeks past the start_date (a 9-month gestation period + a full cycle).&nbsp;</p><p>We restrict our calculation down to just a smaller set of dates (8 weeks before and 4 weeks after), largely to make the data sane. Thus we have possible_dates, which will form the &#8220;spine&#8221; (common index) for the rest of the data: </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mjnK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mjnK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png 424w, https://substackcdn.com/image/fetch/$s_!mjnK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png 848w, https://substackcdn.com/image/fetch/$s_!mjnK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png 1272w, https://substackcdn.com/image/fetch/$s_!mjnK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mjnK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png" width="1434" height="880" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:880,&quot;width&quot;:1434,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:184560,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mjnK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png 424w, https://substackcdn.com/image/fetch/$s_!mjnK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png 848w, https://substackcdn.com/image/fetch/$s_!mjnK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png 1272w, https://substackcdn.com/image/fetch/$s_!mjnK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1cb13d44-f2ad-41cd-8dbe-a9dc179f5f15_1434x880.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://github.co/hiddenchars">gist</a></figcaption></figure></div><p>This code presents the following (simple) DAG:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WS0L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WS0L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png 424w, https://substackcdn.com/image/fetch/$s_!WS0L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png 848w, https://substackcdn.com/image/fetch/$s_!WS0L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png 1272w, https://substackcdn.com/image/fetch/$s_!WS0L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WS0L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png" width="1422" height="458" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:458,&quot;width&quot;:1422,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WS0L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png 424w, https://substackcdn.com/image/fetch/$s_!WS0L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png 848w, https://substackcdn.com/image/fetch/$s_!WS0L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png 1272w, https://substackcdn.com/image/fetch/$s_!WS0L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F955edc3c-d785-4ac9-a083-cbb8450adb14_1422x458.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Computing Probabilities</h3><p>Now that we have the base model as well as our dates, let&#8217;s actually calculate the probabilities. First we&#8217;re going to compute over a larger date range (0-&gt;365 days), which we will later truncate. We create a scipy <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html">rv_continuous</a> object that allows us to compute the density functions we want. We then do some adjustments to model our initial assumptions &#8211; both the current date and the induction date:</p><p>This is the meat of the code &#8211; we do two adjustments:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kEkW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kEkW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png 424w, https://substackcdn.com/image/fetch/$s_!kEkW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png 848w, https://substackcdn.com/image/fetch/$s_!kEkW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png 1272w, https://substackcdn.com/image/fetch/$s_!kEkW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kEkW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png" width="1444" height="1050" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/acb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1050,&quot;width&quot;:1444,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:242684,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kEkW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png 424w, https://substackcdn.com/image/fetch/$s_!kEkW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png 848w, https://substackcdn.com/image/fetch/$s_!kEkW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png 1272w, https://substackcdn.com/image/fetch/$s_!kEkW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Facb2f818-9d14-4886-828a-6743f913e0a1_1444x1050.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/992e8378c78bd77a23916e899ea89149">gist</a></figcaption></figure></div><ol><li><p>We truncate to past the current date (if specified), and readjust the probabilities to sum to 1)</p></li><li><p>We truncate after the &#8220;induction date&#8221; (defaults to two weeks post due-date), and add the entire mass to the induction date</p></li></ol><p>While there are obviously a few simplifying assumptions (fixed induction date, quantized date set, etc&#8230;), this is a pretty reasonable model.</p><p>Next all we need to do is compute the cdf with a cumsum() operation (note we&#8217;re not using the rv_continous cdf() capability as we transformed the probability distribution into a discrete function with different values and cumsum() will work just fine. While we could define our own rv_continous variable, the discrete modeling here is a simple, debuggable approach. We truncate our distribution function series to have the right range, and return them as our final variables:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!s-4A!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!s-4A!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png 424w, https://substackcdn.com/image/fetch/$s_!s-4A!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png 848w, https://substackcdn.com/image/fetch/$s_!s-4A!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png 1272w, https://substackcdn.com/image/fetch/$s_!s-4A!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!s-4A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png" width="1432" height="438" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:438,&quot;width&quot;:1432,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:223020,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!s-4A!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png 424w, https://substackcdn.com/image/fetch/$s_!s-4A!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png 848w, https://substackcdn.com/image/fetch/$s_!s-4A!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png 1272w, https://substackcdn.com/image/fetch/$s_!s-4A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20697a93-5a17-4308-90a6-d14fde8be320_1432x438.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/7ce716ceb2632fb2ecb991b92e85cf0e">gist</a></figcaption></figure></div><p>Finally, we can build the driver and use it to return a dataframe &#8211; in this case we&#8217;re using the <a href="https://hamilton.dagworks.io/en/latest/reference/result-builders/Pandas/">PandasDataFrameResult</a> result builder, which handles joining for us.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mbag!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mbag!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png 424w, https://substackcdn.com/image/fetch/$s_!mbag!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png 848w, https://substackcdn.com/image/fetch/$s_!mbag!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png 1272w, https://substackcdn.com/image/fetch/$s_!mbag!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mbag!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png" width="1438" height="700" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:700,&quot;width&quot;:1438,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:120088,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mbag!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png 424w, https://substackcdn.com/image/fetch/$s_!mbag!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png 848w, https://substackcdn.com/image/fetch/$s_!mbag!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png 1272w, https://substackcdn.com/image/fetch/$s_!mbag!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1a747d8e-bfd8-4b53-bc77-7a5ddeb34a33_1438x700.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/b2564226e14fdac1d7a9fef129d42525#file-driver-py">gist</a></figcaption></figure></div><p>Voila! We have our final results.</p><h2>Analyzing the Results</h2><p>Let&#8217;s take a look at what we produced. Using a simple seaborn plot (code in example, left out for now), we can see the following distributions.&nbsp;</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JV6i!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JV6i!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png 424w, https://substackcdn.com/image/fetch/$s_!JV6i!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png 848w, https://substackcdn.com/image/fetch/$s_!JV6i!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png 1272w, https://substackcdn.com/image/fetch/$s_!JV6i!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JV6i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png" width="1456" height="560" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:560,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JV6i!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png 424w, https://substackcdn.com/image/fetch/$s_!JV6i!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png 848w, https://substackcdn.com/image/fetch/$s_!JV6i!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png 1272w, https://substackcdn.com/image/fetch/$s_!JV6i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f825876-b246-4ed8-acf6-554220e329b6_1600x615.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>At this point in the pregnancy, it is quite likely that the baby will come late. The mode (obviously) its induction on august 1st, with a 12% chance of that happening. The median is around the 22nd (a week late).&nbsp;&nbsp;&nbsp;</p><p>The probability distribution above has no name (of which I&#8217;m aware, although the shape is suspiciously close to a common birthing position), but it tells an interesting story. And, it changes every day! Rerun each morning to get your new conditional probabilities.</p><p>We can also visualize this in a calendar using the builtin <a href="https://docs.python.org/3/library/calendar.html">calendar library in python</a>, a tool that enables us to format calendars and perform various calendar-related operations. In this case we&#8217;re going to be customizing it heavily &#8211; subclassing the HTMLCalendar to allow for highlighting of certain days with a scale:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yLYm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yLYm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png 424w, https://substackcdn.com/image/fetch/$s_!yLYm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png 848w, https://substackcdn.com/image/fetch/$s_!yLYm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png 1272w, https://substackcdn.com/image/fetch/$s_!yLYm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yLYm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png" width="716" height="1097" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1097,&quot;width&quot;:716,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:175210,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yLYm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png 424w, https://substackcdn.com/image/fetch/$s_!yLYm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png 848w, https://substackcdn.com/image/fetch/$s_!yLYm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png 1272w, https://substackcdn.com/image/fetch/$s_!yLYm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9b441c2-033c-46e7-b685-016453fdb60a_716x1097.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">Corresponding <a href="https://gist.github.com/elijahbenizzy/c8768692d2d6c1016ea9b0de5d3e6d11">gist</a></figcaption></figure></div><p>When we run <code>view_date_range</code> on our data, we get the following:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TFm0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TFm0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png 424w, https://substackcdn.com/image/fetch/$s_!TFm0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png 848w, https://substackcdn.com/image/fetch/$s_!TFm0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png 1272w, https://substackcdn.com/image/fetch/$s_!TFm0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TFm0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png" width="1456" height="286" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:286,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TFm0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png 424w, https://substackcdn.com/image/fetch/$s_!TFm0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png 848w, https://substackcdn.com/image/fetch/$s_!TFm0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png 1272w, https://substackcdn.com/image/fetch/$s_!TFm0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74817162-dba9-4fc3-83ca-7b3a4fdc29c8_1600x314.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The real reason I&#8217;m doing all of this, is, however, because I want to know the probability that my baby shares a birthday with me! 5% is low, but stranger things than 1/20 have happened.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sSB0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sSB0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png 424w, https://substackcdn.com/image/fetch/$s_!sSB0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png 848w, https://substackcdn.com/image/fetch/$s_!sSB0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png 1272w, https://substackcdn.com/image/fetch/$s_!sSB0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sSB0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png" width="1072" height="222" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:222,&quot;width&quot;:1072,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sSB0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png 424w, https://substackcdn.com/image/fetch/$s_!sSB0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png 848w, https://substackcdn.com/image/fetch/$s_!sSB0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png 1272w, https://substackcdn.com/image/fetch/$s_!sSB0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42feddb2-324f-4033-a771-37f6e2e893cb_1072x222.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h2>Notes on Workflow, and Future Reading</h2><p>All this to determine a 5% probability? Well, the end result doesn&#8217;t really tell us much (but hey, it&#8217;s a probability distribution, so we&#8217;re speaking in possibilities and unknowns anyway). Furthermore, this probably could have been a simpler notebook (avoiding the use of Hamilton all together).&nbsp;</p><p>That said, Hamilton made me a lot more productive building this, despite the fact that I was adhering to the rules of a specific framework. I got this productivity gain from the following:</p><ol><li><p>I never worried about notebook state &#8211; I had visualizations, and it would recompute whatever needs to be (no changing variable names and accidentally attempting to use them)</p></li><li><p>I was able to work iteratively &#8211; using the Jupyter notebook extensions I can do the following routine</p><ol><li><p>Compute a variable</p></li><li><p>Play around with it until I&#8217;m happy</p></li><li><p>Tab that cell in (b) in and surround it with a function, put it into the module</p></li><li><p>Repeat until I&#8217;m happy</p></li></ol></li><li><p>I get to see the visualization at any point &#8211; I can pretty easily figure out what&#8217;s happening, what a variable means (that I forgot), etc&#8230;</p></li><li><p>I get code out at the end that&#8217;s modular, broken up into functions, and easy to navigate!</p></li></ol><p>This was a toy example. In the real world, there would be a lot more analysis, a lot more spot-checking, and a much more complex set of assumptions to navigate. And that&#8217;s where Hamilton really shines &#8211; at every stage you&#8217;ll have a production-ready ETL to work with. With the Jupyter notebook extension you can even use the -w flag with the %%cell_to_module magic to write your module to a file as you&#8217;re editing! This enables you to use the notebook as both a notebook and an IDE.</p><h2>Learn More</h2><p>If you&#8217;re excited by any of this, or have strong opinions, drop by our Slack channel / leave some comments here! Some resources to help you get started:</p><p>&#128227;<a href="https://join.slack.com/t/hamilton-opensource/shared_invite/zt-1bjs72asx-wcUTgH7q7QX1igiQ5bbdcg"> join our Hamilton community on Slack</a>&#8202;&#8212;&#8202;need help with Hamilton? Ask here.</p><p>&#11088;<a href="https://github.com/dagworks-inc/hamilton"> give hamilton a star on github</a></p><p>&#128221;<a href="https://github.com/DAGWorks-Inc/hamilton/issues"> open an issue if you find any bugs/want new features</a></p><p>We recently launched<a href="https://github.com/dagworks-inc/burr">Burr to create LLM agents and applications</a> as well.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.dagworks.io/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading DAGWorks&#8217;s Substack! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>