Programming with LLMs in R and Python
posit::conf(2026)
2026-09-14
Agents
An LLM, in a harness, that calls tools repeatedly in a loop
Deciding each next step from the last result
What is an agent? by Hadley Wickham
Did we just make a quiz game agent?
read tools to observe the world
write tools to change it
Explore: the agent reads to understand the world
Act: the agent writes to change it
Observe: the agent reads again to see what changed
…and repeat until the task is done
Read tools
Write tools
You work at the Last Blockbuster in the universe, in Bend, Oregon.
The store runs on its annual membership renewal drive.
Your job is to find members who have gone quiet and win them back.
19_agent-1Your agent works in the Last Blockbuster’s records folder.
Wrap up a read tool and a write tool for it to use, then ask it to build the win-back list.
Run the script it writes, then inspect the trace. Did it read the store rules before it wrote code?
Read README.md and notes.md before it decided anything?
Write a script, instead of reading all 1,500 rentals through its tools?
Say things about the store’s rules that it never actually read?
Would you hand this list to your manager?
If you ran the code: how many lapsed members did it find?
20_agent-2Give your agent a list files tool and an edit tool.
Build the win-back list script again. Do these tools make your agent more effective?
Your manager found an old paper register!
Without naming the file, ask the agent to bring the list up to date.
Write a better find_lapsed script than in the last exercise, even before the export arrived?
Use list_files to find the export, instead of guessing the filename?
Patch the find_lapsed script with edit_file, or rewrite the whole script?
Hit an edit_file error — and was the error loud and safe?
Still get the right answer even when it skipped a tool?
An agent is an LLM, in a harness, calling tools in a loop
Read tools observe; write tools change
The harness does the busy work — you write the tools and the system prompt