shikumi-optimize 0.3.1.0 → 0.4.0.0
raw patch · 4 files changed
+132/−16 lines, 4 filesdep ~baikaidep ~shikumidep ~shikumi-cachePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: baikai, shikumi, shikumi-cache, shikumi-compile, shikumi-eval, shikumi-optimize, shikumi-testing, shikumi-trace
API changes (from Hackage documentation)
+ Shikumi.Optimize.Feedback: Human :: Provenance
+ Shikumi.Optimize.Feedback: Inferred :: Provenance
+ Shikumi.Optimize.Feedback: StoredCritique :: !Text -> !Maybe NodePath -> !Text -> !Provenance -> !Text -> StoredCritique
+ Shikumi.Optimize.Feedback: [critiqueAuthor] :: StoredCritique -> !Text
+ Shikumi.Optimize.Feedback: [critiqueExampleId] :: StoredCritique -> !Text
+ Shikumi.Optimize.Feedback: [critiqueNode] :: StoredCritique -> !Maybe NodePath
+ Shikumi.Optimize.Feedback: [critiqueProvenance] :: StoredCritique -> !Provenance
+ Shikumi.Optimize.Feedback: [critiqueText] :: StoredCritique -> !Text
+ Shikumi.Optimize.Feedback: data StoredCritique
+ Shikumi.Optimize.Feedback: instance GHC.Classes.Eq Shikumi.Optimize.Feedback.StoredCritique
+ Shikumi.Optimize.Feedback: instance GHC.Internal.Show.Show Shikumi.Optimize.Feedback.StoredCritique
+ Shikumi.Optimize.Feedback: storedCritiqueFeedback :: Applicative m => [Text] -> [StoredCritique] -> Metric o -> o -> EvaluationEvidence o -> m FeedbackResult
Files
- CHANGELOG.md +19/−0
- shikumi-optimize.cabal +14/−14
- src/Shikumi/Optimize/Feedback.hs +56/−2
- test/FeedbackSpec.hs +43/−0
CHANGELOG.md view
@@ -2,6 +2,25 @@ ## Unreleased +## 0.4.0.0 — 2026-11-23++### Breaking++- Add the `Human` and `Inferred` constructors to `Shikumi.Optimize.Feedback.Provenance`,+ so stored production critiques keep their label kind all the way into the reflection+ prompt. Code that matches on `Provenance` exhaustively must handle them.++### Added++- Add `StoredCritique` and `storedCritiqueFeedback`: a GEPA feedback callback over+ critiques stored with examples and keyed by a stable example id. Node critiques attach+ only when their node executed, at most one program-scoped critique fills the program+ slot, and the existing bounds and redaction apply unchanged.++### Changed++- Upgrade `mori://shinzui/baikai/packages/baikai` to `>=0.11.0.0 && <0.12`.+ ## 0.3.1.0 — 2026-11-02 ### Added
shikumi-optimize.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.4 name: shikumi-optimize-version: 0.3.1.0+version: 0.4.0.0 synopsis: The optimizer framework for shikumi LM programs (EP-10) category: AI description:@@ -74,17 +74,17 @@ build-depends: aeson >=2.2 && <2.3,- baikai >=0.10.0.0 && <0.11,+ baikai >=0.11.0.0 && <0.12, base >=4.20 && <5, containers >=0.6 && <0.9, effectful >=2.6 && <2.8, generic-lens >=2.2 && <2.4, lens ^>=5.3,- shikumi ^>=0.5.0.0,- shikumi-cache ^>=0.2.1.0,- shikumi-compile ^>=0.2.2.0,- shikumi-eval ^>=0.3.1.0,- shikumi-trace ^>=0.3.1.0,+ shikumi ^>=0.5.1.1,+ shikumi-cache ^>=0.2.1.2,+ shikumi-compile ^>=0.2.2.1,+ shikumi-eval ^>=0.3.1.1,+ shikumi-trace ^>=0.3.2.1, text ^>=2.1, vector >=0.13 && <0.14, @@ -122,18 +122,18 @@ build-depends: aeson,- baikai >=0.10.0.0 && <0.11,+ baikai >=0.11.0.0 && <0.12, base, containers, effectful, generic-lens, lens,- shikumi ^>=0.5.0.0,- shikumi-compile ^>=0.2.2.0,- shikumi-eval ^>=0.3.1.0,- shikumi-optimize ^>=0.3.1.0,- shikumi-testing,- shikumi-trace ^>=0.3.1.0,+ shikumi ^>=0.5.1.1,+ shikumi-compile ^>=0.2.2.1,+ shikumi-eval ^>=0.3.1.1,+ shikumi-optimize ^>=0.4.0.0,+ shikumi-testing ^>=0.1.0.0,+ shikumi-trace ^>=0.3.2.1, tasty, tasty-hunit, text,
src/Shikumi/Optimize/Feedback.hs view
@@ -5,6 +5,8 @@ EvaluationEvidence (..), NodeFeedback (..), Provenance (..),+ StoredCritique (..),+ storedCritiqueFeedback, FeedbackResult (..), FeedbackConfig (..), defaultFeedbackConfig,@@ -24,7 +26,7 @@ import Effectful.Error.Static (Error, throwError) import Effectful.Prim (Prim) import Shikumi.Error (ShikumiError (..))-import Shikumi.Eval (Dataset, Example (..), Prediction, Score, datasetExamples, prediction, scoreZero)+import Shikumi.Eval (Dataset, Example (..), Metric, Prediction, Score, datasetExamples, prediction, scoreZero) import Shikumi.Eval.Evaluate (scoreExecution, tryShikumi) import Shikumi.Eval.Report (FailurePolicy (..), FailureReason (..), UsageTotals) import Shikumi.Eval.Usage (withUsageTotals)@@ -45,8 +47,25 @@ } deriving stock (Eq, Show) -data Provenance = Caller | Model | LegacyProgram deriving stock (Eq, Show)+-- | Who produced a critique. 'Human' and 'Inferred' label stored production+-- evidence: an adjudication by a person, and a critique derived from an+-- operational outcome rather than written by anyone. None of the values implies+-- human approval of a candidate (ADR-4).+data Provenance = Caller | Model | LegacyProgram | Human | Inferred deriving stock (Eq, Show) +-- | A critique stored with an example in a dataset rather than computed by a+-- callback. It is keyed by the example's stable identifier, so it survives+-- reordering, and it keeps the provenance of whoever produced it. A critique with+-- no node is program-scoped.+data StoredCritique = StoredCritique+ { critiqueExampleId :: !Text,+ critiqueNode :: !(Maybe NodePath),+ critiqueText :: !Text,+ critiqueProvenance :: !Provenance,+ critiqueAuthor :: !Text+ }+ deriving stock (Eq, Show)+ data NodeFeedback = NodeFeedback { feedbackExample :: !Int, feedbackPath :: !NodePath,@@ -94,6 +113,41 @@ Right out -> let (s, t) = metric expected (prediction out) in FeedbackResult s (if T.null t then Nothing else Just (LegacyProgram, t)) []++-- | A feedback callback over critiques stored with the examples.+--+-- The first argument lists the stable example identifiers in the order of the+-- dataset being captured, so the example at position @n@ has identifier @n@ of+-- the list. Each example is scored with the metric (zero when execution failed).+-- Every stored node critique for the example whose node executed in this run is+-- attached with its provenance; a critique for a node that did not execute is+-- dropped rather than rejected, because production evidence may name a node a+-- failing rerun never reached. The example's program-scoped critique, at most+-- one, fills 'programCritique' and is rendered only when+-- 'includeProgramCritique' is set. Critiques still attach when execution failed,+-- and positions beyond the identifier list attach nothing. The result passes+-- through 'validateFeedback' like any other callback, so the bounds and+-- redaction of t'FeedbackConfig' apply unchanged.+storedCritiqueFeedback ::+ (Applicative m) => [Text] -> [StoredCritique] -> Metric o -> o -> EvaluationEvidence o -> m FeedbackResult+storedCritiqueFeedback ids stored metric expected ev =+ pure (FeedbackResult score programScoped nodeScoped)+ where+ score = either (const scoreZero) (metric expected . prediction) (executionResult ev)+ ix = exampleIndex ev+ mine = case drop ix ids of+ (ident : _) | ix >= 0 -> [c | c <- stored, critiqueExampleId c == ident]+ _ -> []+ executed path = any (\obs -> observationPath obs == path && not (observationOpaque obs)) (observations ev)+ nodeScoped =+ [ NodeFeedback ix path Nothing (critiqueText c) (critiqueProvenance c)+ | c <- mine,+ Just path <- [critiqueNode c],+ executed path+ ]+ programScoped = case [c | c <- mine, critiqueNode c == Nothing] of+ (c : _) -> Just (critiqueProvenance c, critiqueText c)+ [] -> Nothing validateFeedbackConfig :: FeedbackConfig -> Either ShikumiError () validateFeedbackConfig cfg =
test/FeedbackSpec.hs view
@@ -221,6 +221,49 @@ scores @?= [0] map (`feedbackFor` logbook) (programNodePaths prog) @?= [[], []] feedbackFor (NodePath []) logbook @?= ["program (LegacyProgram): fix"],+ testCase "stored critiques reach the proposer labeled Human and Model" $ do+ let ds = dataset [example (Sentence "first") (Label "positive"), example (Sentence "second") (Label "positive")]+ stored =+ [ StoredCritique "ex-a" (Just (NodePath [])) "name the conflict" Human "reviewer@example",+ StoredCritique "ex-b" (Just (NodePath [])) "cite the guidance" Model "critic-model"+ ]+ callback = storedCritiqueFeedback ["ex-a", "ex-b"] stored exactMatch+ proposer = Embed $ \input ->+ if "Human: name the conflict" `T.isInfixOf` feedback input && "Model: cite the guidance" `T.isInfixOf` feedback input+ then pure (ReflectOut "changed")+ else throwError (ValidationFailure (feedback input))+ result <- runScript [ok, ok] $ do+ rows <- captureEvidence defaultFeedbackConfig ds callback sentimentProg+ changed <- mutateFromEvidence defaultFeedbackConfig proposer "" "" rows 0 sentimentProg+ pure (map (\(_, fb, _) -> fb) rows, programParams changed)+ checkRight result $ \(feedbacks, params) -> do+ map (map provenance . nodeCritiques) feedbacks @?= [[Human], [Model]]+ map (unScore . overallScore) feedbacks @?= [1, 1]+ instructionOverride (params !! 0) @?= Just "changed",+ testCase "examples without stored critiques, unexecuted nodes and positions past the ids attach nothing" $ do+ let ds = dataset [example (Sentence "first") (Label "positive"), example (Sentence "second") (Label "negative"), example (Sentence "third") (Label "positive")]+ stored =+ [ StoredCritique "ex-a" (Just (NodePath [StepComposeR])) "never executed" Human "reviewer",+ StoredCritique "ex-b" Nothing "program scoped" Inferred "outcome-adapter",+ StoredCritique "ex-z" (Just (NodePath [])) "unlisted example" Human "reviewer"+ ]+ callback = storedCritiqueFeedback ["ex-a", "ex-b"] stored exactMatch+ result <- runScript [ok, ok, ok] (captureEvidence defaultFeedbackConfig ds callback sentimentProg)+ checkRight result $ \rows -> do+ let feedbacks = map second rows+ map nodeCritiques feedbacks @?= [[], [], []]+ map programCritique feedbacks @?= [Nothing, Just (Inferred, "program scoped"), Nothing]+ map (unScore . overallScore) feedbacks @?= [1, 0, 1],+ testCase "failed executions still carry stored critiques and long critiques are truncated" $ do+ let ds = dataset [example (Sentence "first") (Label "positive")]+ stored = [StoredCritique "ex-a" (Just (NodePath [])) (T.replicate 50 "x") Human "reviewer"]+ cfg = defaultFeedbackConfig {critiqueCharacters = 10}+ result <- runScript [Right "not JSON"] (captureEvidence cfg ds (storedCritiqueFeedback ["ex-a"] stored exactMatch) sentimentProg)+ checkRight result $ \rows -> do+ let fb = second (rows !! 0)+ unScore (overallScore fb) @?= 0+ map critique (nodeCritiques fb) @?= [T.replicate 9 "x" <> "…"]+ map provenance (nodeCritiques fb) @?= [Human], testCase "retry evidence keeps rejected and accepted invocation lineage" $ do let prog = Retry 2 sentimentProg ds = dataset [example (Sentence "input") (Label "positive")]