fix(curator): grant the definition engine its model runner
Registry.filter stripped the LLM capability whenever a manifest declared no tools, skills, memory or conversation capabilities, but DefinitionEngine.Pass always calls the model. An instruction-only custom curator therefore registered healthy and then failed every pass with 'no model runner is bound'. The definition engine is inherently agentic, so the filter now keeps the model runner for it while every other capability service stays bound only when declared. Adds tests reproducing the instruction-only pass through the registry/engine path and pinning that the registrar view for an instruction-only manifest exposes the model but no tools, skills, memory or conversations. Closes #1132
This commit is contained in:
1 parent
aa57377c7f
commit
7c8114bc55
3 files changed
+160
-8
No files matched your search
@@ -0,0 +1,141 @@
|
||||
package curator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
domainmemory "github.com/samcharles93/archie-core/internal/domain/memory"
|
||||
"github.com/samcharles93/archie-core/internal/tools"
|
||||
)
|
||||
|
||||
// fakeLLM records every chat request and returns a canned result.
|
||||
type fakeLLM struct {
|
||||
requests []ChatRequest
|
||||
}
|
||||
|
||||
func (f *fakeLLM) Chat(_ context.Context, req ChatRequest) (ChatResult, error) {
|
||||
f.requests = append(f.requests, req)
|
||||
return ChatResult{Text: "done"}, nil
|
||||
}
|
||||
|
||||
// stubToolBuilder, stubSkillStore, stubMemorySource and stubConversationSource
|
||||
// stand in for host capability services so tests can prove the registrar view
|
||||
// filters them out for a curator that does not declare them.
|
||||
type stubToolBuilder struct{}
|
||||
|
||||
func (stubToolBuilder) Build(context.Context, []string) ([]tools.ToolEntry, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type stubSkillStore struct{}
|
||||
|
||||
func (stubSkillStore) List(context.Context) ([]SkillRef, error) { return nil, nil }
|
||||
func (stubSkillStore) Read(context.Context, string) (Skill, error) { return Skill{}, nil }
|
||||
func (stubSkillStore) Write(context.Context, Skill) error { return nil }
|
||||
func (stubSkillStore) Delete(context.Context, string) error { return nil }
|
||||
|
||||
type stubMemorySource struct{}
|
||||
|
||||
func (stubMemorySource) Get(string) (domainmemory.MemoryEngine, bool) { return nil, false }
|
||||
|
||||
type stubConversationSource struct{}
|
||||
|
||||
func (stubConversationSource) RecentSessions(context.Context, time.Time) ([]SessionRef, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (stubConversationSource) Messages(context.Context, string, int) ([]ConversationMessage, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// fullHost returns a registrar carrying every host service, so a test can
|
||||
// prove what the filtered view keeps and drops.
|
||||
func fullHost(llm LLMRunner) Registrar {
|
||||
return Registrar{
|
||||
Model: "test/model",
|
||||
LLM: llm,
|
||||
Tools: stubToolBuilder{},
|
||||
Skills: stubSkillStore{},
|
||||
MemoryEngines: stubMemorySource{},
|
||||
Conversations: stubConversationSource{},
|
||||
}
|
||||
}
|
||||
|
||||
func instructionOnlyDefinition() Definition {
|
||||
return Definition{
|
||||
Name: "custom",
|
||||
Enabled: true,
|
||||
Instructions: "You are a tidy curator.",
|
||||
Manifest: Manifest{Interval: time.Hour},
|
||||
}
|
||||
}
|
||||
|
||||
// TestInstructionOnlyDefinitionPass runs an instruction-only custom curator
|
||||
// end to end through the registry/engine path: registration binds a filtered
|
||||
// view, and the pass reaches the model. Before the filter granted the
|
||||
// definition engine its model runner, this pass failed with "no model runner
|
||||
// is bound".
|
||||
func TestInstructionOnlyDefinitionPass(t *testing.T) {
|
||||
llm := &fakeLLM{}
|
||||
registry := NewRegistry(fullHost(llm))
|
||||
engine := NewDefinitionEngine(instructionOnlyDefinition())
|
||||
if err := registry.Register(engine); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := engine.Pass(t.Context(), PassInput{Reason: "test"}); err != nil {
|
||||
t.Fatalf("instruction-only pass: %v", err)
|
||||
}
|
||||
if len(llm.requests) != 1 {
|
||||
t.Fatalf("model calls = %d, want 1", len(llm.requests))
|
||||
}
|
||||
req := llm.requests[0]
|
||||
if req.Model != "test/model" {
|
||||
t.Errorf("model = %q, want the registrar default %q", req.Model, "test/model")
|
||||
}
|
||||
if len(req.Tools) != 0 {
|
||||
t.Errorf("model received %d tools, want none: undeclared tools must stay unavailable", len(req.Tools))
|
||||
}
|
||||
var system string
|
||||
for _, msg := range req.Messages {
|
||||
if msg.Role == "system" {
|
||||
system = msg.Content
|
||||
}
|
||||
}
|
||||
if !strings.Contains(system, "You are a tidy curator.") {
|
||||
t.Errorf("system prompt %q does not carry the definition's instructions", system)
|
||||
}
|
||||
}
|
||||
|
||||
// TestInstructionOnlyRegistrarViewFiltered pins capability filtering for an
|
||||
// instruction-only manifest: the bound registrar view exposes the model
|
||||
// runner but no tools, skills, memory or conversation access.
|
||||
func TestInstructionOnlyRegistrarViewFiltered(t *testing.T) {
|
||||
registry := NewRegistry(fullHost(&fakeLLM{}))
|
||||
engine := NewDefinitionEngine(instructionOnlyDefinition())
|
||||
if err := registry.Register(engine); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
host := engine.host
|
||||
if host.LLM == nil {
|
||||
t.Error("registrar view has no model runner; the definition engine always calls the model")
|
||||
}
|
||||
if host.Tools != nil {
|
||||
t.Error("registrar view exposes tools the manifest does not declare")
|
||||
}
|
||||
if host.Skills != nil {
|
||||
t.Error("registrar view exposes the skills capability the manifest does not declare")
|
||||
}
|
||||
if host.MemoryEngines != nil {
|
||||
t.Error("registrar view exposes memory engines the manifest does not declare")
|
||||
}
|
||||
if host.Conversations != nil {
|
||||
t.Error("registrar view exposes conversation history the manifest does not declare")
|
||||
}
|
||||
if host.Clock == nil {
|
||||
t.Error("registrar view has no clock; time is always bound")
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,10 @@ type Registrar struct {
|
||||
// Model is the default model reference ("provider/model") for
|
||||
// curators whose manifest leaves Model empty.
|
||||
Model string
|
||||
// LLM provides model access for agentic passes. Bound when the curator
|
||||
// declares an agentic capability (tools, skills, or a memory engine).
|
||||
// LLM provides model access for curator passes. Bound for the
|
||||
// definition engine (its pass always calls the model, even for an
|
||||
// instruction-only definition) and for curators that declare an
|
||||
// agentic capability (tools, skills, or a memory engine).
|
||||
LLM LLMRunner
|
||||
// Tools resolves the declared tool names into a runnable tool set.
|
||||
// Resolution is the enforcement point: a pass receives exactly the
|
||||
|
||||
@@ -62,7 +62,7 @@ func (r *Registry) Register(c CuratorEngine) error {
|
||||
if err := r.validateDeclared(m); err != nil {
|
||||
return err
|
||||
}
|
||||
return r.Add(c, r.filter(m))
|
||||
return r.Add(c, r.filter(c, m))
|
||||
}
|
||||
|
||||
// Host returns the raw registrar bundle the registry was built with. The
|
||||
@@ -93,11 +93,12 @@ func (r *Registry) validateDeclared(m Manifest) error {
|
||||
|
||||
// filter returns the registrar view narrowed to the curator's declared
|
||||
// capabilities. Events and Clock are always present (activity must stay
|
||||
// attributable and time is universal); model access is present only for
|
||||
// agentic curators; every capability service is present only when declared.
|
||||
func (r *Registry) filter(m Manifest) Registrar {
|
||||
// attributable and time is universal); model access is present for every
|
||||
// curator whose pass calls the model (see agentic); every capability service
|
||||
// is present only when declared.
|
||||
func (r *Registry) filter(c CuratorEngine, m Manifest) Registrar {
|
||||
v := r.host
|
||||
if !agentic(m) {
|
||||
if !agentic(c, m) {
|
||||
v.LLM = nil
|
||||
}
|
||||
if len(m.Tools) == 0 {
|
||||
@@ -115,6 +116,14 @@ func (r *Registry) filter(m Manifest) Registrar {
|
||||
return v
|
||||
}
|
||||
|
||||
func agentic(m Manifest) bool {
|
||||
// agentic reports whether the curator's pass calls the model, so the
|
||||
// registrar view must keep the model runner. The definition engine always
|
||||
// does, even for an instruction-only definition with no declared capability;
|
||||
// any other engine is agentic only when it declares tools, skills, memory or
|
||||
// conversation history.
|
||||
func agentic(c CuratorEngine, m Manifest) bool {
|
||||
if _, ok := c.(*DefinitionEngine); ok {
|
||||
return true
|
||||
}
|
||||
return len(m.Tools) > 0 || m.Skills || m.MemoryEngine != "" || m.Conversations
|
||||
}
|
||||
Reference in new issue
Block a user