-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
assist: Refactor token counting (#29224)
With the actor model, tokens can be used in multiple ways (picking tools, invoking them, ...), which don't necessarily end up in a final action (sometimes we return a nextStep instead). Streaming responses were another challenge: the agent returned without the completion being over (it returned a routine streaming the deltas sent by the model). This PR introduces a TokenCounter interface that abstracts synchronous and asynchronous token counting. All token-consuming operations must return a TokenCounter. TokensCounters are stored in the agent state and returned once the agent exists. Finally, the token counters are evaluated asynchronously to give the streaming completion requests enough time to finish.
- Loading branch information
Showing
9 changed files
with
387 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.