Add extensible chat client routing - #7662
Conversation
Introduce one-shot and failover routing primitives, ordered and semantic routing implementations, lifecycle reporting, streaming safeguards, and focused routing tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
This comment was marked as resolved.
This comment was marked as resolved.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Treat provider-thrown cancellation as terminal, materialize semantic routing messages before inspection, and enforce non-null selection consistently for streaming. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
Capture Current access failures before committing output so pre-output failover and attempt reporting remain accurate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
Apply ConfigureAwait(false) consistently across selection, invocation, streaming, disposal, and routing update awaits. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
There was a problem hiding this comment.
Addressed in commit 0abbfd1, along with some cancellation races
a19b74b to
0abbfd1
Compare
Clarify RoutingContext input semantics, add optional message buffering, centralize validation, simplify timing and disposal, and separate caller cancellation from provider failures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
Clone request options for selector shaping and restrict routing updates to concrete client attempts, leaving selection-failure cleanup to selectors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
Follow MEAI's repeatable-enumerable convention and propagate selector failures without cancellation rewriting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
Use ConcurrentDictionary atomic operations instead of explicit lock blocks while preserving the narrow request-state lifetime. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
896e51d to
a576773
Compare
Keep client selection simple while preventing selector and failed-client option mutations from affecting downstream attempts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
Document client-reference identity and keep semantic scoring parameters together in the constructor signature. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
Align routing code with MEAI formatting and documentation conventions, simplify disposal, and split routing tests by component and assembly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
|
Thank you David for the feedback, addressed in 8b79ae4 |
Consolidate shared streaming and non-streaming cases, reuse routing test helpers, and simplify semantic router disposal. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
|
Sorry y'all, I had a change of thought -- just one last thing I felt was a bit unresolved: I actually think the small per-attempt selection result mentioned earlier is more ergonomic than requiring every option variation to be represented by a configured client:
The client reference still remains the routing identity. The returned options are simply complete, ephemeral options for that attempt, while ConfigureOptionsChatClient remains a way to modify options — it’s just not the only way anymore. @jozkee @PranavSenthilnathan let me know what you guys think when you have time. I kicked off a Copilot session to write it out and push it here — if y’all prefer the old way then I’ll just revert it. |
Return the selected client with complete ephemeral options while preserving client-reference identity and recording routing-boundary attempt options. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74d04840-2379-4615-93f7-84f2299ada74
Resolves #7647
Summary
Adds experimental chat-routing primitives for selecting configured
IChatClientinstances without imposing a particular routing policy.RoutingChatClientsupports one-shot client selection.FailoverChatClientretries uncanceled failures that occur before output is exposed.OrderedFailoverChatClientprovides ordered fallback.SemanticRoutingChatClientselects clients using cached profile embeddings.RoutingContextexposes mutable request messages and options.FailoverChatClientAttemptreports invocation outcome, duration, time to first update, completion, and output commitment.API shape
Routing policies have two seams:
SelectClientAsyncruns before every invocation.OnRoutingUpdateAsyncreports each attempt so policy state can influence the next selection.isTerminalmeans the base will not select another client after the callback completes. A null attempt represents selection terminating before a client was invoked.Failover behavior
Semantic routing
SemanticRoutingChatClient:topK: 1.leaveOpen.Tests
Coverage includes selection failures, retries, cancellation, attempt limits, streaming commitment, early disposal, enumerator failures, concurrent requests, state cleanup, semantic thresholds, top-K aggregation, caching, and ownership.
net10.0net472test project builds successfullyMicrosoft Reviewers: Open in CodeFlow