MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / AssistantMessage

Class AssistantMessage

src/message/types.py:223–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221
222
223class AssistantMessage(Message):
224 role: Literal['assistant'] = Field(default='assistant', description="The role of the messages author, in this case `assistant`.") # type: ignore
225 content: Union[str, List[Union[
226 ContentPartText,
227 ContentPartImage,
228 ContentPartAudio,
229 ContentPartVideo,
230 ContentPartPdf,
231 ContentPartRefusal,
232 ]]] = Field(description="The contents of the assistant message.")
233 name: Optional[str] = Field(default=None, description="An optional name for the participant. Provides the model information to differentiate between participants of the same role.") # type: ignore
234 refusal: Optional[str] = Field(default=None, description="The refusal message by the assistant.") # type: ignore
235 tool_calls: List[ToolCall] = Field(default=[], description="The tool calls generated by the model, such as function calls.") # type: ignore
236
237 @property
238 def text(self) -> str:
239 """
240 Automatically parse the text inside content, whether it's a string or a list of content parts.
241 """
242 if isinstance(self.content, str):
243 return self.content
244 elif isinstance(self.content, list):
245 return '\n'.join([str(part) for part in self.content])
246 else:
247 return ''
248
249 def __str__(self) -> str:
250 return f'AssistantMessage(content={self.text})'
251
252 def __repr__(self) -> str:
253 return f'AssistantMessage(content={repr(self.text)})'

Callers 4

add_eventMethod · 0.90
add_eventMethod · 0.90
add_eventMethod · 0.90
add_eventMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected