Skip to content
Discussion options

You must be logged in to vote

When a ChatCompletionAgent streams tokens, there are 3 things end up over the same terminal at once. First is the agent writing chunks to stdout, then render loop displaying them and the user typing keystrokes. So this causes garbled output and blocked threads. You have to place a Channel between the agent and the terminal so the agent writes tokens in as a producer while a dedicated render worker reads and displays them as a consumer, meaning nothing ever touches stdout at the same time. A SemaphoreSlim gate then blocks the input box while the agent is streaming and only releases once the render worker receives a "turn complete" sentinel, so your prompt never appears mid-stream. For mult…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by markiues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants