conversation
Class info¶
Classes¶
Name | Children | Inherits |
---|---|---|
ChatMessage llmling_agent.messaging.messages Common message format for all UI types. |
||
ChatMessageContainer llmling_agent.messaging.message_container Container for tracking and managing chat messages. |
||
ConversationManager llmling_agent.agent.conversation Manages conversation state and system prompts. |
||
MemoryConfig llmling_agent.models.session Configuration for agent memory and history handling. |
||
SessionQuery llmling_agent.models.session Query configuration for session recovery. |
🛈 DocStrings¶
Conversation management for LLMling agent.
ConversationManager
¶
Manages conversation state and system prompts.
Source code in src/llmling_agent/agent/conversation.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
|
last_run_messages
property
¶
last_run_messages: list[ChatMessage]
Get messages from the last run converted to our format.
HistoryCleared
dataclass
¶
Emitted when chat history is cleared.
Source code in src/llmling_agent/agent/conversation.py
54 55 56 57 58 59 |
|
__aenter__
async
¶
__aenter__() -> Self
Initialize when used standalone.
Source code in src/llmling_agent/agent/conversation.py
100 101 102 103 104 |
|
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
)
Clean up any pending messages.
Source code in src/llmling_agent/agent/conversation.py
106 107 108 109 110 111 112 113 |
|
__contains__
¶
Check if item is in history.
Source code in src/llmling_agent/agent/conversation.py
156 157 158 |
|
__getitem__
¶
__getitem__(key: int) -> ChatMessage[Any]
__getitem__(key: slice | str) -> list[ChatMessage[Any]]
__getitem__(key: int | slice | str) -> ChatMessage[Any] | list[ChatMessage[Any]]
Access conversation history.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
int | slice | str
|
Either: - Integer index for single message - Slice for message range - Agent name for conversation history with that agent |
required |
Source code in src/llmling_agent/agent/conversation.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
__init__
¶
__init__(
agent: Agent[Any],
session_config: MemoryConfig | None = None,
*,
resources: Sequence[Resource | PromptType | str] = (),
)
Initialize conversation manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agent
|
Agent[Any]
|
instance to manage |
required |
session_config
|
MemoryConfig | None
|
Optional MemoryConfig |
None
|
resources
|
Sequence[Resource | PromptType | str]
|
Optional paths to load as context |
()
|
Source code in src/llmling_agent/agent/conversation.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
__len__
¶
__len__() -> int
Get length of history.
Source code in src/llmling_agent/agent/conversation.py
160 161 162 |
|
add_chat_messages
¶
add_chat_messages(messages: Sequence[ChatMessage])
Add new messages to history and update last_messages.
Source code in src/llmling_agent/agent/conversation.py
394 395 396 397 |
|
add_context_from_path
async
¶
Add file or URL content as context message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
StrPath
|
Any UPath-supported path |
required |
convert_to_md
|
bool
|
Whether to convert content to markdown |
False
|
**metadata
|
Any
|
Additional metadata to include with the message |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If content cannot be loaded or converted |
Source code in src/llmling_agent/agent/conversation.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
|
add_context_from_prompt
async
¶
add_context_from_prompt(
prompt: PromptType, metadata: dict[str, Any] | None = None, **kwargs: Any
)
Add rendered prompt content as context message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
PromptType
|
LLMling prompt (static, dynamic, or file-based) |
required |
metadata
|
dict[str, Any] | None
|
Additional metadata to include with the message |
None
|
kwargs
|
Any
|
Optional kwargs for prompt formatting |
{}
|
Source code in src/llmling_agent/agent/conversation.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
add_context_from_resource
async
¶
add_context_from_resource(resource: Resource | str)
Add content from a LLMling resource.
Source code in src/llmling_agent/agent/conversation.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
|
add_context_message
¶
Add a context message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content
|
str
|
Text content to add |
required |
source
|
str | None
|
Description of content source |
None
|
**metadata
|
Any
|
Additional metadata to include with the message |
{}
|
Source code in src/llmling_agent/agent/conversation.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
|
clear
¶
clear()
Clear conversation history and prompts.
Source code in src/llmling_agent/agent/conversation.py
347 348 349 350 351 352 |
|
clear_pending
¶
clear_pending()
Clear pending messages without adding them to history.
Source code in src/llmling_agent/agent/conversation.py
338 339 340 |
|
format_history
async
¶
format_history(
*,
max_tokens: int | None = None,
include_system: bool = False,
format_template: str | None = None,
num_messages: int | None = None,
) -> str
Format conversation history as a single context message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_tokens
|
int | None
|
Optional limit to include only last N tokens |
None
|
include_system
|
bool
|
Whether to include system messages |
False
|
format_template
|
str | None
|
Optional custom format (defaults to agent/message pairs) |
None
|
num_messages
|
int | None
|
Optional limit to include only last N messages |
None
|
Source code in src/llmling_agent/agent/conversation.py
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 |
|
get_history
¶
get_history(include_pending: bool = True, do_filter: bool = True) -> list[ChatMessage]
Get conversation history.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_pending
|
bool
|
Whether to include pending messages |
True
|
do_filter
|
bool
|
Whether to apply memory config limits (max_tokens, max_messages) |
True
|
Returns:
Type | Description |
---|---|
list[ChatMessage]
|
Filtered list of messages in chronological order |
Source code in src/llmling_agent/agent/conversation.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
get_history_tokens
¶
get_history_tokens() -> int
Get token count for current history.
Source code in src/llmling_agent/agent/conversation.py
517 518 519 520 |
|
get_initialization_tasks
¶
Get all initialization coroutines.
Source code in src/llmling_agent/agent/conversation.py
95 96 97 98 |
|
get_message_tokens
¶
get_message_tokens(message: ChatMessage) -> int
Get token count for a single message.
Source code in src/llmling_agent/agent/conversation.py
164 165 166 167 |
|
get_pending_messages
¶
get_pending_messages() -> list[ChatMessage]
Get messages that will be included in next interaction.
Source code in src/llmling_agent/agent/conversation.py
334 335 336 |
|
get_pending_tokens
¶
get_pending_tokens() -> int
Get token count for pending messages.
Source code in src/llmling_agent/agent/conversation.py
522 523 524 525 |
|
load_context_source
async
¶
load_context_source(source: Resource | PromptType | str)
Load context from a single source.
Source code in src/llmling_agent/agent/conversation.py
222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
load_history_from_database
¶
load_history_from_database(
session: SessionIdType | SessionQuery = None,
*,
since: datetime | None = None,
until: datetime | None = None,
roles: set[MessageRole] | None = None,
limit: int | None = None,
)
Load conversation history from database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
SessionIdType | SessionQuery
|
Session ID or query config |
None
|
since
|
datetime | None
|
Only include messages after this time (override) |
None
|
until
|
datetime | None
|
Only include messages before this time (override) |
None
|
roles
|
set[MessageRole] | None
|
Only include messages with these roles (override) |
None
|
limit
|
int | None
|
Maximum number of messages to return (override) |
None
|
Source code in src/llmling_agent/agent/conversation.py
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 280 281 282 283 284 285 286 287 288 289 290 |
|
set_history
¶
set_history(history: list[ChatMessage])
Update conversation history after run.
Source code in src/llmling_agent/agent/conversation.py
342 343 344 345 |
|
temporary_state
async
¶
temporary_state(
history: list[AnyPromptType] | SessionQuery | None = None,
*,
replace_history: bool = False,
) -> AsyncIterator[Self]
Temporarily set conversation history.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
history
|
list[AnyPromptType] | SessionQuery | None
|
Optional list of prompts to use as temporary history. Can be strings, BasePrompts, or other prompt types. |
None
|
replace_history
|
bool
|
If True, only use provided history. If False, append to existing history. |
False
|
Source code in src/llmling_agent/agent/conversation.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
|
_to_base_prompt
¶
_to_base_prompt(prompt: PromptInput) -> BasePrompt
Convert input to BasePrompt instance.
Source code in src/llmling_agent/agent/conversation.py
41 42 43 44 45 46 47 48 |
|