Programming with LLM APIs
A Beginner’s Guide in R and Python
posit::conf(2025)
2025-09-16
A robot wearing a tool belt, selects a tool from a wall of futuristic space tools. A sign above the wall reads “Tools”.
You write some words
The LLM writes some more words
You use those words
On their own, can LLMs… access the internet? send an email? interact with the world?
a.k.a. functions, tool calling or function calling
Bring real-time or up-to-date information to the model
Let the model interact with the world
user vs. programmer
What should I wear to posit::conf(2025) in Atlanta?
👨💻 _demos/18_manual-tools/app.R
👨💻 _demos/19_tools/19_weather-tool.R
👨💻 _demos/19_tools/19_weather-tool.py
20_quiz-game-2I’ve given you a function that plays a sound when called.
Your job: teach the model to play sounds in the Quiz Show game we made earlier today.
You can use your prompt or switch _exercises → _solutions to use ours.
06:00
A robot is standing in front of a display case, pointing at a holographic interface showing various tools and options. The robot appears to be selecting a tool from the interface.
Provide hints to clients about tool behavior
Help humans and AI systems make informed decisions about tool usage
All properties are hints only - not guaranteed to be accurate
| Property | Description |
|---|---|
title |
Human-readable tool name |
readOnlyHint |
Tool doesn’t modify environment |
destructiveHint |
May perform destructive updates |
idempotentHint |
Repeated calls with same arguments return same |
openWorldHint |
Interacts with external entities vs. closed domain |
21_quiz-game-3Add tool annotations to our play_sound tools.
Pick an icon from FontAwesome free icons
08:00
title and icon dynamically in the tool?22_quiz-game-4Pick an icon and a title for each action in the Quiz show app.
Return a ContentToolResult from each tool that sets the icon and title.
Play the game again to see the icons and titles in action.
08:00
Define the tool function inside the server
You can update reactive values in the tool function!
You can read reactive values, if you isolate() reads. (Be careful!)
23_quiz-game-5I’ve updated the app to show the score in value boxes.
(And turned off the sounds.)
In the system prompt, tell the model when to use update_score.
Read update_score(). It should update a reactive value in the app when called. Finish implementing it.
Complete the tool definition.
Add tool annotations (optional, but fun!)
08:00