Adding Logs to the Agent › Log Levels for Different Information
AI Agent HandbookAll chapters Adding Logs to the Agent › Log Levels for Different InformationOne section · Sections in this chapter5 / 10 ↓
Python's logging module provides different levels for different types of information. Using the right level helps you filter logs based on what you're looking for.
INFO: Normal operation milestones. Use this for standard agent actions like "received query", "selected tool", "generated response".
DEBUG: Detailed information useful during development. Use this for verbose details like the full content of prompts or intermediate data structures.
WARNING: Something unexpected happened, but the agent recovered. Use this for cases like "tool call failed, retrying" or "no relevant memory found".
ERROR: Something went wrong that prevented normal operation. Use this when a tool crashes or the agent can't complete a request.
The following example assigns a level to each outcome:
def use_calculator(expression):
logger.debug(f"Calculator input (full): {expression}")
try:
result = eval(expression)
logger.info(f"Calculator computed: {result}")
return result
except SyntaxError as e:
logger.warning(f"Invalid expression: {expression}, error: {e}")
return "I couldn't understand that mathematical expression"
except Exception as e:
logger.error(f"Calculator failed unexpectedly: {e}")
return NoneWith log levels, you can control how much detail you see. During development, set the level to DEBUG to see everything. In production, set it to INFO or WARNING to reduce noise.