feat: allow custom session metadata enrichment in watch() API#439
feat: allow custom session metadata enrichment in watch() API#439arcgod-design wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an optional ChangesCustom Session Metadata Enrichment
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
agentwatch/core/watcher.py (1)
583-599:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftMetadata is not propagated for framework-specific adapters.
Line 584, Line 588, Line 592, and Line 596 call framework-specific attachers without forwarding
metadata, while only the generic fallback receives it at Line 609. This breaks the watch-level contract for LangChain/LangGraph/Autogen/Smolagents sessions.Also applies to: 609-610
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@agentwatch/core/watcher.py` around lines 583 - 599, The framework-specific attacher functions _attach_langchain, _attach_langgraph, _attach_autogen, and _attach_smolagents are being called without passing the metadata argument, while the generic fallback case does pass it. Add metadata as an argument to each of these four function calls to ensure consistent metadata propagation across all framework adapters and maintain the watch-level contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@agentwatch/core/watcher.py`:
- Line 243: The metadata dictionary is stored by reference in
self._session_metadata at line 243 and reused directly in TOOL_CALL events at
lines 310-311 and 386-387. Any downstream mutation of the metadata dict will
affect all future events. Fix this by creating a snapshot copy when storing
metadata in self._session_metadata initialization, and creating independent
copies of self._session_metadata when emitting TOOL_CALL events at those
locations to ensure each event has its own isolated metadata dictionary.
---
Outside diff comments:
In `@agentwatch/core/watcher.py`:
- Around line 583-599: The framework-specific attacher functions
_attach_langchain, _attach_langgraph, _attach_autogen, and _attach_smolagents
are being called without passing the metadata argument, while the generic
fallback case does pass it. Add metadata as an argument to each of these four
function calls to ensure consistent metadata propagation across all framework
adapters and maintain the watch-level contract.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 78293598-1cdf-43a0-b099-2f28a82db6cf
📒 Files selected for processing (3)
agentwatch/core/watcher.pyagentwatch/tracing/collector.pytests/test_watcher.py
🧪 PR Test Results
Python 3.12 · commit 5eb85df |
|
@arcgod-design please check your prs |
Summary
metadatakeyword argument towatch()andGenericAdapter.__init__()TraceCollector.ingest()Changes
agentwatch/core/watcher.py: Addedmetadataparam toGenericAdapter.__init__,_emit_safely,_async_emit, andwatch(). Merges session metadata into all events.agentwatch/tracing/collector.py: Seeds session metadata from first event's metadata on session creation.tests/test_watcher.py: Added 5 new tests for metadata functionality.Usage
Testing
All 28 watcher tests pass, including 5 new metadata tests:
test_watch_metadata_attached_to_eventstest_watch_metadata_merged_with_call_metadatatest_watch_no_metadata_empty_dicttest_generic_adapter_metadata_storedtest_generic_adapter_empty_metadataCloses
closes #147
Summary by CodeRabbit
SESSION_STARTand merged into subsequent agent events.