Tools in a Loop
◯ [tool call] run_r_code(code = "babynames %>% filter(year == 1995,
sex == \"F\") %>% slice_max(n, n = 1) %>% select(name, n)")
● #> # A tibble: 1 × 2
#> name n
#> <chr> <int>
#> 1 Jessica 27935
The most popular girls' name in 1995 was Jessica, given to 27,935
baby girls.
How many requests did that one
$chat()send?
With a neighbor: what does the model need to find out? Write down each tool call you expect, in order. How many requests will this send?
01:30
◯ [tool call] run_r_code(code = "babynames %>% filter(year == 1996,
sex == \"F\") %>% slice_max(n, n = 1) %>% select(name, n)")
● #> # A tibble: 1 × 2
#> name n
#> <chr> <int>
#> 1 Emily 25151
◯ [tool call] run_r_code(code = "babynames %>% filter(year == 1996,
sex == \"F\", name == \"Jessica\") %>% select(name, n)")
● #> # A tibble: 1 × 2
#> name n
#> <chr> <int>
#> 1 Jessica 24194
No. In 1996, Emily took the top spot with 25,151 births, and
Jessica dropped to second with 24,194.
How many requests this time? Who decided when to stop?
Roughly what $chat() does each time you call it:
Agent
A model, a set of tools, and a loop. The client sends a request, runs any tools the model asks for, and sends back the results, until the model answers in text.
| Tool | What it does |
|---|---|
read, ls, search |
Reads and finds files in your folder |
executeCode |
Runs R in your R session |
bash |
Runs a shell command |
edit, write |
Changes or creates a file |
AskUser |
Asks you a question |
AGENTS.md, if your folder has one@AGENTS.mdA file of instructions in your project folder, sent with every request:
Which line would have fixed Wednesday’s
%>%?
| Mode | Tool calls |
|---|---|
| Ask | Reads and searches only. Shows you code to run yourself. |
| Normal | Asks you before it runs code or edits a file. |
| Auto | A second model rates each call’s risk, and asks you only when it judges it should. |
| Plan | Reads only, writes a plan, and waits for your OK. |
| Cleaning | Audits a data set and asks you each cleaning decision. Monday. |
Mode
The client’s rule for which tool calls run without asking you. The model only requests calls; the mode decides which ones the client runs on its own.
Which girl's name was given most often in 1995,
and was it still the top name in 1996?
Normal mode. Before each Approve:
Trace
The record of an agent’s work: each request, the tool calls the model asked for with their arguments, and the results the client sent back.
In ellmer, print the chat object. In Posit Assistant, export the conversation as JSON.
◯ [tool call] run_r_code(code = "babynames %>% filter(year == 1996,
sex == \"F\") %>% slice_max(n, n = 1) %>% select(name, n)")
● #> 1 Emily 25151
◯ [tool call] run_r_code(code = "babynames %>% filter(year == 1996,
sex == \"F\", name == \"Jessica\") %>% select(name, n)")
● #> 1 Jessica 24194
No. In 1996, Emily took the top spot with 25,151 births, and
Jessica dropped to second with 24,194.
Question: for each claim in the last sentence, find the tool result behind it. Is there a claim with no result behind it?
02:00
Paste into Posit Assistant, in Normal mode:
Make a scatterplot of mpg against hp in mtcars with ggplot2.
What relationship does the plot show?
Before it answers: what do you expect the plot to show?
git diff shows every change.An agent is like a giant in the forest: it covers ground in strides you can’t keep up with, but every step leaves a footprint. Follow the footprints (the trace) to see where it really went.
Hand a question from a previous project to Posit Assistant, then check its work:
| Step | Tool call | Result | Claim it supports |
|---|---|---|---|
| 1 | run_r_code: top girls’ name, 1996 |
Emily, 25,151 | “Emily took the top spot with 25,151” |
| 2 |
