Format Percent • AI Agent SDK

format_percent: Smart percentage formatting for context utilization display.

format_percent

Function

</div>

This function is defined in the context module.

Smart percentage formatting for context utilization display.

  • For values &lt; 0.1%: shows “&lt;0.1%”
  • For values &lt; 1%: shows 2 decimal places (e.g., “0.02%”)
  • For values &gt;= 1%: shows 1 decimal place (e.g., “5.3%”)

Signature

python
def format_percent(value: float) -> str

Parameters

ParamField float

A ratio (0.0 to 1.0+), NOT already multiplied by 100

Returns

ResponseField str

Formatted percentage string

Source

View on GitHub

praisonaiagents/context/__init__.py at line 44