@@ -125,6 +125,7 @@ def from_tool(cls, tool: "Tool") -> "ToolInfo":
125125 "tool_result_resource" ,
126126 "json" ,
127127 "pdf" ,
128+ "thinking" ,
128129]
129130"""
130131A discriminated union of all content types.
@@ -682,6 +683,40 @@ def __repr__(self, indent: int = 0):
682683 return " " * indent + f"<ContentPDF size={ len (self .data )} >"
683684
684685
686+ class ContentThinking (Content ):
687+ """
688+ Thinking/reasoning content
689+
690+ This content type represents reasoning traces from models that support
691+ extended thinking (like OpenAI's o-series models). The thinking content
692+ is not meant to be sent back to the model but is useful for debugging
693+ and understanding the model's reasoning process.
694+
695+ Parameters
696+ ----------
697+ thinking
698+ The thinking/reasoning text from the model.
699+ extra
700+ Additional metadata associated with the thinking content (e.g.,
701+ encrypted content, status information).
702+ """
703+
704+ thinking : str
705+ extra : Optional [dict [str , Any ]] = None
706+
707+ content_type : ContentTypeEnum = "thinking"
708+
709+ def __str__ (self ):
710+ return f"<thinking>\n { self .thinking } \n </thinking>\n "
711+
712+ def _repr_markdown_ (self ):
713+ return self .__str__ ()
714+
715+ def __repr__ (self , indent : int = 0 ):
716+ preview = self .thinking [:50 ] + "..." if len (self .thinking ) > 50 else self .thinking
717+ return " " * indent + f"<ContentThinking thinking='{ preview } '>"
718+
719+
685720ContentUnion = Union [
686721 ContentText ,
687722 ContentImageRemote ,
@@ -692,6 +727,7 @@ def __repr__(self, indent: int = 0):
692727 ContentToolResultResource ,
693728 ContentJson ,
694729 ContentPDF ,
730+ ContentThinking ,
695731]
696732
697733
@@ -724,6 +760,8 @@ def create_content(data: dict[str, Any]) -> ContentUnion:
724760 return ContentJson .model_validate (data )
725761 elif ct == "pdf" :
726762 return ContentPDF .model_validate (data )
763+ elif ct == "thinking" :
764+ return ContentThinking .model_validate (data )
727765 else :
728766 raise ValueError (f"Unknown content type: { ct } " )
729767
0 commit comments