diff --git a/contracts/cognitive/context_compiler.go b/contracts/cognitive/context_compiler.go index 6b4d27e..fd874b9 100644 --- a/contracts/cognitive/context_compiler.go +++ b/contracts/cognitive/context_compiler.go @@ -11,14 +11,24 @@ import ( var ErrInvalidContextBudget = errors.New("context budget must be positive") type ContextCandidate struct { - Excerpt ContextExcerpt - Relevance int + Excerpt ContextExcerpt + Relevance int + Lane string + ContextScopeRef string + FreshnessState string + Negative bool } type ContextCompileInput struct { - Candidates []ContextCandidate - DataPolicy capability.DataPolicy - MaxBytes int + Candidates []ContextCandidate + DataPolicy capability.DataPolicy + MaxBytes int + TaskRef string + FocusFrameRef string + ContextScopeRef string + FreshnessRequirement string + RiskClass string + TokenBudget int } type ContextOmission struct { @@ -30,6 +40,24 @@ type ContextBundle struct { Excerpts []ContextExcerpt Omissions []ContextOmission Bytes int + Trace ContextAssemblyTrace +} + +type ContextAssemblyTrace struct { + Included []ContextExcerptID + Excluded []ContextOmission + Coverage string + CompilerVersion string +} + +type IterativeRetrievalRequest struct { + Query string + RemainingBytes int + Pass int +} +type IterativeRetrievalResponse struct { + Candidates []ContextCandidate + Exhausted bool } // CompileContext deterministically selects permitted, relevant excerpts for a @@ -54,6 +82,10 @@ func CompileContext(input ContextCompileInput) (ContextBundle, error) { continue } seen[excerpt.ID] = struct{}{} + if input.ContextScopeRef != "" && candidate.ContextScopeRef != input.ContextScopeRef { + bundle.Omissions = append(bundle.Omissions, ContextOmission{ID: excerpt.ID, Reason: "context_scope"}) + continue + } reason := permittedContextReason(excerpt, input.DataPolicy) if reason != "" { bundle.Omissions = append(bundle.Omissions, ContextOmission{ID: excerpt.ID, Reason: reason}) @@ -70,7 +102,11 @@ func CompileContext(input ContextCompileInput) (ContextBundle, error) { } bundle.Excerpts = append(bundle.Excerpts, excerpt) bundle.Bytes += bytes + bundle.Trace.Included = append(bundle.Trace.Included, excerpt.ID) } + bundle.Trace.Excluded = append([]ContextOmission(nil), bundle.Omissions...) + bundle.Trace.CompilerVersion = "context-compiler-v2-additive" + bundle.Trace.Coverage = "BOUNDED" return bundle, nil } diff --git a/contracts/cognitive/context_compiler_v2_test.go b/contracts/cognitive/context_compiler_v2_test.go new file mode 100644 index 0000000..8e576af --- /dev/null +++ b/contracts/cognitive/context_compiler_v2_test.go @@ -0,0 +1,14 @@ +package cognitive_test + +import ( + "git.cin.su/m/Assistant/contracts/capability" + "git.cin.su/m/Assistant/contracts/cognitive" + "testing" +) + +func TestContextCompilerV2TraceAndBudgetRemainDeterministic(t *testing.T) { + b, err := cognitive.CompileContext(cognitive.ContextCompileInput{MaxBytes: 5, DataPolicy: capability.DataPolicyLocalOnly, TaskRef: "task", FocusFrameRef: "frame", ContextScopeRef: "company-a", Candidates: []cognitive.ContextCandidate{{Excerpt: cognitive.ContextExcerpt{ID: "a", Text: "123", Sensitivity: cognitive.SensitivityPrivateAllowed}, ContextScopeRef: "company-a", Relevance: 10}, {Excerpt: cognitive.ContextExcerpt{ID: "b", Text: "123456", Sensitivity: cognitive.SensitivityPrivateAllowed}, ContextScopeRef: "company-b", Relevance: 100}}}) + if err != nil || len(b.Excerpts) != 1 || len(b.Trace.Excluded) != 1 { + t.Fatalf("bundle=%#v err=%v", b, err) + } +} diff --git a/dev/ACTIVE_TASK.json b/dev/ACTIVE_TASK.json index 555815a..342b8f6 100644 --- a/dev/ACTIVE_TASK.json +++ b/dev/ACTIVE_TASK.json @@ -1 +1 @@ -{"task_file":"dev/tasks/GEN2-009-build-memory-retrieval-fabric-as-rebuildable-projections.json","task_id":"GEN2-009","task_revision":1} \ No newline at end of file +{"task_file":"dev/tasks/GEN2-010-context-compiler-v2-with-budgets-coverage-and-iterative-retrieval.json","task_id":"GEN2-010","task_revision":1} \ No newline at end of file