Commit Graph
25 Commits
Author SHA1 Message Date
Xubin Ren 46b19b15e1 perf: background post-response memory consolidation for faster replies 2026-03-16 09:01:11 +00:00
Xubin Ren 6d63e22e86 Merge remote-tracking branch 'origin/main' into pr-1961
Made-with: Cursor

# Conflicts:
#	.gitignore
2026-03-16 08:47:28 +00:00
Xubin RenandXubin Ren b29275a1d2 refactor(/new): background archival with guaranteed persistence
Replace fire-and-forget consolidation with archive_messages(), which
retries until the raw-dump fallback triggers — making it effectively
infallible. /new now clears the session immediately and archives in
the background. Pending archive tasks are drained on shutdown via
close_mcp() so no data is lost on process exit.
2026-03-16 16:40:09 +08:00
Tony d286926f6b feat(memory): implement async background consolidation
Implement asynchronous memory consolidation that runs in the background when
sessions are idle, instead of blocking user interactions after each message.

Changes:
- MemoryConsolidator: Add background task management with idle detection
  * Track session activity timestamps
  * Background loop checks idle sessions every 30s
  * Consolidation triggers only when session idle > 60s
- AgentLoop: Integrate background task lifecycle
  * Start consolidation task when loop starts
  * Stop gracefully on shutdown
  * Record activity on each message
- Refactor maybe_consolidate_by_tokens: Keep sync API but schedule async
- Add debug logging for consolidation completion

Benefits:
- Non-blocking: Users no longer wait for consolidation after responses
- Efficient: Only consolidate idle sessions, avoiding redundant work
- Scalable: Background task can process multiple sessions efficiently
- Backward compatible: Existing API unchanged

Tests: 11 new tests covering background task lifecycle, idle detection,
scheduling, and error handling. All passing.

🤖 Generated with Claude Code
2026-03-13 13:52:36 +08:00
Xubin Ren 6d3a0ab6c9 fix(memory): validate save_memory payload and raw-archive on repeated failure
- Require both history_entry and memory_update, reject null/empty values
- Fallback to tool_choice=auto when provider rejects forced function call
- After 3 consecutive consolidation failures, raw-archive messages to
  HISTORY.md without LLM summarization to prevent context window overflow
2026-03-13 03:53:50 +00:00
Xubin Ren 60c29702cc Merge branch 'main' into pr-1810
# Conflicts:
#	nanobot/agent/memory.py
#	tests/test_memory_consolidation_types.py
2026-03-13 03:29:16 +00:00
Xubin Ren 4f77b9385c fix(memory): fallback to tool_choice=auto when provider rejects forced function call
Some providers (e.g. Dashscope in thinking mode) reject object-style
tool_choice with "does not support being set to required or object".
Retry once with tool_choice="auto" instead of failing silently.

Made-with: Cursor
2026-03-13 03:18:08 +00:00
Re-bin 774452795b fix(memory): use explicit function name in tool_choice for DashScope compatibility 2026-03-12 16:09:24 +00:00
Re-bin 0a0017ff45 fix: raise tool result history limit to 16k and force save_memory in consolidation 2026-03-12 03:08:53 +00:00
Re-bin c72c2ce7e2 refactor: move generation settings to provider level, eliminate parameter passthrough 2026-03-11 09:47:04 +00:00
ethanclaw 12104c8d46 fix(memory): pass temperature, max_tokens and reasoning_effort to memory consolidation
Fix issue #1823: Memory consolidation does not inherit agent temperature
and maxTokens configuration.

The agent's configured generation parameters were not being passed through
to the memory consolidation call, causing it to fall back to default values.
This resulted in the consolidation response being truncated before the
save_memory tool call was emitted.

- Pass temperature, max_tokens, reasoning_effort from AgentLoop to
  MemoryConsolidator and then to MemoryStore.consolidate()
- Forward these parameters to the provider.chat_with_retry() call

Fixes #1823
2026-03-11 14:22:33 +08:00
Re-bin 62ccda43b9 refactor(memory): switch consolidation to token-based context windows
Move consolidation policy into MemoryConsolidator, keep backward compatibility for legacy config, and compress history by token budget instead of message count.
2026-03-10 19:55:06 +00:00
Re-bin 4784eb4128 merge origin/main into pr-1704 2026-03-10 18:09:15 +00:00
Re-bin b0a5435b87 refactor(llm): share transient retry across agent paths 2026-03-10 10:10:37 +00:00
shenchengtsi b24d6ffc94 fix(memory): validate save_memory payload before persisting 2026-03-10 11:32:11 +08:00
VITOHJL dbc518098e refactor: implement token-based context compression mechanism
Major changes:
- Replace message-count-based memory window with token-budget-based compression
- Add max_tokens_input, compression_start_ratio, compression_target_ratio config
- Implement _maybe_compress_history() that triggers based on prompt token usage
- Use _build_compressed_history_view() to provide compressed history to LLM
- Refactor MemoryStore.consolidate() -> consolidate_chunk() for chunk-based compression
- Remove last_consolidated from Session, use _compressed_until metadata instead
- Add background compression scheduling to avoid blocking message processing

Key improvements:
- Compression now based on actual token usage, not arbitrary message counts
- Better handling of long conversations with large context windows
- Non-destructive compression: old messages remain in session, but excluded from prompt
- Automatic compression when history exceeds configured token thresholds
2026-03-08 14:20:16 +08:00
Re-bin fc0b38c304 fix(memory): improve warning message for empty/non-dict list arguments 2026-03-06 05:27:39 +00:00
nanobot-contributor 6fb4204ac6 fix(memory): handle list type tool call arguments
Some LLM providers return tool_calls[0].arguments as a list instead of
dict or str. Add handling to extract the first dict element from the list.

Fixes /new command warning: 'unexpected arguments type list'
2026-03-06 11:47:00 +08:00
Re-bin d546cbac6e style(memory): use loguru {} formatting in warning 2026-02-24 11:23:10 +00:00
alairjt 3eeac4e8f8 Fix: handle non-string tool call arguments in memory consolidation
Fixes #1042. When the LLM returns tool call arguments as a dict or
JSON string instead of parsed values, memory consolidation would fail
with "TypeError: data must be str, not dict".

Changes:
- Add type guard in MemoryStore.consolidate() to parse string arguments
  and reject unexpected types gracefully
- Add regression tests covering dict args, string args, and edge cases
2026-02-23 13:59:49 -03:00
Re-bin 1cfcc647b7 fix(loop): resolve conflicts with main and improve /new handler 2026-02-22 17:11:59 +00:00
Re-bin ab026c5131 refactor: extract memory consolidation to MemoryStore, slim down AgentLoop 2026-02-21 08:14:46 +00:00
Re-bin 94c21fc235 feat: redesign memory system — two-layer architecture with grep-based retrieval 2026-02-12 15:02:52 +00:00
Re-bin ac527d40d7 fix: unify skill metadata format 2026-02-01 18:45:42 +00:00
Re-bin d4cc48afd5 🐈nanobot: hello world! 2026-02-01 07:36:42 +00:00