DEV Community

Jamal
Jamal

Posted on

# 🔍 Lab 03: Logging and Debugging | Strands Agentic AI

AI agents can perform complex tasks, call tools, and interact with external services. But what happens when something goes wrong?

Without logging, debugging an AI agent can feel like trying to solve a puzzle with half the pieces missing.

In this lab, you'll learn how to enable logging in Strands Agents so you can observe what's happening behind the scenes, understand agent behavior, and troubleshoot issues more effectively.


🚀 What You'll Learn

By the end of this lab, you'll understand:

  • How logging works in Strands Agents
  • How to enable DEBUG logs
  • How to inspect agent execution flow
  • How to monitor tool invocations
  • How logging helps troubleshoot agent issues

🤖 Why Logging Matters in Agentic AI

Traditional applications usually follow a predictable flow.

AI agents are different.

A single prompt can trigger multiple reasoning steps, tool calls, and external API requests.

User Prompt
     ↓
Agent Reasoning
     ↓
Tool Selection
     ↓
HTTP Request
     ↓
Response Processing
     ↓
Final Answer
Enter fullscreen mode Exit fullscreen mode

If something fails during this process, logs help us understand:

  • Which tool was selected
  • What requests were sent
  • What responses were received
  • Where failures occurred
  • How the agent reached its final answer

Think of logging as the flight recorder for your AI agent.


🛠️ Prerequisites

Before starting, make sure you have:

  • Python 3.10+
  • AWS Account
  • Amazon Bedrock access
  • Access to a model such as amazon.nova-2-lite-v1
  • AWS credentials configured
  • uv installed

📜 The Script

Let's start by looking at the complete example.

# This lab is to teach you about logging

from strands import Agent
from strands.models.bedrock import BedrockModel
from strands_tools import file_read, file_write, http_request
import logging

# Configure the root strands logger
logging.getLogger("strands").setLevel(logging.DEBUG)

# Add a handler to display logs in the terminal
logging.basicConfig(
    format="%(levelname)s | %(name)s | %(message)s",
    handlers=[logging.StreamHandler()]
)

# Configure the Bedrock model
bedrock_model = BedrockModel(
    model_id="<YOUR_MODEL_ID>",
    region_name="eu-west-2",
    temperature=0.3,
)

system_prompt = """
Weather Information
    - You can also make HTTP requests to the National Weather Service API.
    - Process and display weather forecast data for locations in the United States.
"""

# Create the agent with tools
local_agent = Agent(
    system_prompt=system_prompt,
    model=bedrock_model,
    tools=[http_request],
)

# Ask the agent a question
local_agent("what is the weather in new york?")
Enter fullscreen mode Exit fullscreen mode

Now let's break it down.


⚙️ Step 1: Configure Logging

import logging

logging.getLogger("strands").setLevel(logging.DEBUG)

logging.basicConfig(
    format="%(levelname)s | %(name)s | %(message)s",
    handlers=[logging.StreamHandler()]
)
Enter fullscreen mode Exit fullscreen mode

What is happening here?

First, we configure Python's built-in logging module.

logging.getLogger("strands").setLevel(logging.DEBUG)
Enter fullscreen mode Exit fullscreen mode

This tells Strands to emit detailed debugging information.

The DEBUG level provides maximum visibility into agent execution.

We then configure how logs appear in the terminal:

logging.basicConfig(
    format="%(levelname)s | %(name)s | %(message)s"
)
Enter fullscreen mode Exit fullscreen mode

Example:

DEBUG | strands.agent | Processing user request
INFO | strands.tools | Executing HTTP request
Enter fullscreen mode Exit fullscreen mode

This makes logs easy to read and troubleshoot.


⚙️ Step 2: Configure the Bedrock Model

bedrock_model = BedrockModel(
    model_id="<YOUR_MODEL_ID>",
    region_name="eu-west-2",
    temperature=0.3,
)
Enter fullscreen mode Exit fullscreen mode

Here we create the LLM that powers our agent.

Parameters

Parameter Description
model_id Bedrock model identifier
region_name AWS Region
temperature Controls response randomness

A lower temperature produces more consistent and predictable responses.


⚙️ Step 3: Define the Agent's Role

system_prompt = """
Weather Information
    - You can also make HTTP requests to the National Weather Service API.
    - Process and display weather forecast data for locations in the United States.
"""
Enter fullscreen mode Exit fullscreen mode

The system prompt acts as the agent's instructions.

It tells the model:

  • What task it should perform
  • Which information sources are available
  • How it should behave

In this case, the agent is focused on retrieving weather information.


⚙️ Step 4: Add the HTTP Tool

tools=[http_request]
Enter fullscreen mode Exit fullscreen mode

The http_request tool gives the agent the ability to access external APIs.

Without tools, the agent can only rely on its training data.

With tools, it can fetch live information from the internet.

For weather data, the agent can query APIs and process real-time forecasts.


⚙️ Step 5: Create the Agent

local_agent = Agent(
    system_prompt=system_prompt,
    model=bedrock_model,
    tools=[http_request],
)
Enter fullscreen mode Exit fullscreen mode

This combines:

  • The model
  • The instructions
  • The available tools

into a working AI agent.


▶️ Run the Agent

Invoke the agent using:

local_agent("what is the weather in new york?")
Enter fullscreen mode Exit fullscreen mode

The agent will:

  1. Analyze the request
  2. Decide whether a tool is needed
  3. Call the HTTP tool
  4. Retrieve weather information
  5. Generate a final response

📊 Example Debug Output

When running the script, you'll see logs similar to:

DEBUG | strands.agent | Processing user request
DEBUG | strands.agent | Selecting tool
INFO  | strands.tools | Executing HTTP request
INFO  | strands.tools | Response received
DEBUG | strands.agent | Generating final answer
Enter fullscreen mode Exit fullscreen mode

The exact output may vary depending on the model and SDK version.


🔍 Understanding the Log Levels

DEBUG

Most detailed level.

Useful during development.

DEBUG | Agent selecting tool
Enter fullscreen mode Exit fullscreen mode

INFO

General execution information.

INFO | HTTP request executed
Enter fullscreen mode Exit fullscreen mode

WARNING

Something unexpected happened, but execution continues.

WARNING | Missing optional parameter
Enter fullscreen mode Exit fullscreen mode

ERROR

Execution failed.

ERROR | Failed to call external API
Enter fullscreen mode Exit fullscreen mode

💡 Why Developers Love Logs

Imagine your agent gives an incorrect answer.

Without logs:

❌ No idea what happened.

With logs:

✅ See which tool was selected

✅ Inspect API requests

✅ Inspect responses

✅ Find failures quickly

✅ Improve prompts and tools

Logs dramatically reduce debugging time.


🎯 Key Takeaways

  • Logging provides visibility into agent execution
  • DEBUG logs help trace reasoning and tool usage
  • Python's built-in logging module works seamlessly with Strands
  • Logs make troubleshooting faster and easier
  • Observability is essential for production-ready AI agents

📚 Source Code

GitHub Repository:

https://github.com/d3vjamal/strands-agents-labs


🚀 Next Lab

In the next lab, we'll explore custom tools and learn how to extend Strands Agents with capabilities tailored to your own applications.

Top comments (0)