Using logging_plugin in Agent Engine to Log Custom Fields #4202
Replies: 2 comments
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: To log custom fields like Hello! As an AI agent, I can provide some guidance on how to best approach logging custom fields with ADK in Agent Engine. The standard For your use case, the recommended pattern is to leverage ADK's session 1. Store Per-Request Data in Session StateYour application should add the contextual information (like 2. Create a Custom Logging PluginYou can create your own plugin to inspect the Here is an example of a simple plugin that logs custom fields before a tool is executed: import logging
from google.adk.plugins import BasePlugin, ToolContext
class ContextualLoggingPlugin(BasePlugin):
"""A plugin to log contextual data from the session state."""
def __init__(self, logger):
self.logger = logger
def before_tool_callback(self, tool_context: ToolContext) -> None:
"""Called before a tool is executed."""
custom_fields = {
"user_email": tool_context.state.get("user_email"),
"country": tool_context.state.get("country"),
"tool_name": tool_context.tool_name,
"tool_parameters": tool_context.tool_parameters,
}
# Remove fields that are not set
custom_fields = {k: v for k, v in custom_fields.items() if v is not None}
if custom_fields:
self.logger.info("Executing tool with context: %s", custom_fields)
# In your main application setup:
# logger = ... (your configured logger)
# contextual_logger_plugin = ContextualLoggingPlugin(logger)
#
# agent_engine = AgentEngineApp(
# app=adk_app,
# plugins=[contextual_logger_plugin],
# ...
# )In this example, the 3. For Production: Use
|
Beta Was this translation helpful? Give feedback.
-
|
ttps://google.github.io/adk-docs/observability/bigquery-agent-analytics/ BigQuery Agent Analytics Plugin: the ADK offers a plugin to log detailed agent analytics to BigQuery. This allows you to run complex queries on your agent's behavior and performance, get out of box observability for both token usage, tool call/LLM call error rate and the latency for both tool call and LLM call immediately. The plugin just need one line code change to add plugin into your APP. With this plugin, you can monitor which tool/subagent would cost your token most in the whole agent life-cycle |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am building an Agent Engine application using ADK and deploying it via Agent Engine. A simplified version of the setup looks like this:
Question
I want to understand how to properly use the
logging_pluginwithin an agent that is deployed on Agent Engine.Specifically:
How can I attach or configure
logging_pluginfor agents running inside Agent Engine?What is the recommended way to log custom / contextual fields, such as:
user_emailcountryGoal
Any guidance, examples, or best practices for doing this with
logging_plugin+ Agent Engine would be very helpful.Beta Was this translation helpful? Give feedback.
All reactions