import%20marimo%0A%0A__generated_with%20%3D%20%220.16.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Setup%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22We%20are%20using%20LiteLLM%20again%2C%20to%20use%20a%20server%20under%20my%20desk%20that%20hosts%20%20%5BQwen3-4B-Instruct-2507%5D(https%3A%2F%2Fhuggingface.co%2FQwen%2FQwen3-4B-Instruct-2507).%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20litellm%0A%20%20%20%20import%20datasets%0A%20%20%20%20import%20datetime%0A%20%20%20%20import%20io%0A%20%20%20%20import%20contextlib%0A%20%20%20%20import%20re%0A%0A%0A%20%20%20%20litellm.api_base%20%3D%20%22http%3A%2F%2Faurora-r11.wg.guha-anderson.com%3A8000%2Fv1%22%0A%20%20%20%20litellm.api_key%20%3D%20%22dummy%22%0A%0A%20%20%20%20_resp%20%3D%20litellm.completion(%0A%20%20%20%20%20%20%20%20%22openai%2Fqwen3%22%2C%0A%20%20%20%20%20%20%20%20messages%3D%5B%7B%22role%22%3A%20%22user%22%2C%20%22content%22%3A%20%22Say%20hello.%22%7D%5D%0A%20%20%20%20)%0A%20%20%20%20_resp.choices%5B0%5D.message.content%0A%20%20%20%20return%20contextlib%2C%20datasets%2C%20datetime%2C%20io%2C%20litellm%2C%20mo%2C%20re%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20The%20Airline%20Agent%20Dataset%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22This%20is%20the%20same%20airline%20agent%20dataset%20that%20we%20had%20the%20last%20time.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(datasets%2C%20datetime)%3A%0A%20%20%20%20flights_dataset%20%3D%20datasets.load_dataset(%22nuprl%2Fengineering-llm-systems%22%2C%20%22flights%22%2C%20split%3D%22train%22)%0A%0A%20%20%20%20def%20parse_date_and_time(item)%3A%0A%20%20%20%20%20%20%20%20%23%20departure_time%20and%20arrival_time%20are%20in%20HH%3AMM%20format.%20Convert%20to%20time%20objects.%0A%20%20%20%20%20%20%20%20item%5B%22departure_time%22%5D%20%3D%20datetime.datetime.strptime(item%5B%22departure_time%22%5D%2C%20%22%25H%3A%25M%22).time()%0A%20%20%20%20%20%20%20%20item%5B%22arrival_time%22%5D%20%3D%20datetime.datetime.strptime(item%5B%22arrival_time%22%5D%2C%20%22%25H%3A%25M%22).time()%0A%20%20%20%20%20%20%20%20%23%20date%20is%20in%20YYYY-MM-DD%20format.%20Convert%20to%20date%20object.%0A%20%20%20%20%20%20%20%20item%5B%22date%22%5D%20%3D%20datetime.datetime.strptime(item%5B%22date%22%5D%2C%20%22%25Y-%25m-%25d%22).date()%0A%20%20%20%20%20%20%20%20return%20item%0A%20%20%20%20flights_dataset%20%3D%20flights_dataset.map(parse_date_and_time)%0A%20%20%20%20flights_dataset.to_pandas()%0A%20%20%20%20return%20(flights_dataset%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20The%20ReAct%20Pattern%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20In%20the%20*ReAct*%20pattern%2C%20we%20define%20several%20tools%20and%20*let%20the%20model%20decide%20which%20tool%20to%20use*.%20In%20addition%2C%20we%20allow%20the%20model%0A%20%20%20%20to%20*observe%20tool%20outputs*%20to%20determine%20if%20it%20needs%20to%20use%20another%20tool%20to%20complete%20the%20task.%20This%20means%20that%20the%20model%20may%20operate%20for%20%0A%20%20%20%20several%20steps%2C%20and%20we%20will%20need%20some%20way%20to%20determine%20if%20its%20done%20or%20has%20run%20for%20too%20long.%20If%20it%20looks%20like%20a%20*while*%20loop%20with%20an%20LLM%20%0A%20%20%20%20call%20in%20the%20middle%2C%20that's%20because%20it%20is.%0A%0A%20%20%20%20To%20demonstrate%20ReAct%2C%20we%20will%20define%20a%20few%20tools.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(datetime%2C%20flights_dataset)%3A%0A%20%20%20%20def%20find_flights(origin%3A%20str%2C%20destination%3A%20str%2C%20date%3A%20datetime.date)%3A%0A%20%20%20%20%20%20%20%20found_any%20%3D%20False%0A%20%20%20%20%20%20%20%20for%20flight%20in%20flights_dataset%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20flight%5B%22origin%22%5D%20!%3D%20origin%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20flight%5B%22destination%22%5D%20!%3D%20destination%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20flight%5B%22date%22%5D%20!%3D%20date%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%0A%20%20%20%20%20%20%20%20%20%20%20%20found_any%20%3D%20True%0A%20%20%20%20%20%20%20%20%20%20%20%20print(f%22Id%3A%20%7Bflight%5B'id'%5D%7D%3A%20%7Bflight%5B'airline'%5D%7D%20%7Bflight%5B'flight_number'%5D%7D%20%20%7Bflight%5B'departure_time'%5D%7D--%7Bflight%5B'arrival_time'%5D%7D%22)%0A%20%20%20%20%20%20%20%20if%20not%20found_any%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22No%20flights%20found.%22)%0A%0A%20%20%20%20def%20available_seats(id%3A%20int)%3A%0A%20%20%20%20%20%20%20%20for%20flight%20in%20flights_dataset%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20flight%5B%22id%22%5D%20%3D%3D%20id%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(flight%5B%22available_seats%22%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%0A%20%20%20%20%20%20%20%20print(%22Not%20a%20valid%20flight.%22)%0A%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20**Tool%20recap**%0A%0A%20%20%20%20-%20%60find_flights%60%20is%20our%20search%20primitive.%20It%20filters%20the%20dataset%20and%20prints%20any%20matching%0A%20%20%20%20%20%20itineraries.%20Because%20it%20prints%20rather%20than%20returns%2C%20the%20agent%20must%20read%20console%20output%20before%0A%20%20%20%20%20%20choosing%20the%20next%20action.%0A%20%20%20%20-%20%60available_seats%60%20accepts%20a%20flight%20%60id%60%20and%20prints%20a%20seat%20count.%20The%20agent%20uses%20it%20after%20it%0A%20%20%20%20%20%20has%20identified%20a%20candidate%20flight.%0A%0A%20%20%20%20Returning%20text%20instead%20of%20structured%20data%20mirrors%20production%20tool%20integrations%20where%20the%20model%0A%20%20%20%20reasons%20over%20plain-language%20observations.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20done%20tool%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20done_messages%20%3D%20%5B%20%5D%0A%0A%20%20%20%20def%20display(message%3A%20str)%3A%0A%20%20%20%20%20%20%20%20done_messages.append(message)%0A%20%20%20%20return%20(done_messages%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20The%20%60display%60%20helper%20captures%20the%20agent's%20final%20response.%20Every%20time%20the%20model%20calls%0A%20%20%20%20%60display(...)%60%2C%20we%20append%20the%20message%20to%20%60done_messages%60.%20The%20outer%20agent%20loop%20watches%20this%0A%20%20%20%20list%20to%20know%20when%20to%20stop%3A%20this%20is%20our%20%22Act%22%20termination%20condition%20that%20hands%20control%20back%20to%20the%20user.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20system%20prompt%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20SYSTEM_PROMPT%20%3D%20%22%22%22%0A%20%20%20%20You%20are%20an%20airline%20chatbot%20interacting%20with%20a%20flight%20database%20and%20a%20user.%20You%20can%20write%20code%0A%20%20%20%20that%20uses%20these%20functions%20to%20interact%20with%20the%20database.%0A%0A%20%20%20%20The%20find_flights%20function%3A%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20def%20find_flights(origin%3A%20str%2C%20destination%3A%20str%2C%20departure_date%3A%20datetime.date)%3A%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20takes%20the%20origin%20and%20destination%20airport%20codes.%20And%20prints%20the%20flights%20it%20finds%2C%20with%0A%20%20%20%20ID%2C%20airline%20flight%20number%2C%20departure--arrival%20time.%0A%0A%20%20%20%20The%20available_seats%20function%3A%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20def%20available_seats(id%3A%20int)%3A%0A%20%20%20%20%60%60%60%0A%20%20%20%20Prints%20the%20number%20of%20available%20seats%20on%20a%20flight.%0A%0A%20%20%20%20The%20display%20function%20displays%20a%20message%20to%20the%20user.%20Use%20display%20when%20you%20are%20done%0A%20%20%20%20answering%20the%20query%3A%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20def%20display(message%3A%20str)%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20Don't%20import%20anything%20and%20don't%20define%20helpers.%20Do%20not%20simulate%20data.%20I%20will%0A%20%20%20%20run%20your%20code%20on%20my%20data.%0A%0A%20%20%20%20Today%20is%20Jan%201%202023.%0A%20%20%20%20%22%22%22%0A%0A%20%20%20%20PROMPT_PREFIX%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%7B%20%22role%22%3A%20%22system%22%2C%20%0A%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20SYSTEM_PROMPT%20%7D%2C%0A%20%20%20%20%20%20%20%20%23%20Example%201%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22user%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22Can%20I%20get%20a%20flight%20from%20SFO%20to%20BOS%20tomorrow%20or%20day-after%3F%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22assistant%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22%22%22I%20will%20use%20find_flights%20to%20first%20search%20for%20a%20flight%20tomorrow.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20find_flights(%22SFO%22%2C%20%22BOS%22%2C%20datetime.date(2023%2C%201%2C%202))%0A%20%20%20%20%60%60%60%22%22%22%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22user%22%2C%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22%22%22The%20result%20was%3A%0A%0A%20%20%20%20Id%2042%3A%20Delta%20DL111%20%2003%3A51%3A00--05%3A51%3A00%22%22%22%20%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%20%22role%22%3A%20%22assistant%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22%22%22There%20is%20a%20Delta%20flight%20(id%2042)%20tomorrow.%20Let's%20see%20if%20it%20has%20available%20seats.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20available_seats(42)%0A%20%20%20%20%60%60%60%20%22%22%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22user%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22%22%22The%20result%20was%3A%0A%0A%20%20%20%200%22%22%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22assistant%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22%22%22No%20seats%20on%20that%20flight.%20Let's%20look%20for%20one%20the%20day%20after%20tomorrow.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20find_flights(%22SFO%22%2C%20%22BOS%22%2C%20datetime.date(2023%2C%201%2C%203))%0A%20%20%20%20%60%60%60%22%22%22%20%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22user%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22%22%22The%20result%20was%3A%0A%0A%20%20%20%20Id%2045%3A%20United%20UA222%20%2006%3A00%3A00--08%3A00%3A00%0A%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22assistant%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22%22%22There%20is%20a%20United%20flight%20(id%2045)%20the%20day%20after%20tomorrow.%20Let's%20see%20if%20it%20has%20available%20seats.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20available_seats(45)%0A%20%20%20%20%60%60%60%22%22%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22user%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22%22%22The%20result%20was%3A%0A%0A%20%20%20%2010%22%22%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22role%22%3A%20%22assistant%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22content%22%3A%20%22%22%22Great!%20There%20are%2010%20available%20seats%20on%20that%20flight.%20I%20am%20done%20and%20will%20let%20the%20user%0A%20%20%20%20%20%20%20%20%20%20know.%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20display(%22Yes%2C%20United%20222%20from%20SFO%20to%20BOS%20the%20day%20after%20tomorrow%20on%20United%20with%2010%20available%20seats.%20Unfortunately%2C%20nothing%20is%20available%20on%20the%20Delta%20flight%20tomorrow.%22)%0A%20%20%20%20%60%60%60%22%22%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%0A%0A%0A%20%20%20%20%5D%0A%20%20%20%20return%20(PROMPT_PREFIX%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20The%20%60SYSTEM_PROMPT%60%20limits%20the%20agent's%20behavior%3A%20no%20imports%2C%20only%20our%20tools%2C%20and%20the%20calendar%0A%20%20%20%20date%20is%20fixed.%20The%20%60PROMPT_PREFIX%60%20then%20provides%20a%20worked%20ReAct%20example%20so%20the%20model%20gets%20a%0A%20%20%20%20template%20for%20planning%20tool%20calls%2C%20observing%20their%20outputs%2C%20and%20finishing%20with%20%60display(...)%60.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(JFK%2C%20PROMPT_PREFIX%2C%20contextlib%2C%20done_messages%2C%20io%2C%20litellm%2C%20re)%3A%0A%20%20%20%20def%20extract_code_from_markdown(markdown_text%3A%20str)%3A%0A%20%20%20%20%20%20%20%20%23%20Look%20for%20code%20blocks%20in%20the%20markdown%20text%0A%20%20%20%20%20%20%20%20code_blocks%20%3D%20re.findall(r'%60%60%60(%3F%3Apython)%3F(.*%3F)%60%60%60'%2C%20markdown_text%2C%20re.DOTALL)%0A%0A%20%20%20%20%20%20%20%20%23%20If%20no%20code%20blocks%20found%2C%20return%20empty%20string%0A%20%20%20%20%20%20%20%20if%20not%20code_blocks%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20None%0A%0A%20%20%20%20%20%20%20%20return%20%22%5Cn%22.join(code_blocks)%0A%20%20%20%20%20%20%20%20JFK%0A%20%20%20%20def%20run_query(messages%3A%20list)%3A%0A%20%20%20%20%20%20%20%20%23%20print(messages)%0A%20%20%20%20%20%20%20%20resp%20%3D%20litellm.completion(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22openai%2Fqwen3%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20messages%3Dmessages%0A%20%20%20%20%20%20%20%20).choices%5B0%5D.message.content%0A%20%20%20%20%20%20%20%20messages.append(%7B%22role%22%3A%20%22assistant%22%2C%20%22content%22%3A%20resp%7D)%0A%20%20%20%20%20%20%20%20%23%20print(f%22Response%3A%20%7Bresp%7D%22)%0A%20%20%20%20%20%20%20%20code%20%3D%20extract_code_from_markdown(resp)%0A%20%20%20%20%20%20%20%20print(%22-%22%20*%2080)%0A%20%20%20%20%20%20%20%20print(resp)%0A%20%20%20%20%20%20%20%20if%20code%20is%20None%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20None%0A%20%20%20%20%20%20%20%20with%20io.StringIO()%20as%20buf%2C%20contextlib.redirect_stdout(buf)%3A%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20exec(code)%0A%20%20%20%20%20%20%20%20%20%20%20%20output%20%3D%20buf.getvalue()%0A%20%20%20%20%20%20%20%20print(output)%0A%20%20%20%20%20%20%20%20return%20output%0A%0A%0A%20%20%20%20def%20agent(user_query%3A%20str)%20-%3E%20str%3A%0A%20%20%20%20%20%20%20%20done_messages.clear()%0A%20%20%20%20%20%20%20%20messages%20%3D%20PROMPT_PREFIX%20%2B%20%5B%7B%22role%22%3A%20%22user%22%2C%20%22content%22%3A%20user_query%7D%5D%0A%20%20%20%20%20%20%20%20first_run%20%3D%20True%0A%20%20%20%20%20%20%20%20while%20first_run%20or%20len(done_messages)%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20first_run%20%3D%20False%0A%20%20%20%20%20%20%20%20%20%20%20%20code_output%20%3D%20run_query(messages)%0A%20%20%20%20%20%20%20%20%20%20%20%20messages.append(%7B%22role%22%3A%20%22user%22%2C%20%22content%22%3A%20f%22The%20result%20was%3A%5Cn%5Cn%7Bcode_output%7D%22%7D)%0A%0A%20%20%20%20%20%20%20%20print(%22%5Cn%22.join(done_messages))%0A%20%20%20%20return%20(agent%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20The%20agent%20loop%20glues%20ReAct%20together%3A%0A%0A%20%20%20%20-%20Build%20the%20conversation%20with%20the%20prefix%20%2B%20new%20user%20query.%0A%20%20%20%20-%20Call%20%60run_query%60%2C%20which%20sends%20everything%20to%20Qwen%20and%20executes%20any%20returned%20code%20block.%0A%20%20%20%20-%20Append%20the%20observed%20output%20as%20a%20new%20user%20turn%20so%20the%20model%20can%20reason%20over%20the%20result.%0A%20%20%20%20-%20Repeat%20until%20the%20model%20calls%20%60display(...)%60%2C%20which%20populates%20%60done_messages%60%20and%20breaks%20the%0A%20%20%20%20%20%20loop.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20**Demo%3A%20Boston-Newark%20over%20two%20days**%0A%0A%20%20%20%20The%20agent%20explores%20two%20consecutive%20days%2C%20reads%20the%20printed%20flight%20options%2C%20and%20stops%0A%20%20%20%20once%20%60available_seats%60%20confirms%20there%20is%20room.%20Notice%20how%20the%20conversation%20history%20preserves%20the%0A%20%20%20%20earlier%20findings%2C%20so%20the%20agent%20does%20not%20lose%20track%20of%20previous%20tool%20calls.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(agent)%3A%0A%20%20%20%20agent(%22Search%20for%20flights%20from%20Boston%20to%20EWR%20tomorrow%20or%20day-after.%20Get%20me%20the%20first%20that%20has%20available%20seats.%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20**Layovers**%0A%0A%20%20%20%20The%20agent%20can%20reason%20through%20layovers%2C%20including%20whether%20the%20connections%20make%20sense.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(agent)%3A%0A%20%20%20%20agent(%22Can%20I%20get%20from%20BOS%20to%20ORD%20tomorrow%20with%20a%20layover%20in%20EWR%3F%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
12db18c08b610ab466b34831f324b9a0befe7ece1091e4f5d5ded8be8493b436