@@ -228,6 +228,7 @@ async def store_message(
228228 * ,
229229 blob : MessageBlob ,
230230 format : Literal ["acontext" , "openai" , "anthropic" , "gemini" ] = "openai" ,
231+ parent_id : str | None = None ,
231232 meta : dict [str , Any ] | None = None ,
232233 file_field : str | None = None ,
233234 file : (
@@ -243,6 +244,7 @@ async def store_message(
243244 session_id: The UUID of the session.
244245 blob: The message blob in Acontext, OpenAI, Anthropic, or Gemini format.
245246 format: The format of the message blob. Defaults to "openai".
247+ parent_id: Optional parent message UUID for branching. Defaults to None.
246248 meta: Optional user-provided metadata for the message. This metadata is stored
247249 separately from the message content and can be retrieved via get_messages().metas
248250 or updated via patch_message_meta(). Works with all formats.
@@ -272,6 +274,8 @@ async def store_message(
272274 payload : dict [str , Any ] = {
273275 "format" : format ,
274276 }
277+ if parent_id is not None :
278+ payload ["parent_id" ] = parent_id
275279 if meta is not None :
276280 payload ["meta" ] = meta
277281
@@ -369,6 +373,7 @@ async def get_messages(
369373 * ,
370374 limit : int | None = None ,
371375 cursor : str | None = None ,
376+ leaf_id : str | None = None ,
372377 with_asset_public_url : bool | None = None ,
373378 with_events : bool | None = None ,
374379 format : Literal ["acontext" , "openai" , "anthropic" , "gemini" ] = "openai" ,
@@ -382,6 +387,7 @@ async def get_messages(
382387 session_id: The UUID of the session.
383388 limit: Maximum number of messages to return. Defaults to None.
384389 cursor: Cursor for pagination. Defaults to None.
390+ leaf_id: Optional leaf message UUID to read one root-to-leaf branch path. Defaults to None.
385391 with_asset_public_url: Whether to include presigned URLs for assets. Defaults to None.
386392 format: The format of the messages. Defaults to "openai". Supports "acontext", "openai", "anthropic", or "gemini".
387393 time_desc: Order by created_at descending if True, ascending if False. Defaults to None.
@@ -404,9 +410,19 @@ async def get_messages(
404410 Returns:
405411 GetMessagesOutput containing the list of messages and pagination information.
406412 """
413+ if leaf_id is not None :
414+ if limit is not None :
415+ raise ValueError ("leaf_id cannot be combined with limit" )
416+ if cursor is not None :
417+ raise ValueError ("leaf_id cannot be combined with cursor" )
418+ if time_desc is not None :
419+ raise ValueError ("leaf_id cannot be combined with time_desc" )
420+
407421 params : dict [str , Any ] = {}
408422 if format is not None :
409423 params ["format" ] = format
424+ if leaf_id is not None :
425+ params ["leaf_id" ] = leaf_id
410426 params .update (
411427 build_params (
412428 limit = limit ,
0 commit comments