Switch memory on: the agent may keep one, and carries them into the next run
The store and the write trigger existed and nothing used either. This wires both ends, so "we have long-term memory" stops being a statement about code that exists and becomes one about behaviour. READ. Memories are recalled before retrieval and placed before it in the prompt: it is the smaller block and the more general one — a standing preference frames how the documents should be read, where a document does not frame a preference. The question stays last, because a model reads the last thing and answers it, and evidence after the question becomes the prompt. Skipped for smalltalk on the same terms as retrieval. Nobody needs remembering to say good morning, and paying for it is how "hi" came to cost six thousand tokens. FAILS QUIET, RECORDED LOUDLY. A memory store that is unreachable must not take the run with it: an answer without memory is worse, not wrong, and the alternative is an outage in the knowledge layer becoming an outage in the product. The trajectory records the failure, and records separately when the store returned recency instead of relevance — a reader comparing two answers needs to know which one got which. WRITE. tools.Remember is registered only where there is somewhere to put it, through DefaultToolsWithMemory rather than a nil check inside the old constructor: a deployment that has not migrated 000017 must not offer a tool whose every call fails against a table that is not there. Passing nil registers exactly the catalogue that was there before. Memory shares retrieval's embedder, and memory.Embedder is knowledge.Embedder by structure so it cannot be given a different one. Two embedding models in one deployment produce vectors that cannot be compared, and the failure is silent: a recall that returns nothing rather than an error. Five new tests on the loop, including the two that matter — a failing store still answers, and a greeting carries nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/krow/krow-backend/go-api/internal/config"
|
||||
"github.com/krow/krow-backend/go-api/internal/gateway"
|
||||
"github.com/krow/krow-backend/go-api/internal/knowledge"
|
||||
"github.com/krow/krow-backend/go-api/internal/memory"
|
||||
"github.com/krow/krow-backend/go-api/internal/repo"
|
||||
"github.com/krow/krow-backend/go-api/internal/tools"
|
||||
)
|
||||
@@ -26,8 +27,16 @@ func NewModelEngine(db repo.Querier, cfg config.Config) *Engine {
|
||||
// alternative provider needed an edit to this file to be reachable.
|
||||
gw := gateway.New(gateway.FromConfig(cfg.Model))
|
||||
retriever := knowledge.NewRetriever(db, NewEmbedder(cfg))
|
||||
exec := NewModelExecutor(gw, NewPostgresSink(db), DefaultTools(db, retriever)).
|
||||
|
||||
// Long-term memory shares the embedder with retrieval, deliberately: two
|
||||
// embedding models in one deployment produce vectors that cannot be
|
||||
// compared, and the failure is silent — a recall that quietly returns
|
||||
// nothing rather than an error.
|
||||
memories := memory.New(db, NewEmbedder(cfg))
|
||||
|
||||
exec := NewModelExecutor(gw, NewPostgresSink(db), DefaultToolsWithMemory(db, retriever, memories)).
|
||||
WithRetriever(retriever).
|
||||
WithMemory(memories).
|
||||
// Without this, a spec's `subagents:` parses, loads, and is then
|
||||
// dropped — which is how krow-workforce-agent came to declare five
|
||||
// subagents and answer every question by itself. The resolver is the
|
||||
@@ -118,6 +127,16 @@ func NewEmbedder(cfg config.Config) knowledge.Embedder {
|
||||
// service that booted without a capability its specs name would fail one run
|
||||
// at a time instead of once, loudly, at startup.
|
||||
func DefaultTools(db repo.Querier, retriever *knowledge.Retriever) *tools.Registry {
|
||||
return DefaultToolsWithMemory(db, retriever, nil)
|
||||
}
|
||||
|
||||
// DefaultToolsWithMemory is DefaultTools with long-term memory available.
|
||||
//
|
||||
// A separate constructor rather than a nil check inside the old one, because a
|
||||
// deployment that has not migrated 000017 must not offer a tool whose every
|
||||
// call would fail against a table that is not there. Passing nil registers the
|
||||
// catalogue exactly as it was.
|
||||
func DefaultToolsWithMemory(db repo.Querier, retriever *knowledge.Retriever, memories tools.MemoryWriter) *tools.Registry {
|
||||
// The confirmation store is Postgres-backed, not in-process. A pending
|
||||
// write is asked about in one request and approved in another, and nothing
|
||||
// guarantees those two reach the same replica — an in-memory store would
|
||||
@@ -162,5 +181,12 @@ func DefaultTools(db repo.Querier, retriever *knowledge.Retriever) *tools.Regist
|
||||
} {
|
||||
reg.MustRegister(t)
|
||||
}
|
||||
|
||||
// Memory, only where there is somewhere to put it. It is a confirmed
|
||||
// write like assign_worker: it stores personal data that shapes later
|
||||
// hiring answers, so a person sees the sentence before it is kept.
|
||||
if memories != nil {
|
||||
reg.MustRegister(tools.Remember(memories))
|
||||
}
|
||||
return reg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user