Skip to content

test: add unit tests for TokenAwareConversationManager#2040

Open
FlorentLa wants to merge 1 commit intostrands-agents:mainfrom
FlorentLa:feat/token-aware-tests-only
Open

test: add unit tests for TokenAwareConversationManager#2040
FlorentLa wants to merge 1 commit intostrands-agents:mainfrom
FlorentLa:feat/token-aware-tests-only

Conversation

@FlorentLa
Copy link
Copy Markdown

Motivation

Adds comprehensive test coverage for the TokenAwareConversationManager introduced in #2038. Split into a separate PR to stay under the size limit.

Merge after #2038 — this PR imports the class added in that PR.

Public API Changes

No public API changes.

Testing

35 unit tests covering:

  • Initialization with default and custom parameters
  • Hook registration and BeforeModelCallEvent callback (token capture from cycles[-2])
  • ANSI sanitization of tool results
  • Tool result truncation pass
  • Tool pair adjustment logic (avoiding orphaned toolUse/toolResult)
  • Full compact flow: truncation → summarization → trim fallback
  • LLM summarization via model.stream() (no agent re-entry)
  • State persistence (get_state / restore_from_session)
  • Role alternation after compaction (summary as assistant role)
  • removed_message_count tracking across multiple compactions

35 tests covering all four compaction passes, hook callbacks,
state persistence, role alternation after summarization, and
edge cases (too few messages, summarization failure fallback).

Depends on strands-agents#2038 being merged first (imports TokenAwareConversationManager).
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.

1 participant