add robot reply and update chunking logic#2638
Closed
YuchengZhou821 wants to merge 1 commit into
Closed
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the memory logging/indexing pipeline to record both sides of a conversation (user + robot), improve chunking by merging consecutive same-user sections, and keep the in-memory index in sync after summarization.
Changes:
- Updated interaction recording to include the robot reply in both daily logs and the hot-update index path.
- Reworked daily-log parsing to merge consecutive same-user sections (up to
maxMergeSections) and normalize lines into timestamped[HH:MM:SS] Speaker: ...format. - Added
Reader.RebuildIndex()and invoked it after summarization, plus updated/added tests around the new parsing/merging behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/runtime/runtime.go | Passes robot reply into memory interaction recording. |
| internal/memory/writer.go | Writes user + optional robot reply to daily logs and write-through index. |
| internal/memory/writer_test.go | Updates writer tests for new method signature (needs stronger coverage for robot replies). |
| internal/memory/reader.go | Adds index rebuild capability. |
| internal/memory/manager.go | Triggers index rebuild + persistence after summarization. |
| internal/memory/indexer.go | Adds merge limit constant and new daily-file parsing/merging logic supporting robot lines. |
| internal/memory/indexer_test.go | Updates tests for new parsing format and adds merge/robot-reply cases. |
Comments suppressed due to low confidence (1)
internal/memory/writer_test.go:31
- Robot-reply logging isn’t covered by this test: both calls pass an empty robotReply, so the new “- Robot:” branch in AppendInteraction is never asserted. Updating this test to include a non-empty robot reply will protect the new behavior.
w.AppendInteraction("Hello robot", "", testUUID, "alice")
w.AppendInteraction("What is your name?", "", testUUID, "alice")
dailyPath := w.dailyPath()
content, err := os.ReadFile(dailyPath)
require.NoError(t, err)
require.Contains(t, string(content), "Hello robot")
require.Contains(t, string(content), "What is your name?")
require.Contains(t, string(content), "[User: "+testUUID+"]")
}
| @@ -56,7 +56,7 @@ func NewWriter(memoryRoot string, log *zap.Logger) (*Writer, error) { | |||
| } | |||
|
|
|||
| // AppendInteraction writes a user message to today's daily log. | |||
| } | ||
| } | ||
|
|
||
| // AppendToIndex embeds and inserts a new user message into the given index. |
Comment on lines
+71
to
+79
| // RebuildIndex rebuilds the index from daily files. On failure the old index is kept. | ||
| func (r *Reader) RebuildIndex(ctx context.Context) error { | ||
| newIdx := NewMemoryIndex(r.index.embedder, r.log) | ||
| if err := BuildIndex(ctx, newIdx, r.dailyDir, DefaultValidDurationDays); err != nil { | ||
| return err | ||
| } | ||
| r.index = newIdx | ||
| r.indexReady = true | ||
| return nil |
Comment on lines
101
to
110
| go func() { | ||
| m.summarizer.Run(ctx) | ||
| if err := m.reader.RebuildIndex(ctx); err != nil { | ||
| m.log.Warn("index rebuild failed, keeping old index", zap.Error(err)) | ||
| return | ||
| } | ||
| m.log.Info("index rebuilt after summarization", zap.Int("chunks", m.reader.Index().Size())) | ||
| if err := m.reader.Index().SaveToDisk(m.indexDir); err != nil { | ||
| m.log.Warn("failed to persist index", zap.Error(err)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant improvements to the memory indexing and logging system, especially around how user and robot interactions are recorded, merged, and indexed. The main focus is on supporting both user and robot messages in daily logs, merging consecutive messages from the same user, and ensuring that the in-memory index stays consistent after summarization. The changes also include updates to tests to reflect the new logic.
Memory log and index enhancements:
ParseDailyFilefunction now merges consecutive sections from the same user (up to a maximum of three) into a single chunk, improving context retention in memory logs. It also parses both user and robot messages, formatting them with timestamps and speaker labels.AppendInteractionandAppendToIndexmethods inwriter.gonow support logging both user messages and robot replies, and format them consistently in both the daily log files and in-memory index. [1] [2]Index rebuilding and summarization:
RebuildIndexmethod is added to theReadertype, allowing the index to be rebuilt from daily files after summarization, ensuring the index stays up-to-date. TheSummarizemethod in theManagernow triggers this rebuild and logs the outcome. [1] [2]API and test updates:
RecordInteractionAPI and all related test calls are updated to accept both user and robot messages, reflecting the new logging format. [1] [2] [3] [4] [5] [6] [7] [8]Constants and refactoring:
maxMergeSectionsconstant to control how many consecutive sections from the same user are merged.These changes improve the fidelity and usability of memory logs, ensure the index accurately reflects the latest state, and provide better context for downstream features.