Skip to content

feat(a2a): durable history compression across A2A turns#66

Merged
SasCezar merged 4 commits into
mainfrom
feat/28-history-compression-hook
Jun 23, 2026
Merged

feat(a2a): durable history compression across A2A turns#66
SasCezar merged 4 commits into
mainfrom
feat/28-history-compression-hook

Conversation

@SasCezar

@SasCezar SasCezar commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds compression.py with checkpoint find/persist helpers that serialise the compressed message baseline into A2A task history as a synthetic metadata message
  • A2AExecutor now restores the most-recent checkpoint on each turn via _build_history, keeping LLM message counts bounded long-term instead of growing with every turn
  • State._compression_context (private attr) is populated by HistoryCompressionHook after compression fires so the executor can persist it
  • Fixes ClassVar annotations on AgentHook.name and HistoryCompressionHook.name so Pydantic does not treat them as model fields

Test plan

  • tests/unit/hooks/test_history_compression.py — new unit tests verify _compression_context is set/unset correctly
  • tests/unit/memory/test_react_loop_memory.py — new tests verify memory-triggered compression and memory.update() still receives correct messages
  • tests/integration/a2a/test_history.py — new integration tests verify message count stays bounded over 4 and 8 turns
  • tests/integration/hooks/test_compression_agent.py — new integration test suite for compression hook behaviour end-to-end

SasCezar added 3 commits June 4, 2026 15:29
Implements issue #28. Adds HistoryCompressionHook to
src/ant_ai/hooks/builtins/ that compresses older conversation history
via LLM summarisation when a configurable threshold (max_messages and/or
max_token_ratio) is exceeded, keeping the most recent keep_last messages
verbatim.

Also restructures the hooks namespace for consistency with the rest of
the codebase: hooks/adapters/ is split into hooks/builtins/ (first-party, mirrors tools/builtins/) and hooks/integrations/ (third-party wrappers, mirrors observer/integrations/). Adds name: str = "hook" to AgentHook protocol so all hooks expose an identifier.

Closes #28
Persists the compressed baseline as a synthetic checkpoint message in
A2A task history so future turns restore it instead of replaying the
full BFS chain, keeping LLM message counts bounded long-term.

Also fixes ClassVar annotations on AgentHook.name and
HistoryCompressionHook.name so Pydantic no longer treats them as fields.
pytest rootdir-based imports don't need __init__.py and having them
causes ModuleNotFoundError when parent directories lack them.
@SasCezar SasCezar added feat New feature (feat: commit type) bump:minor New backwards-compatible functionality (x.Y.0) labels Jun 5, 2026
@SasCezar SasCezar self-assigned this Jun 5, 2026
@codecov

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.57173% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/ant_ai/a2a/compression.py 94.44% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Consistent with the same fix applied to AgentHook and
HistoryCompressionHook — instance variable cannot override a ClassVar.
@SasCezar
SasCezar added this pull request to the merge queue Jun 23, 2026
Merged via the queue into main with commit ae0ef3f Jun 23, 2026
5 checks passed
@SasCezar
SasCezar deleted the feat/28-history-compression-hook branch June 23, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bump:minor New backwards-compatible functionality (x.Y.0) feat New feature (feat: commit type)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant