Skip to content

Conversation

@simonpcouch
Copy link
Collaborator

Closes #889.

  library(ellmer)

# for an example tool that has some non-trivial arguments
library(btw)

client <- chat_openrouter(model = "anthropic/claude-haiku-4.5")
client$set_system_prompt("Be very terse.")
client$register_tool(btw_tool_files_list_files)
client$register_tool(btw_tool_files_code_search)

client$chat("Is there a file in the R directory with util in the name?")
#> ◯ [tool call] btw_tool_files_list_files(path = "R", type = "file", regexp =
#> "util", ...)
#> ● #> | path | type | size | modification_time |
#>   #> |------|------|------|-------------------|
#>   #> | R/chat-utils.R | file | 336 | 2025-11-26 10:14:30 |
#>   #> | R/utils-S7.R | file | 4.71K | 2025-11-26 10:14:30 |
#>   #> | R/utils-auth.R | file | 2.13K | 2025-11-26 10:14:30 |
#>   #> …
#> Yes, there are several files with "util" in the name in the R directory:
#> 
#> - `chat-utils.R`
#> - `utils-S7.R`
#> - `utils-auth.R`
#> - `utils-callbacks.R`
#> - `utils-cat.R`
#> - `utils-coro.R`
#> - `utils-merge.R`
#> - `utils-prettytime.R`
#> - `utils.R`
client$chat("How about util in the contents of any .R files?")
#> ◯ [tool call] btw_tool_files_code_search(term = "util", limit = 100L,
#> case_sensitive = FALSE, ...)
#> ℹ Indexing files in '/Users/simoncouch/Documents/rrr/helperbench/inst/resources…
#> ✔ Indexing files in '/Users/simoncouch/Documents/rrr/helperbench/inst/resources…
#> 
#> ● #> [{"filename":"piny-loon_reprex.spin.R","size":482,"last_modified":"2025-1…
#> Yes, "util" appears in many .R files. Key occurrences include:
#> 
#> - **R/utils-*.R files** (multiple files with "Utility functions" comments)
#> - **utils:: calls** throughout (e.g., `utils::packageVersion()`, 
#> `utils::capture.output()`, `utils::modifyList()`)
#> - **Comments** like "Utilities" and "Utility functions"
#> 
#> The search returned 33 matches across various R files, mostly referencing 
#> utility functions from R's `utils` package or comments describing utility 
#> functionality.

Created on 2025-11-26 with reprex v2.1.1

@hadley
Copy link
Member

hadley commented Nov 27, 2025

Hmmmm, actually would you mind adding a to_json() helper and then using it every where. It looks like this might also affect a couple of other providers.

@simonpcouch simonpcouch requested a review from hadley December 1, 2025 16:07
@simonpcouch simonpcouch merged commit 1a5a25b into main Dec 1, 2025
11 checks passed
@simonpcouch simonpcouch deleted the unbox-889 branch December 1, 2025 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

intermittent failures tool calling with OpenRouter

3 participants