Skip to content

add robot reply and update chunking logic#2638

Closed
YuchengZhou821 wants to merge 1 commit into
mainfrom
add-robot-reply-and-update-chunking-logic
Closed

add robot reply and update chunking logic#2638
YuchengZhou821 wants to merge 1 commit into
mainfrom
add-robot-reply-and-update-chunking-logic

Conversation

@YuchengZhou821

Copy link
Copy Markdown
Contributor

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:

  • The ParseDailyFile function 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.
  • The AppendInteraction and AppendToIndex methods in writer.go now 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:

  • A new RebuildIndex method is added to the Reader type, allowing the index to be rebuilt from daily files after summarization, ensuring the index stays up-to-date. The Summarize method in the Manager now triggers this rebuild and logs the outcome. [1] [2]

API and test updates:

  • The RecordInteraction API 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]
  • New and updated tests verify correct merging of user sections, inclusion of robot replies, and proper chunk formatting in logs and the index. [1] [2]

Constants and refactoring:

  • Introduced the maxMergeSections constant 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.

Copilot AI review requested due to automatic review settings June 28, 2026 03:04
@YuchengZhou821 YuchengZhou821 requested review from a team as code owners June 28, 2026 03:04
@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.07317% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/memory/writer.go 25.00% 7 Missing and 2 partials ⚠️
internal/memory/manager.go 0.00% 7 Missing ⚠️
internal/memory/reader.go 0.00% 7 Missing ⚠️
internal/memory/indexer.go 94.54% 3 Missing ⚠️
internal/runtime/runtime.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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+"]")
}

Comment thread internal/memory/writer.go
@@ -56,7 +56,7 @@ func NewWriter(memoryRoot string, log *zap.Logger) (*Writer, error) {
}

// AppendInteraction writes a user message to today's daily log.
Comment thread internal/memory/writer.go
}
}

// AppendToIndex embeds and inserts a new user message into the given index.
Comment thread internal/memory/reader.go
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))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants