t7 explanation: evidence assembly + one anthropic call behind a strict-json seam - #2
Merged
Merged
Conversation
…dapter, explain_anomaly orchestrator + explanation repository
…ahead), dedupe evidence indices, drop unused param
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
what
domain/explanation.py— the trust design: candidates (anomaly + recent news, each sentiment-scored) are built deterministically from stored data and numbered; the LLM returns prosereasoningplus the indices it cites, so it can never mint evidence.ExplainerLLMProtocol is the seam;AnthropicExplaineris the one concrete (SDK import deferred to construction, like FinBERT's torch). Strict pydantic validation of the reply (extra="forbid", index range check, duplicate indices deduped); anything else raisesMalformedReplyand stores nothing.ingest/explain.py—explain_anomalyorchestrator: idempotency check first (an explained anomaly costs no second LLM call), news window[bar_ts - 3d, bar close)so later news can't "explain" an earlier move, sequentialto_threadsentiment scoring, one LLM call, commit as one unit of work.store/repositories.py—ExplanationRepository(natural-key upsert,on_conflict_do_nothing),NewsRepository.recent_for_symbolwith a bounded window.anthropic_api_key/anthropic_modelrequired, no defaults;.env.exampleupdated.tests
AnthropicExplainer).Explanationlinked to its anomaly by natural key with ≥ 1EvidenceRef(the anomaly cites itself, so the floor holds even with zero news).