Files
local 471e9ce935 feat: migrate chat backend to Semantic Kernel with tool calling support
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>
2026-04-04 23:59:13 +01:00

1.7 KiB

ADDED Requirements

Requirement: Semantic Kernel service registration

The API backend SHALL register a Semantic Kernel Kernel instance in the ASP.NET Core DI container at startup, configured with an OpenAI chat completion connector.

Scenario: Kernel registered at startup

  • WHEN the API application starts
  • THEN a Kernel instance is available for injection into controllers

Requirement: OpenAI connector targets CLIProxyAPI proxy

The Semantic Kernel OpenAI chat completion service SHALL be configured to use the existing CLIProxyAPI proxy endpoint as its base URL, reading the URL and model name from appsettings.json.

Scenario: Connector uses configured endpoint

  • WHEN the kernel makes a chat completion request
  • THEN it sends the request to the URL specified in ResponsesApi:BaseUrl configuration

Scenario: Model from configuration

  • WHEN the kernel makes a chat completion request
  • THEN it uses the model name specified in ResponsesApi:Model configuration

Requirement: Plugin registration

The API backend SHALL register extraction and validation plugins with the Kernel so they are available as tools for the LLM to invoke.

Scenario: Plugins available as tools

  • WHEN the kernel is constructed
  • THEN all registered plugin functions appear in the tool list sent to the LLM

Requirement: Auto function calling

The Kernel SHALL be configured with automatic function calling enabled, allowing the LLM to invoke registered plugin functions without manual dispatch code.

Scenario: LLM invokes tool automatically

  • WHEN the LLM decides to call a registered function during chat completion
  • THEN the kernel automatically executes the function and returns the result to the LLM