Skip to content

feat: add batch write optimization to TrajectoryRecorder - #448

Open
lxcxjxhx wants to merge 2 commits into
bytedance:mainfrom
lxcxjxhx:feat/trajectory-batch-write-pr4
Open

feat: add batch write optimization to TrajectoryRecorder#448
lxcxjxhx wants to merge 2 commits into
bytedance:mainfrom
lxcxjxhx:feat/trajectory-batch-write-pr4

Conversation

@lxcxjxhx

Copy link
Copy Markdown

Motivation

TrajectoryRecorder writes to disk after every LLM interaction, causing excessive I/O operations during long-running tasks. This PR adds a buffer mechanism to batch writes and reduce disk I/O.

Changes

1. TrajectoryRecorder Buffer (trae_agent/utils/trajectory_recorder.py)

  • Added \�uffer_size\ parameter to _init_\ (default: 10)
  • Added _pending_writes\ counter to track buffered writes
  • Added \ lush()\ method for manual buffer flushing
  • Implemented batch write logic in
    ecord_llm_interaction()\
  • Automatically saves to disk when buffer is full

2. Buffer Management

  • Each interaction increments _pending_writes\ counter
  • When counter reaches \�uffer_size, automatically calls \save_trajectory()\
  • Manual \ lush()\ method ensures data can be saved immediately when needed
  • Default buffer size of 10 is configurable

Testing

  • Created \ ests/utils/test_trajectory_recorder.py\ with 7 test cases
  • Covers buffer mechanism, batch writes, manual flush, and edge cases
  • All tests pass

Checklist

  • Code follows project coding standards
  • Added comprehensive test cases
  • All tests pass
  • No unnecessary dependencies added
  • Changes are backward compatible

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