optimize • AI Agent SDK

optimize: Optimize messages to fit within target tokens.

optimize

Method

</div>

This is a method of the ContextOptimizer class in the models module.

Optimize messages to fit within target tokens.

Signature

python
def optimize(messages: List[Dict[str, Any]], target_tokens: int, ledger: ContextLedger) -> tuple[List[Dict[str, Any]], OptimizationResult]

Parameters

ParamField List

No description available.

ParamField int

No description available.

ParamField ContextLedger

No description available.

Returns

ResponseField tuple[List[Dict[str, Any]], OptimizationResult]

The result of the operation.

Source

View on GitHub

praisonaiagents/context/models.py at line 466