Adding Logs to the Agent › Log Levels for Different Information

Michael BrenndoerferAugust 6, 20251 min read
AI Agent HandbookAll chapters
Part 12 of 15Observability and Debugging - Peering Inside the Agent
Chapter 33Adding Logs to the Agent › Log Levels for Different Information
Reading section 5 of 10 · Log Levels for Different Information · 1 minSection 5 of 10 · 1 min

Book contents

Section 5 of 10 · 1 min read

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:

In[11]:
Code
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 None

With 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.