Skip to content

feat: Add tool_reject() - #490

Merged
gadenbuie merged 6 commits into
tidyverse:mainfrom
gadenbuie:feat/tool-reject
May 9, 2025
Merged

gadenbuie merged 6 commits into
tidyverse:mainfrom
gadenbuie:feat/tool-reject

Conversation

@gadenbuie

@gadenbuie gadenbuie commented May 9, 2025 •

Copy link
Copy Markdown
Collaborator

Adds a new helper function tool_reject() that can be used to reject a tool call. It's a small wrapper around a classed error.

tool_reject()
#> Error in `tool_reject()`:
#> ! Tool call rejected. The user has chosen to disallow the tool call.

tool_reject("Timed out while waiting for user response")
#> Error in `tool_reject()`:
#> ! Tool call rejected. Timed out while waiting for user response

In the current PR, tool_reject() can be called from a tool function and is treated like any other error, with the advantage of communicating the tool rejection through the error message.

When tool_request callbacks are availble (#401), tool_reject() will be used to prevent the tool function from being called.

@gadenbuie
gadenbuie marked this pull request as ready for review May 9, 2025 15:03
@gadenbuie
gadenbuie requested a review from hadley May 9, 2025 15:06
Comment thread R/tools-def.R Outdated
Comment thread R/tools-def.R Outdated
gadenbuie and others added 2 commits May 9, 2025 13:18
Co-authored-by: Hadley Wickham <hadley@posit.co>
@gadenbuie
gadenbuie merged commit 899fd15 into tidyverse:main May 9, 2025
@gadenbuie
gadenbuie deleted the feat/tool-reject branch May 9, 2025 17:25
schloerke added a commit to schloerke/ellmer that referenced this pull request May 15, 2025
* main: (26 commits)
  Drop `completed` (tidyverse#495)
  Add PortkeyAI support (tidyverse#471)
  feat: Adds `stream = "content"` option to `$stream()` and `$stream_async()` (tidyverse#494)
  feat(Chat): `tool_request` and `tool_result` callbacks (tidyverse#493)
  feat: Add `tool_reject()` (tidyverse#490)
  fix: Tweak simple tools test to avoid Claude's empty strings (tidyverse#492)
  feat(chat_async): Adds `tool_mode` to choose between sequential or concurrent tool calling (tidyverse#488)
  And azure :|
  Update snapshot tests; fix bad bedrock model choice
  chore: Remove trailing whitespace from NEWS (tidyverse#489)
  Add (some) functions for listing models (tidyverse#454)
  Move `chat$extract_data_parallel()` to `parallel_chat_structured()` (tidyverse#486)
  refactor: Use generators for tool invocation (tidyverse#487)
  refactor: Remove private invoke_tools methods (tidyverse#485)
  Automatically convert tool inputs (tidyverse#463)
  Allow `$extract_data_parallel()` to return tokens + cost (tidyverse#449)
  Start work on programming vignette (tidyverse#458)
  Revise type coercion (tidyverse#484)
  Tweak `chat_openai_test()` (tidyverse#483)
  refactor(tools): `match_tools()` and `tool_results_as_turn()` (tidyverse#480)
  ...
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.

2 participants