Skip to content

Conversation

@lukehinds
Copy link
Contributor

@lukehinds lukehinds commented Jan 25, 2026

What does this PR do?

When using GRPOTrainerwith tools, the trainer generates multiple completions per prompt (num_generations), then executes tool calls for each completion via _tool_call_loop. However, tool callables have no way to know which completion triggered them.

The fix exposes the completion index to tool callables by inspecting each tool's signature at initialization and caching whether it accepts a _completion_idx parameter. During tool execution in _tool_call_loop, if a tool declares this parameter, the trainer passes the current completion index; otherwise it calls the tool normally. This allows tools to know which of the multiple generated completions triggered them, enabling per-completion attribution for reward functions without breaking existing tools that don't need this information.

Fixes #4866

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

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.

Expose generation index to tool callables during GRPOTrainer tool execution

1 participant