Skip to content

[v13] assist: Refactor token counting#29753

Merged
jakule merged 1 commit intobranch/v13from
bot/backport-29224-branch/v13
Jul 31, 2023
Merged

[v13] assist: Refactor token counting#29753
jakule merged 1 commit intobranch/v13from
bot/backport-29224-branch/v13

Conversation

@jakule
Copy link
Copy Markdown
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
@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.

3 participants