feat(plugins): add thread-safe LogCollectorPlugin for event logging #2427
+618
−1
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.
This commit introduces the
LogCollectorPlugin, a plugin that collects execution logs from ADK callbacks in asynchronous environments. Logs are organized by session ID for retrieval.The plugin uses
asyncio.Lockto ensure thread-safe logging. Logs are stored in adefaultdict(list)indexed by session ID and can be retrieved with theget_logs_by_sessionmethod.The plugin implements the following callback hooks to log contextual data:
on_user_messagebefore_run,after_runbefore_agent,after_agentbefore_model,after_model,on_model_errorbefore_tool,after_tool,on_tool_erroron_eventEach log entry includes the callback type and relevant data, such as invocation ID, agent name, tool name, function call ID, arguments, and results or errors.