ChatMessage
Base classes¶
Name | Children | Inherits |
---|---|---|
Generic typing Abstract base class for generic types. |
⋔ Inheritance diagram¶
graph TD
94004557226496["messages.ChatMessage"]
94004505984624["typing.Generic"]
140104485245120["builtins.object"]
94004505984624 --> 94004557226496
140104485245120 --> 94004505984624
🛈 DocStrings¶
Common message format for all UI types.
Generically typed with: ChatMessage[Type of Content] The type can either be str or a BaseModel subclass.
Source code in src/llmling_agent/messaging/messages.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
associated_messages
class-attribute
instance-attribute
¶
associated_messages: list[ChatMessage[Any]] = field(default_factory=list)
List of messages which were generated during the the creation of this messsage.
content
instance-attribute
¶
content: TContent
Message content, typed as TContent (either str or BaseModel).
conversation_id
class-attribute
instance-attribute
¶
conversation_id: str | None = None
ID of the conversation this message belongs to.
cost_info
class-attribute
instance-attribute
¶
cost_info: TokenCost | None = None
Token usage and costs for this specific message if available.
forwarded_from
class-attribute
instance-attribute
¶
List of agent names (the chain) that forwarded this message to the sender.
message_id
class-attribute
instance-attribute
¶
Unique identifier for this message.
metadata
class-attribute
instance-attribute
¶
Additional metadata about the message.
model
class-attribute
instance-attribute
¶
model: str | None = None
Name of the model that generated this message.
name
class-attribute
instance-attribute
¶
name: str | None = None
Display name for the message sender in UI.
provider_extra
class-attribute
instance-attribute
¶
Provider specific metadata / extra information.
response_time
class-attribute
instance-attribute
¶
response_time: float | None = None
Time it took the LLM to respond.
timestamp
class-attribute
instance-attribute
¶
When this message was created.
tool_calls
class-attribute
instance-attribute
¶
tool_calls: list[ToolCallInfo] = field(default_factory=list)
List of tool calls made during message generation.
_get_content_str
¶
_get_content_str() -> str
Get string representation of content.
Source code in src/llmling_agent/messaging/messages.py
218 219 220 221 222 223 224 225 226 227 |
|
format
¶
format(
style: FormatStyle = "simple",
*,
template: str | None = None,
variables: dict[str, Any] | None = None,
show_metadata: bool = False,
show_costs: bool = False,
) -> str
Format message with configurable style.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
style
|
FormatStyle
|
Predefined style or "custom" for custom template |
'simple'
|
template
|
str | None
|
Custom Jinja template (required if style="custom") |
None
|
variables
|
dict[str, Any] | None
|
Additional variables for template rendering |
None
|
show_metadata
|
bool
|
Whether to include metadata |
False
|
show_costs
|
bool
|
Whether to include cost information |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
If style is "custom" but no template provided or if style is invalid |
Source code in src/llmling_agent/messaging/messages.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
forwarded
¶
forwarded(previous_message: ChatMessage[Any]) -> Self
Create new message showing it was forwarded from another message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
previous_message
|
ChatMessage[Any]
|
The message that led to this one's creation |
required |
Returns:
Type | Description |
---|---|
Self
|
New message with updated chain showing the path through previous message |
Source code in src/llmling_agent/messaging/messages.py
202 203 204 205 206 207 208 209 210 211 212 |
|
to_text_message
¶
to_text_message() -> ChatMessage[str]
Convert this message to a text-only version.
Source code in src/llmling_agent/messaging/messages.py
214 215 216 |
|