@@ -162,6 +162,49 @@ def to_json(self) -> str:
162162 """Convert the ActivityModelInput to a JSON string."""
163163 return to_json (self ).decode ('utf-8' )
164164
165+ @classmethod
166+ def from_json (cls , json_str : str ) -> 'ActivityModelInput' :
167+ """Create an ActivityModelInput instance from a JSON string."""
168+ import json
169+ data = json .loads (json_str )
170+
171+ # Convert complex types back from dictionaries
172+ if 'model_settings' in data and isinstance (data ['model_settings' ], dict ):
173+ data ['model_settings' ] = ModelSettings (** data ['model_settings' ])
174+
175+ if 'tracing' in data and isinstance (data ['tracing' ], int ):
176+ data ['tracing' ] = ModelTracingInput (data ['tracing' ])
177+
178+ # Convert tool inputs back to proper types
179+ if 'tools' in data and data ['tools' ]:
180+ converted_tools = []
181+ for tool_data in data ['tools' ]:
182+ if isinstance (tool_data , dict ):
183+ # Check the tool type and convert accordingly
184+ if 'name' in tool_data and 'description' in tool_data and 'params_json_schema' in tool_data :
185+ # FunctionToolInput
186+ converted_tools .append (FunctionToolInput (** tool_data ))
187+ elif 'tool_config' in tool_data :
188+ # HostedMCPToolInput
189+ converted_tools .append (HostedMCPToolInput (** tool_data ))
190+ else :
191+ # For other tool types like FileSearchTool, WebSearchTool, etc.
192+ # These might be already properly serialized/deserialized by pydantic_core
193+ converted_tools .append (tool_data )
194+ else :
195+ converted_tools .append (tool_data )
196+ data ['tools' ] = converted_tools
197+
198+ # Convert handoffs back to proper types
199+ if 'handoffs' in data and data ['handoffs' ]:
200+ data ['handoffs' ] = [HandoffInput (** handoff ) for handoff in data ['handoffs' ]]
201+
202+ # Convert output_schema back to proper type
203+ if 'output_schema' in data and data ['output_schema' ] and isinstance (data ['output_schema' ], dict ):
204+ data ['output_schema' ] = AgentOutputSchemaInput (** data ['output_schema' ])
205+
206+ return cls (** data )
207+
165208
166209class ModelActivity :
167210 """Class wrapper for model invocation activities to allow model customization. By default, we use an OpenAIProvider with retries disabled.
0 commit comments