Skip to content

feat(agent): add long-term memory extraction and visualization#412

Open
newcat22 wants to merge 2 commits into
bytedance:mainfrom
newcat22:feature/long-term-memory
Open

feat(agent): add long-term memory extraction and visualization#412
newcat22 wants to merge 2 commits into
bytedance:mainfrom
newcat22:feature/long-term-memory

Conversation

@newcat22
Copy link
Copy Markdown

@newcat22 newcat22 commented May 9, 2026

Summary

  • Add LLM-powered memory extraction that compresses agent execution steps into human-readable Markdown documents with problem/conclusion pairs
  • Support manual and periodic triggers via factory pattern, with context compression when messages exceed 20
  • Add trae-cli memory subcommand for offline extraction from trajectory JSON files, and --extract-memory flag on run command
  • Add console visualization for memory documents in SimpleCLIConsole

New files

  • trae_agent/utils/long_term_memory.py — Core module: LLM extraction, Markdown rendering (MemoryDocument with to_markdown/from_markdown round-trip), memory message builder
  • trae_agent/utils/memory_trigger.py — Trigger factory: ManualMemoryTrigger, PeriodicMemoryTrigger, create_memory_trigger() factory
  • tests/utils/test_long_term_memory.py — 22 test cases covering config, triggers, document round-trip, memory injection, and end-to-end extraction

Modified files

  • trae_agent/utils/config.py — LongTermMemoryConfig dataclass + YAML parsing
  • trae_agent/agent/base_agent.py — Memory trigger integration in execute_task(), context compression in _run_llm_step(), inject_memory_into_messages(), extract_memory_now()
  • trae_agent/agent/agent.py — Wire up LongTermMemory creation and set_task()
  • trae_agent/cli.pymemory subcommand + --extract-memory flag
  • trae_agent/utils/cli/cli_console.py — set_memory_doc() base method
  • trae_agent/utils/cli/simple_console.py — Memory summary visualization with Rich Panels
  • trae_config.yaml.example — long_term_memory config examples

Test plan

  • All 84 existing + new tests pass
  • Ruff lint check passes
  • YAML config parsing for long_term_memory section
  • MemoryDocument to_markdown/from_markdown round-trip
  • ManualMemoryTrigger never fires, PeriodicMemoryTrigger fires at interval
  • create_memory_trigger() factory returns correct types
  • inject_memory_into_messages preserves system + memory + recent messages
  • extract_memory() with mock LLM produces correct sections
  • extract_and_save() creates Markdown file with correct content

Add LLM-powered memory extraction that compresses agent execution
steps into human-readable Markdown documents with problem/conclusion
pairs. Supports manual and periodic triggers via factory pattern,
context compression when messages exceed 20, and CLI commands
for offline extraction from trajectory files.
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Add --memory CLI flag to preload previous session memory into new
sessions, session ID tracking in memory files and index.json,
memory-list command for viewing session-memory associations, and
preloaded_sections that persist across set_task() calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants