Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v13] assist: Refactor token counting #29753

Merged
merged 1 commit into from Jul 31, 2023
Merged

Conversation

jakule
Copy link
Contributor

@jakule jakule commented Jul 28, 2023

Backport #29224 to branch/v13

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.
@jakule jakule added this pull request to the merge queue Jul 31, 2023
Merged via the queue into branch/v13 with commit cca08e7 Jul 31, 2023
21 checks passed
@jakule jakule deleted the bot/backport-29224-branch/v13 branch July 31, 2023 14:01
@fheinecke fheinecke mentioned this pull request Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants