MCPcopy
hub / github.com/langchain-ai/deepagents / format_token_count

Function format_token_count

libs/code/deepagents_code/_session_stats.py:139–152  ·  view source on GitHub ↗

Format a token count into a human-readable short string. Args: count: Number of tokens. Returns: Formatted string like `'12.5K'`, `'1.2M'`, or `'500'`.

(count: int)

Source from the content-addressed store, hash-verified

137
138
139def format_token_count(count: int) -> str:
140 """Format a token count into a human-readable short string.
141
142 Args:
143 count: Number of tokens.
144
145 Returns:
146 Formatted string like `'12.5K'`, `'1.2M'`, or `'500'`.
147 """
148 if count >= 1_000_000: # noqa: PLR2004
149 return f"{count / 1_000_000:.1f}M"
150 if count >= 1000: # noqa: PLR2004
151 return f"{count / 1000:.1f}K"
152 return str(count)

Callers 15

print_usage_tableFunction · 0.90
_handle_commandMethod · 0.90
_handle_offloadMethod · 0.90
test_small_countsMethod · 0.90
test_thousandsMethod · 0.90
test_millionsMethod · 0.90
format_offload_limitFunction · 0.85
perform_offloadFunction · 0.85
_format_tokenMethod · 0.85
test_zeroMethod · 0.85
test_below_thresholdMethod · 0.85
test_at_thresholdMethod · 0.85

Calls

no outgoing calls

Tested by 15

test_small_countsMethod · 0.72
test_thousandsMethod · 0.72
test_millionsMethod · 0.72
test_zeroMethod · 0.68
test_below_thresholdMethod · 0.68
test_at_thresholdMethod · 0.68
test_above_thresholdMethod · 0.68
test_large_valueMethod · 0.68
test_millionsMethod · 0.68
test_above_millionMethod · 0.68
test_small_countMethod · 0.68
test_thousandsMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…