Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/strands/types/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def converse(
"""
logger.debug("formatting request")
request = self.format_request(messages, tool_specs, system_prompt)
logger.debug("formatted request=<%s>", request)

logger.debug("invoking model")
response = self.stream(request)
Expand Down
29 changes: 29 additions & 0 deletions tests/strands/types/models/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,32 @@ def test_structured_output(model):
response = model.structured_output(Person)

assert response == Person(name="test", age=20)


def test_converse_logging(model, messages, tool_specs, system_prompt, caplog):
"""Test that converse method logs the formatted request at debug level."""
import logging

# Set the logger to debug level to capture debug messages
caplog.set_level(logging.DEBUG, logger="strands.types.models.model")

# Execute the converse method
response = model.converse(messages, tool_specs, system_prompt)
list(response) # Consume the generator to trigger all logging

# Check that the expected log messages are present
assert "formatting request" in caplog.text
assert "formatted request=" in caplog.text
assert "invoking model" in caplog.text
assert "got response from model" in caplog.text
assert "finished streaming response from model" in caplog.text

# Check that the formatted request is logged with the expected content
expected_request_str = str(
{
"messages": messages,
"tool_specs": tool_specs,
"system_prompt": system_prompt,
}
)
assert expected_request_str in caplog.text