Skip to content

feat(llm): abstract the LLM provider behind IChangelogModel - #41

Merged
goldbarth merged 1 commit into
mainfrom
2-decide-and-abstract-the-llm-provider
Jul 16, 2026
Merged

goldbarth merged 1 commit into
mainfrom
2-decide-and-abstract-the-llm-provider

Conversation

@goldbarth

Copy link
Copy Markdown
Owner

Closes #2

What

Adds the provider-agnostic LLM seam the pipeline builds on.

  • Chartula.Core (new): the domain-focused seam.
    • IChangelogModel - the interface the pipeline depends on (RephraseAsync, CheckFaithfulnessAsync).
    • ChatModel - the single implementation, backed by a provider-agnostic Microsoft.Extensions.AI.IChatClient.
    • Domain types: Audience, GroundedFacts, RephraseRequest, FaithfulnessRequest, FaithfulnessReport.
  • Chartula.Cli: composition root wiring Anthropic as the first provider (AsIChatClient), model + provider selectable via config, API key read by env-var name. This is the only provider-specific code.
  • Chartula.Core.Tests (new): 5 tests exercising the seam with a stub IChatClient - no live provider call.

Acceptance criteria

  • An interface defines the LLM operations the pipeline needs.
  • At least one concrete provider implements it.
  • The rest of the code depends only on the interface.
  • API keys are read from environment/config, never hardcoded.
  • Tests: the seam is exercised with a stub IChatClient (no live provider call), asserting the pipeline uses only the interface.

Notes

  • Architecture chosen after discussion: hybrid (domain interface over agnostic IChatClient). Swapping providers is a composition-root change only.
  • GroundedFacts and the ChatModel prompts are intentionally minimal placeholders; the fact base and prompt design are their own issues.

Build: 0 warnings / 0 errors. dotnet test: 5/5 green.

Introduce Chartula.Core with a domain-focused LLM seam the pipeline
depends on (IChangelogModel: RephraseAsync, CheckFaithfulnessAsync),
backed by a provider-agnostic Microsoft.Extensions.AI IChatClient.
The only provider-specific code (Anthropic) lives in the CLI
composition root, so swapping providers never touches the pipeline.
API keys are read by environment-variable name from configuration,
never hardcoded.

Add Chartula.Core.Tests exercising the seam with a stub IChatClient,
so the pipeline is verified without a live provider call.
@goldbarth goldbarth linked an issue Jul 16, 2026 that may be closed by this pull request
5 tasks
@goldbarth goldbarth self-assigned this Jul 16, 2026
@goldbarth
goldbarth merged commit ead4865 into main Jul 16, 2026
@goldbarth
goldbarth deleted the 2-decide-and-abstract-the-llm-provider branch July 16, 2026 10:38
goldbarth added a commit that referenced this pull request Oct 1, 2026
… alone (#319)

Follows #318, which added the ADR index and template.

- **Why:** the reason the domain knows no model provider was argued in
one bullet of `architecture.md`, in `CLAUDE.md`, and implied in
`testing.md`, but recorded nowhere as a decision with its date and its
cost. A contributor who wanted to call a provider feature from
`Chartula.Core` found a rule without the reasons behind it.
- **ADR 0004** records it in the template of #318: decided 2026-07-16 in
#41 (for #2), recorded here.
- **Context:** two operations need a model, both with structured output;
the product promises several providers (#75); a domain tied to one SDK
ties the pipeline to it, and lets a test of the domain reach a real
model, which costs tokens, needs a key and depends on the model.
- **Decision:** `Chartula.Core` references `Microsoft.Extensions.AI`
alone, `ChatModel` sends to an `IChatClient`, the provider packages are
referenced by `Chartula.Cli` alone, and what the domain asks of a model
is expressed in `Microsoft.Extensions.AI` terms. Provider knowledge such
as `ClaudeThinkingSupport` stays in `Cli/Composition`.
- **Consequences, precise about the tests:** `Chartula.Core.Tests`
cannot reach a model by construction. `Chartula.Cli.Tests` does
reference the SDKs, on purpose, and stays offline because its tests
replace the network, not because of its references; the ADR says so
rather than claiming the whole suite is safe by construction. Also: a
provider joins in the composition root (#88 changed no file in
`Chartula.Core`), the domain is limited to what `IChatClient` expresses,
a provider package is weighed for trimming (ADR 0002), and referencing
one from `Core` or `Infrastructure` starts as an issue.
- **`architecture.md`** keeps the choice as one line and links the ADR
instead of arguing it; **`testing.md`** links the ADR for why no Core
test can reach a model.
- The index in `adr/README.md` lists 0004.

**Verified:**
- The references were read from the project files:
`Chartula.Core.csproj` holds `Microsoft.Extensions.AI` and nothing else;
`Anthropic` and `Microsoft.Extensions.AI.OpenAI` are in
`Chartula.Cli.csproj` only; `Chartula.Cli.Tests` references
`Chartula.Cli`.
- The decision date and pull request from `git log -S IChatClient` and
#41's description; the provider promise from the decision comment on
#75; that #88 touched no file in `src/Chartula.Core` from its diff.
- `GetResponseAsync<T>`, `ReasoningOptions` and `UsageDetails` as used
in `ChatModel.cs` and `ChatModelOptions.cs`.
- Every relative link and anchor in all Markdown files of the repository
resolves (script, with a negative test).

Tests: none, documentation only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decide and abstract the LLM provider

1 participant