Agents

Programming with LLMs in R and Python

posit::conf(2026)

2026-09-14

Agents

What’s an agent?

  • An LLM, in a harness, that calls tools repeatedly in a loop

  • Deciding each next step from the last result

How many tools does it take
to make an agent?

Did we just make a quiz game agent?

What kind of tools?

  • read tools to observe the world

  • write tools to change it

The agent loop

  • 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

Brainstorm: tools for agents

Read tools

  • Read a file

Write tools

  • Write a file

Oh, and prompting!

Welcome to the Last Blockbuster

  • 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.

Your Turn 19_agent-1

  1. Your agent works in the Last Blockbuster’s records folder.

  2. Wrap up a read tool and a write tool for it to use, then ask it to build the win-back list.

  3. Run the script it writes, then inspect the trace. Did it read the store rules before it wrote code?

Discussion: Did your agent…?

  • 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?

Your Turn 20_agent-2

  1. Give your agent a list files tool and an edit tool.

  2. Build the win-back list script again. Do these tools make your agent more effective?

  3. Your manager found an old paper register!

  4. Without naming the file, ask the agent to bring the list up to date.

Discussion: Did your agent…?

  • 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?

Agents, recap

  • 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