feat: emit structured log records for context compression events#3982
Open
agent-morrow wants to merge 1 commit intocamel-ai:masterfrom
Open
feat: emit structured log records for context compression events#3982agent-morrow wants to merge 1 commit intocamel-ai:masterfrom
agent-morrow wants to merge 1 commit intocamel-ai:masterfrom
Conversation
Replace unstructured f-string logger.warning calls in _get_context_with_summarization (sync and async) with structured extra metadata: event_type, compression_mode, token counts, and thresholds. This makes compression boundaries machine-observable by contract rather than requiring downstream tooling to parse log message strings. Includes tests verifying the structured fields are present for both progressive and full compression modes.
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces unstructured f-string
logger.warningcalls in_get_context_with_summarization(sync and async) with structuredextrametadata, making compression boundaries machine-observable by contract.This is the narrower alternative to PR #3976 (callback hook), as discussed with @fengju0213 in this comment.
Changes
camel/agents/chat_agent.py— 4 logger calls updated:f"Summary tokens ({n}) exceed limit, full compression.""Context compression triggered"+extra={"event_type": "context_compression", "compression_mode": "full", "summary_token_count": ..., "token_limit": ..., "summary_window_ratio": ...}f"Token count ({n}) exceed threshold ({t}). Triggering summarization.""Context compression triggered"+extra={"event_type": "context_compression", "compression_mode": "progressive", "num_tokens": ..., "threshold": ..., "token_limit": ...}Both sync and async paths are updated identically.
test/agents/test_structured_compression_events.py— new test file verifying:event_type="context_compression"withcompression_mode="progressive"and token countsevent_type="context_compression"withcompression_mode="full"and summary token countsWhy
Downstream tooling (OpenTelemetry spans, behavioral attestation, monitoring hooks) currently has to parse logger message strings or diff token counts to detect compression boundaries. A stable
event_typeinextramakes compression observable without depending on message format.Backward compatibility
WARNINGextrafields are ignored by formatters that don't request them