Replace manual HTTP proxy in ChatController with Semantic Kernel's OpenAI chat completion service pointed at CLIProxyAPI. Add extraction plugin with validation function for structured field extraction from natural language, enabling an agentic loop with auto-retry and human-in-the-loop escalation. - Add Microsoft.SemanticKernel 1.74.0 with OpenAI connector - Create ExtractedFields schema and ValidationResult models - Create ExtractionPlugin with [KernelFunction] validation - Rewrite ChatController to use IChatCompletionService streaming - Configure FunctionChoiceBehavior.Auto() for tool calling - Preserve existing SSE contract (client unchanged) - Update tests to mock SK services, add plugin and integration tests - Archive multi-turn-conversations and migrate-to-semantic-kernel changes - Sync specs for agent-extraction, semantic-kernel-integration, chat-streaming Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2.4 KiB
2.4 KiB
Why
The chat backend currently proxies requests to an OpenAI-compatible API (CLIProxyAPI) via manual HttpClient calls and SSE parsing. As the agent evolves toward structured extraction with tool calling and autonomous validation loops, this manual plumbing becomes a liability. Semantic Kernel provides a production-ready abstraction for chat completion, tool/function calling, and auto-invocation — letting us focus on agent behavior rather than HTTP mechanics. Adopting it now establishes the foundation for the agentic workflow (natural language → structured extraction → tool-based validation → human-in-the-loop clarification).
What Changes
- Replace manual HttpClient + SSE proxy in
ChatControllerwith Semantic Kernel'sOpenAIChatCompletionServicepointed at the existing CLIProxyAPI proxy - Add a validation plugin that the agent can call as a tool to validate extracted key-value output against a predefined schema
- Introduce an agentic loop: the kernel autonomously retries extraction up to 2–3 times on validation failure, then escalates to the user for clarification
- Keep the existing SSE contract to the Blazor client unchanged —
ChatApiClientandChat.razorare not modified - BREAKING:
ChatControllerinternals are rewritten; the manual Responses API proxy logic is removed entirely
Capabilities
New Capabilities
agent-extraction: Defines the structured field extraction behavior — predefined keys, validation rules, autonomous retry loop, and human-in-the-loop escalationsemantic-kernel-integration: Defines how Semantic Kernel is configured, registered, and wired into the API — kernel setup, OpenAI connector config, plugin registration
Modified Capabilities
chat-streaming: The streaming requirement changes from "proxy SSE from upstream API" to "stream Semantic Kernel chat completion responses as SSE" — same client contract, different server implementation
Impact
- ChatAgent.Api: New NuGet dependencies (
Microsoft.SemanticKernel),Program.csservice registration changes,ChatControllerrewritten - ChatAgent.Api.Tests: Existing
ChatControllerTestsneed updating to mock Semantic Kernel services instead of upstream HTTP calls - Dependencies: Adds
Microsoft.SemanticKernelandMicrosoft.SemanticKernel.Connectors.OpenAIpackages - Infrastructure: No change — still talks to CLIProxyAPI at
localhost:8317 - Client: No change — SSE contract preserved