cloudwego / cloudwego/eino

注入记忆主题信息的先决条件是否过于严格

Open
#1,130 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
13k
Forks
1.1k
Avg merge
4h 6m
Merged PRs (30d)
41

Description

`automemory` 中间件对于记忆的注入是否合理,当前实现是先查看一下上下文中是否有注入主题信息,如果之前注入过,那就不再注入了, 但可能后续聊天中用户又提问了新的内容,那这个时候就需要注入新的主题,但由于之前上下文中已经注入过了主题信息,所以当前就不会再重新的注入符合当前用户提问内容的记忆信息了,这一点是否不太合理

```go
// 3) Topic memories: sync mode selects from the original user query.
if !hasTopicMemoryInjected(nRunCtx.AgentInput.Messages) &&
m.cfg.Read.Mode == ReadModeSync && m.topicSelectionEnabled() {
memMsg, err := m.selectAndBuildTopicMemoryMessage(ctx, nRunCtx.AgentInput)
if err != nil {
m.onErr(ctx, OnErrorStageTopicSelectionSync, err)
} else if !isNilMessage(memMsg) {
m.sendTopicMemoryEvent(ctx, nRunCtx.AgentInput.Messages, memMsg)
reminders = append(reminders, memMsg)
}
}

if len(reminders) > 0 {
msgs := insertMessagesBeforeLastUserQuery(nRunCtx.AgentInput.Messages, reminders)
nRunCtx.AgentInput = &adk.TypedAgentInput[M]{Messages: msgs, EnableStreaming: nRunCtx.AgentInput.EnableStreaming}
}

// 4) Topic memories: async mode starts selection here (cannot use RunLocalValue in BeforeAgent).
if !hasTopicMemoryInjected(nRunCtx.AgentInput.Messages) &&
m.cfg.Read.Mode == ReadModeAsync && m.topicSelectionEnabled() {
if existing, _ := ctx.Value(ctxKeySelectionFuture{}).(*selectionFuture); existing == nil {
fut := &selectionFuture{done: make(chan struct{})}
ctx = context.WithValue(ctx, ctxKeySelectionFuture{}, fut)

// Snapshot current messages for selection; async path is best-effort.
msgSnapshot := append([]M{}, nRunCtx.AgentInput.Messages...)
go func() {
defer close(fut.done)
memMsg, selErr := m.selectAndBuildTopicMemoryMessage(ctx, &adk.TypedAgentInput[M]{Messages: msgSnapshot})
fut.mu.Lock()
defer fut.mu.Unlock()
if selErr != nil {
fut.err = selErr
return
}
if !isNilMessage(memMsg) {
fut.content = userMessageTextContent(memMsg)
}
}()
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing hasTopicMemoryInjected and the automemory middleware around the shown sync and async topic-selection paths. Reproduce a conversation where a later user query changes the topic, then verify that topic memories are selected and injected for the current query without breaking the existing one-time behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
ai, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.