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
from_LLMMessage(message, sender_name='', recipient='')
staticmethod
¶
Convert LLMMessage to ChatDocument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
LLMMessage
|
LLMMessage to convert. |
required |
sender_name
|
str
|
Name of the sender. Defaults to "". |
''
|
recipient
|
str
|
Name of the recipient. Defaults to "". |
''
|
Returns:
Name | Type | Description |
---|---|---|
ChatDocument |
'ChatDocument'
|
ChatDocument representation of this LLMMessage. |
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
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 |
|