MCPcopy
hub / github.com/langroid/langroid / ChatDocument

Class ChatDocument

langroid/agent/chat_document.py:127–571  ·  view source on GitHub ↗

Represents a message in a conversation among agents. All responders of an agent have signature ChatDocument -> ChatDocument (modulo None, str, etc), and so does the Task.run() method. Attributes: oai_tool_calls (Optional[List[OpenAIToolCall]]): Tool-calls from a

Source from the content-addressed store, hash-verified

125
126
127class ChatDocument(Document):
128 """
129 Represents a message in a conversation among agents. All responders of an agent
130 have signature ChatDocument -> ChatDocument (modulo None, str, etc),
131 and so does the Task.run() method.
132
133 Attributes:
134 oai_tool_calls (Optional[List[OpenAIToolCall]]):
135 Tool-calls from an OpenAI-compatible API
136 oai_tool_id2results (Optional[OrderedDict[str, str]]):
137 Results of tool-calls from OpenAI (dict is a map of tool_id -> result)
138 oai_tool_choice: ToolChoiceTypes | Dict[str, str]: Param controlling how the
139 LLM should choose tool-use in its response
140 (auto, none, required, or a specific tool)
141 function_call (Optional[LLMFunctionCall]):
142 Function-call from an OpenAI-compatible API
143 (deprecated by OpenAI, in favor of tool-calls)
144 tool_messages (List[ToolMessage]): Langroid ToolMessages extracted from
145 - `content` field (via JSON parsing),
146 - `oai_tool_calls`, or
147 - `function_call`
148 metadata (ChatDocMetaData): Metadata for the message, e.g. sender, recipient.
149 attachment (None | ChatDocAttachment): Any additional data attached.
150 """
151
152 reasoning: str = "" # reasoning produced by a reasoning LLM
153 content_any: Any = None # to hold arbitrary data returned by responders
154 # Original LLM response text including inline thought signatures
155 # (e.g. <thinking>...</thinking>). Only populated when reasoning was
156 # extracted from inline tags in the message text. Used by to_LLMMessage()
157 # to preserve thought signatures in message history, which is critical
158 # for models like Gemini 3 Flash and Amazon Nova that rely on seeing
159 # their own thought tags in context to maintain reasoning ability.
160 content_with_reasoning: Optional[str] = None
161 files: List[FileAttachment] = [] # list of file attachments
162 oai_tool_calls: Optional[List[OpenAIToolCall]] = None
163 oai_tool_id2result: Optional[OrderedDict[str, str]] = None
164 oai_tool_choice: ToolChoiceTypes | Dict[str, Dict[str, str] | str] = "auto"
165 function_call: Optional[LLMFunctionCall] = None
166 # tools that are explicitly added by agent response/handler,
167 # or tools recognized in the ChatDocument as handle-able tools
168 tool_messages: List[ToolMessage] = []
169 # all known tools in the msg that are in an agent's llm_tools_known list,
170 # even if non-used/handled
171 # (the list is populated by Agent.has_tool_message_attempt())
172 all_tool_messages: Optional[List[ToolMessage]] = None
173 # ID of the agent that populated all_tool_messages (for cache validity)
174 all_tool_messages_agent_id: Optional[str] = None
175
176 metadata: ChatDocMetaData
177 attachment: None | ChatDocAttachment = None
178
179 def __init__(self, **data: Any):
180 super().__init__(**data)
181 ObjectRegistry.register_object(self)
182
183 @property
184 def parent(self) -> Optional["ChatDocument"]:

Callers 15

initMethod · 0.90
stepMethod · 0.90
step_asyncMethod · 0.90
resultMethod · 0.90
_agent_response_finalMethod · 0.90
response_templateMethod · 0.90
_user_response_finalMethod · 0.90
responseMethod · 0.90
responseMethod · 0.90
handleMethod · 0.90

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…