chat_document
langroid/agent/chat_document.py
StatusCode
¶
Bases: str
, Enum
Codes meant to be returned by task.run(). Some are not used yet.
ChatDocument(**data)
¶
Bases: Document
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:
Name | Type | Description |
---|---|---|
oai_tool_calls |
Optional[List[OpenAIToolCall]]
|
Tool-calls from an OpenAI-compatible API |
oai_tool_id2results |
Optional[OrderedDict[str, str]]
|
Results of tool-calls from OpenAI (dict is a map of tool_id -> result) |
oai_tool_choice |
ToolChoiceTypes | Dict[str, Dict[str, str] | str]
|
ToolChoiceTypes | Dict[str, str]: Param controlling how the LLM should choose tool-use in its response (auto, none, required, or a specific tool) |
function_call |
Optional[LLMFunctionCall]
|
Function-call from an OpenAI-compatible API (deprecated by OpenAI, in favor of tool-calls) |
tool_messages |
List[ToolMessage]
|
Langroid ToolMessages extracted from
- |
metadata |
ChatDocMetaData
|
Metadata for the message, e.g. sender, recipient. |
attachment |
None | ChatDocAttachment
|
Any additional data attached. |
Source code in langroid/agent/chat_document.py
delete_id(id)
staticmethod
¶
Remove ChatDocument with given id from ObjectRegistry, and all its descendants.
Source code in langroid/agent/chat_document.py
get_tool_names()
¶
Get names of attempted tool usages (JSON or non-JSON) in the content
of the message.
Returns:
List[str]: list of attempted tool names
(We say "attempted" since we ONLY look at the request
component of the
tool-call representation, and we're not fully parsing it into the
corresponding tool message class)
Source code in langroid/agent/chat_document.py
log_fields()
¶
Fields for logging in csv/tsv logger Returns: List[str]: list of fields
Source code in langroid/agent/chat_document.py
pop_tool_ids()
¶
from_LLMResponse(response, displayed=False)
staticmethod
¶
Convert LLMResponse to ChatDocument. Args: response (LLMResponse): LLMResponse to convert. displayed (bool): Whether this response was displayed to the user. Returns: ChatDocument: ChatDocument representation of this LLMResponse.
Source code in langroid/agent/chat_document.py
to_LLMMessage(message, oai_tools=None)
staticmethod
¶
Convert to list of LLMMessage, to incorporate into msg-history sent to LLM API. Usually there will be just a single LLMMessage, but when the ChatDocument contains results from multiple OpenAI tool-calls, we would have a sequence LLMMessages, one per tool-call result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str | ChatDocument
|
Message to convert. |
required |
oai_tools |
Optional[List[OpenAIToolCall]]
|
Tool-calls currently awaiting response, from the ChatAgent's latest message. |
None
|
Returns: List[LLMMessage]: list of LLMMessages corresponding to this ChatDocument.
Source code in langroid/agent/chat_document.py
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 |
|