Module agents.llm.context.readonly
Classes
class ReadOnlyChatContext (items: List[ChatItem])-
Expand source code
class ReadOnlyChatContext(ChatContext): """A read-only view over a ChatContext's items. All read operations (items, messages, copy, fork, get_by_id, active_config_at, serialization) work normally. Every mutating operation raises ``RuntimeError``. Used when a shared context is handed to an agent that must not mutate the parent. """ def __init__(self, items: List[ChatItem]): # Hold a reference to the live items list — this is a view, not a copy. self._items = items def _readonly(self, *args, **kwargs): raise RuntimeError(_MUTATION_ERROR) async def _readonly_async(self, *args, **kwargs): raise RuntimeError(_MUTATION_ERROR) # Sync mutators add_message = _readonly add_function_call = _readonly add_function_output = _readonly add_handoff = _readonly add_config_update = _readonly insert = _readonly insert_many = _readonly truncate = _readonly cleanup = _readonly # Async mutators summarize = _readonly_async merge = _readonly_async merge_result = _readonly_async merge_with_summary = _readonly_asyncA read-only view over a ChatContext's items.
All read operations (items, messages, copy, fork, get_by_id, active_config_at, serialization) work normally. Every mutating operation raises
RuntimeError. Used when a shared context is handed to an agent that must not mutate the parent.Initialize the chat context.
Args
items:Optional[List[ChatItem]]- Initial list of chat items. If None, starts with empty context.
Ancestors
Inherited members
ChatContext:active_config_atadd_config_updateadd_function_calladd_function_outputadd_handoffadd_messagecleanupcopyemptyestimated_tokensforkfork_brieffork_filteredfrom_dictget_by_idinsertinsert_manyitemsmergemerge_resultmerge_with_summarymessagessummarizeto_anthropic_messagesto_dictto_google_contentsto_openai_messagestruncateturn_count