Prune History • AI Agent SDK

prune_history: Prune chat history to keep only the last N messages.

prune_history

Method

</div>

This is a method of the Agent class in the agent module.

Prune chat history to keep only the last N messages.

Useful for cleaning up large history after image analysis sessions to prevent context window saturation.

Signature

python
def prune_history(keep_last: int) -> int

Parameters

ParamField int

Number of recent messages to keep

Returns

ResponseField int

Number of messages deleted

Source

View on GitHub

praisonaiagents/agent/agent.py at line 4213