{% set in_tool_group = namespace(value=false) %}
{% for msg in messages %}
{% if msg.role in ("tool_call", "tool_result") %}
{% if not in_tool_group.value %}
{% set in_tool_group.value = true %}
{% endif %}
{% if msg.role == "tool_call" %}
Tool: {{ msg.tool_name }}
{{ msg.tool_arguments }}
{% elif msg.role == "tool_result" %}
{% set html_content = msg.tool_output | agent_extract_html %}
{% if html_content %}