Files
AgenticCode/openspec/changes/archive/2026-04-06-few-shot-prompt-infrastructure/tasks.md
local 5b027eb0db feat: add extraction schema, sidebar nav, few-shot prompting, and prompt settings
Overhaul extraction pipeline with new TradeItem model, conversation flow,
and dedicated extraction endpoint. Add sidebar navigation with NavMenu
component and landing page. Introduce few-shot prompting service and
tests. Add prompt settings and email upload specs. Update OpenSpec
tooling with improved export-spec and extract-feature commands. Archive
completed changes and export full specs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 23:39:23 +01:00

2.7 KiB

1. Example Folder Structure

  • 1.1 Create directory structure: examples/extraction/few-shot/ and examples/extraction/evaluation/
  • 1.2 Add placeholder example 01/ with input.html (sample email HTML) and output.json (sample ExtractionResult JSON matching TradeItem schema). Use realistic but anonymized data.
  • 1.3 Add placeholder example 02/ with a different email pattern (e.g., single swap, different currency)
  • 1.4 Add placeholder example 03/ with an edge case (e.g., breakclause = "Y", or unusual counterparty name)

2. Instruction Template

  • 2.1 Create examples/extraction/instruction-template.txt with the fixed extraction system prompt: task description, TradeItem schema definition (all 7 fields with types), mapping rules (date parsing, leg flattening, currency symbol → ISO code, breakclause default), and expected JSON output format

3. FewShotService

  • 3.1 Create FewShotService.cs in the API project — constructor loads instruction template and all few-shot examples from disk, assembles a ChatHistory prefix (system message + alternating user/assistant turns)
  • 3.2 Add CloneWithEmail(string emailHtml) method that clones the cached ChatHistory prefix and appends the email as a user message
  • 3.3 Add CloneWithEmailAndMessages(string emailHtml, List<ChatMessage> messages) method for follow-up disambiguation requests — clones prefix, appends email, appends follow-up messages
  • 3.4 Register FewShotService as singleton in Program.cs
  • 3.5 Add Examples:FewShotPath configuration in appsettings.json pointing to the examples folder

4. ExtractionRequest DTO

  • 4.1 Create ExtractionRequest.cs in Shared/Models with EmailHtml (string, required) and Messages (List, optional)

5. Extraction Endpoint

  • 5.1 Add Extract action to ChatController (or new ExtractionController) — POST /api/chat/extract accepting ExtractionRequest
  • 5.2 In the Extract action: get ChatHistory from FewShotService.CloneWithEmail() or CloneWithEmailAndMessages() based on whether Messages are present
  • 5.3 Import extraction-specific plugins only (not general chat plugins)
  • 5.4 Stream response via SSE using the same format as the existing chat endpoint
  • 5.5 Update ChatApiClient on the client side — add SendExtractionStreamingAsync(ExtractionRequest request) method mirroring the existing streaming pattern

6. Build and Verify

  • 6.1 Build the solution (dotnet build) and confirm no compilation errors
  • 6.2 Run all tests (dotnet test) and confirm they pass
  • 6.3 Add unit test for FewShotService — verify it loads examples and assembles correct ChatHistory structure (message count, roles, ordering)