context.history_archive
History archive — persists the full conversation history for search.
The full conversation history (before compression) is continuously
saved to a JSON file. A search_conversation_history tool allows
the agent to look up specific details from compressed messages.
HistoryArchive Objects
class HistoryArchive()
Persist and search the full conversation history.
Parameters
archive_path : str Path to the JSONL archive file.
append
def append(message: dict[str, Any]) -> None
Append a message to the archive.
append_many
def append_many(messages: list[dict[str, Any]]) -> None
Append multiple messages to the archive.
search
def search(query: str, max_results: int = 10) -> list[dict[str, Any]]
Search the archive for messages matching the query.
Uses simple case-insensitive substring matching.
Parameters
query : str Search text. max_results : int Maximum number of results.
Returns
list[dict] Matching archived messages (most recent first).
get_total_messages
def get_total_messages() -> int
Return the total number of archived messages.
search_conversation_history_tool_fn
def search_conversation_history_tool_fn(
archive: HistoryArchive) -> dict[str, Any]
Create a tool definition for the agent to search conversation history.
Returns a dict with name, description, parameters and function
suitable for registration as a PydanticAI tool.