97 """Count tokens in a message list.
99 This is the replacement for the old _estimate_tokens() heuristic.
100 Counts content, reasoning_content, and tool_calls for each message.
103 messages: List of message dicts with 'role', 'content', etc.
106 Total estimated token count for the message list.
118 content = msg.get(
"content",
"")
119 if isinstance(content, str):
123 role = msg.get(
"role",
"")
128 reasoning = msg.get(
"reasoning_content",
"")
129 if isinstance(reasoning, str):
133 tool_calls = msg.get(
"tool_calls", [])
134 if tool_calls
and isinstance(tool_calls, list):
135 for tc
in tool_calls:
136 fn = tc.get(
"function", {})
137 if isinstance(fn, dict):