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

Understand the .NET BroadcastQueue #186

Open
Tracked by #182
dsgrieve opened this issue Aug 19, 2024 · 1 comment
Open
Tracked by #182

Understand the .NET BroadcastQueue #186

dsgrieve opened this issue Aug 19, 2024 · 1 comment

Comments

@dsgrieve
Copy link
Member

No description provided.

@dsgrieve
Copy link
Member Author

The intent of BroadcastQueue (notes from Teams chat with Chris Rickman):

Functionally, the state of each channel needs to be "in-sync" at the point an agent based on said channel is invoked. This becomes critical when ChatCompletionAgent and OpenAIAssistantAgent are participating in the same AgentChat.
If they don't have the most up-to-date message the response won't have fidelity.

Syncing a ChatHistoryChannel is virtually instantaneous...for an assistant-agent, its based on an REST API call (to store the messages on the thread).

Syncing OpenAIAssistantChannel could therefore have non-trivial latency.

We don't want to block the chat on each turn to sync every channel.
Each ChatCompletionAgent (by default) does share the same history since they utiliize the same channel (based on the channel-key contract).

An assistant requires that all messages be saved to the thread, which is managed remotely by the API

Multiple assistants will share the same thread-id / channel (by default) [I'll come back to qualify "default" in a minute)

Ultimately, if an assistant-agent isn't taking a turn...it doesn't make sense to block on synchronization (just slow down the entire experience)

The BroadcastQueue is responsible for taking a request to broadcast the most recent messages to all channels, without blocking the caller. Blocking only occurs when a channel is being used whose queue is not empty.

I specifically didn't want to manage a background thread looping to manage the queue...so it's all driven / triggered by adding to the queue.

I also took care to minimize as much as possible how much locking was utilized (since that can also impact performance)

In terms of the "default" qualification - it is possible for different ChatCompletionAgents to be managed in separate channels based on the presence / configuration of the HistoryReducer...this is because the reducer alters the channel specific history.

Example: Two chat-completion agents, one with a reducer and one without will each use a different channel so that their channel history is managed as each expects. Any chat-completion agent using a reducer with equivalent configuration will consolidate to the same channel.

For an assistant-agent, it is possible for the caller to create one that targets one endpoint and another that targets a different endpoint. This might be an assistant that targets OpenAI and one that targets Azure...or maybe they target different azure regions or subscriptions.

In these cases, an assistant wouldn't be able to share the same thread-id. This necessarily requires a different channel based on the assistant configuration

So, in the "vanilla" case for mixing chat-completion and assistant agents, one would expect two channels...but this isn't necessarily a given for all usage cases.

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

No branches or pull requests

1 participant