Objects
Completed
Bases: Update
Completed message to be sent to the frontend (tree is complete all recursions).
Source code in elysia/objects.py
Error
Bases: Update
Error objects are used to communicate errors to the decision agent/tool calls. When yielded, Error objects are automatically saved inside the TreeData object. When calling the same tool again, the saved Error object is automatically loaded into any tool calls made with the same tool name. All errors are shown to the decision agent to help decide whether the tool should be called again (retried), or a different tool should be called.
Source code in elysia/objects.py
__init__(feedback='', error_message='')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feedback
|
str
|
The feedback to display to the decision agent. Usually this will be the error message, but it could be formatted more specifically. |
''
|
Source code in elysia/objects.py
Result
Bases: Return
Result objects are returned to the frontend. These are displayed on the frontend. E.g. a table, a chart, a text response, etc.
You can yield a Result
directly, and specify the type
and name
of the result.
Source code in elysia/objects.py
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
|
__init__(objects, metadata={}, payload_type='default', name='default', mapping=None, llm_message=None, unmapped_keys=['_REF_ID'], display=True)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objects
|
list[dict]
|
The objects attached to this result. |
required |
payload_type
|
str
|
(str): Identifier for the type of result. |
'default'
|
metadata
|
dict
|
The metadata attached to this result, for example, query used, time taken, any other information not directly within the objects |
{}
|
name
|
str
|
The name of the result, e.g. this could be the name of the collection queried. Used to index the result in the environment. |
'default'
|
mapping
|
dict | None
|
A mapping of the objects to the frontend. Essentially, if the objects are going to be displayed on the frontend, the frontend has specific keys that it wants the objects to have. This is a dictionary that maps from frontend keys to the object keys. |
None
|
llm_message
|
str | None
|
A message to be displayed to the LLM to help it parse the result. You can use the following placeholders that will automatically be replaced with the correct values:
|
None
|
unmapped_keys
|
list[str]
|
A list of keys that are not mapped to the frontend. |
['_REF_ID']
|
display
|
bool
|
Whether to display the result on the frontend when yielding this object.
Defaults to |
True
|
Source code in elysia/objects.py
format_llm_message()
llm_message is a string that is used to help the LLM parse the output of the tool. It is a placeholder for the actual message that will be displayed to the user.
You can use the following placeholders:
- {payload_type}: The type of the object
- {name}: The name of the object
- {num_objects}: The number of objects in the object
- {metadata_key}: Any key in the metadata dictionary
Source code in elysia/objects.py
llm_parse()
This method is called when the result is displayed to the LLM.
It is used to display custom information to the LLM about the result.
If llm_message
was defined, then the llm message is formatted using the placeholders.
Otherwise a default message is used.
Returns:
Type | Description |
---|---|
str
|
The formatted llm message. |
Source code in elysia/objects.py
to_frontend(user_id, conversation_id, query_id)
async
Convert the result to a frontend payload.
This is a wrapper around the to_json
method.
But the objects and metadata are inside a payload
key, which also includes a type
key,
being the frontend identifier for the type of payload being sent.
(e.g. ticket
, product
, message
, etc.)
The outside of the payload also contains the user_id, conversation_id, and query_id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_id
|
str
|
The user ID. |
required |
conversation_id
|
str
|
The conversation ID. |
required |
query_id
|
str
|
The query ID. |
required |
Returns:
Type | Description |
---|---|
dict
|
Source code in elysia/objects.py
to_json(mapping=False)
Convert the result to a list of dictionaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mapping
|
bool
|
Whether to map the objects to the frontend.
This will use the |
False
|
Returns:
Type | Description |
---|---|
list[dict]
|
A list of dictionaries, which can be serialised to JSON. |
Source code in elysia/objects.py
Retrieval
Bases: Result
Store of returned objects from a query/aggregate/any displayed results.
Source code in elysia/objects.py
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 |
|
Return
A Return object is something that is returned to the frontend. This kind of object is frontend-aware.
Source code in elysia/objects.py
Status
Bases: Update
Status message to be sent to the frontend for real-time updates in words.
Source code in elysia/objects.py
Text
Bases: Return
Frontend Return Type 1: Text Objects is usually a one-element list containing a dict with a "text" key only. But is not limited to this.
Source code in elysia/objects.py
Tool
The generic Tool class, which will be a superclass of any tools used by Elysia.
Source code in elysia/objects.py
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 |
|
__call__(tree_data, inputs, base_lm, complex_lm, client_manager, **kwargs)
async
This method is called to run the tool.
This must be an async generator, so objects must be yielded and not returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree_data
|
TreeData
|
The data from the decision tree, includes the environment, user prompt, etc.
See the |
required |
base_lm
|
LM
|
The base language model, a dspy.LM object. |
required |
complex_lm
|
LM
|
The complex language model, a dspy.LM object. |
required |
client_manager
|
ClientManager
|
The client manager, a way of interfacing with a Weaviate client. |
required |
Source code in elysia/objects.py
__init__(name, description, status='', inputs={}, end=False, **kwargs)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the tool. Required. |
required |
description
|
str
|
A detailed description of the tool to give to the LLM. Required. |
required |
status
|
str
|
A status update message to display while the tool is running. Optional, defaults to "Running {name}...". |
''
|
inputs
|
dict
|
{}
|
|
end
|
bool
|
Whether the tool is an end tool. Optional, defaults to False. |
False
|
Source code in elysia/objects.py
get_metadata()
classmethod
Get tool metadata without instantiation.
Source code in elysia/objects.py
is_tool_available(tree_data, base_lm, complex_lm, client_manager)
async
This method is called to check if the tool is available.
If this returns True
, then the tool is available to be used by the LLM.
Otherwise it does not appear in the decision tree.
The difference between this and run_if_true
is that run_if_true
will always run the call method if it returns True
,
even if the LLM does not choose to use the tool.
This must be an async function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree_data
|
TreeData
|
The tree data object. |
required |
base_lm
|
LM
|
The base language model, a dspy.LM object. |
required |
complex_lm
|
LM
|
The complex language model, a dspy.LM object. |
required |
client_manager
|
ClientManager
|
The client manager, a way of interfacing with a Weaviate client. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the tool is available, False otherwise. |
Source code in elysia/objects.py
run_if_true(tree_data, base_lm, complex_lm, client_manager)
async
This method is called to check if the tool should be run automatically.
If this returns True
, then the tool is immediately called at the start of the tree.
Otherwise it does not appear in the decision tree.
You must also return a dictionary of inputs for the tool, which will be used to call the tool if True
is returned.
If the inputs are None or an empty dictionary, then the default inputs will be used.
This must be an async function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tree_data
|
TreeData
|
The tree data object. |
required |
base_lm
|
LM
|
The base language model, a dspy.LM object. |
required |
complex_lm
|
LM
|
The complex language model, a dspy.LM object. |
required |
client_manager
|
ClientManager
|
The client manager, a way of interfacing with a Weaviate client. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the tool should be run automatically, False otherwise. |
dict |
dict
|
Source code in elysia/objects.py
ToolMeta
Bases: type
Metaclass that extracts tool metadata from init method.
Source code in elysia/objects.py
Update
Bases: Return
Frontend Return Type 2: Update An update is something that is not displayed on the frontend, but gives information to the frontend. E.g. a warning, error, status message, etc.
Source code in elysia/objects.py
Warning
tool(function=None, *, status=None, end=False, tree=None, branch_id=None)
Create a tool from a python function. Use this decorator to create a tool from a function. The function must be an async function or async generator function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function
|
Callable
|
The function to create a tool from. |
None
|
status
|
str | None
|
The status message to display while the tool is running. Optional, defaults to None, which will use the default status message "Running {tool_name}...". |
None
|
end
|
bool
|
Whether the tool can be at the end of the decision tree. Set to True when this tool is allowed to end the conversation. Optional, defaults to False. |
False
|
tree
|
Tree | None
|
The tree to add the tool to. Optional, defaults to None, which will not add the tool to the tree. |
None
|
branch_id
|
str | None
|
The branch of the tree to add the tool to. Optional, defaults to None, which will add the tool to the root branch. |
None
|
Returns:
Type | Description |
---|---|
Tool
|
The tool object which can be added to the tree (via |
Source code in elysia/objects.py
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 |
|
CollectionData
Store of data about the Weaviate collections that are used in the tree.
These are the output of the preprocess
function.
You do not normally need to interact with this class directly.
Instead, do so via the TreeData
class, which has corresponding methods to get the data in a variety of formats.
(Such as via the output_full_metadata
method.)
Source code in elysia/tree/objects.py
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 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
Environment
Store of all objects across different types of queries and responses.
The environment is how the tree stores all objects across different types of queries and responses. This includes things like retrieved objects, retrieved metadata, retrieved summaries, etc.
This is persistent across the tree, so that all agents are aware of the same objects.
The environment is formatted and keyed as follows:
Where "tool_name"
is the name of the function that the result belongs to,
e.g. if the result came from a tool called "query"
, then "tool_name"
is "query"
.
"result_name"
is the name of the Result object, which can be customised,
e.g. if the result comes from a specific collection, then "result_name"
is the name of the collection.
"metadata"
is the metadata of the result,
e.g. the time taken to retrieve the result, the query used, etc.
"objects"
is the list of objects retrieved from the result. This is a list of dictionaries, where each dictionary is an object.
It is important that objects
should have be list of dictionaries.
e.g. each object that was returned from a retrieval, where the fields of each dictionary are the fields of the object returned.
Each list under result_name
is a dictionary with both metadata
and objects
keys.
This is if, for example, you retrieve multiple objects from the same collection, each one is stored with different metadata.
Because, for example, the query used to retrieve each object may be different (and stored differently in the metadata).
The environment is initialised with a default "SelfInfo.generic" key, which is a list of one object, containing information about Elysia itself.
You can use various methods to add, remove, replace, and find objects in the environment. See the methods below for more information.
Within the environment, there is a variable called hidden_environment
, which is a dictionary of key-value pairs.
This is used to store information that is not shown to the LLM, but is instead a 'store' of data that can be used across tools.
Source code in elysia/tree/objects.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 |
|
add(tool_name, result, include_duplicates=False)
Adds a result to the environment. Is called automatically by the tree when a result is returned from an agent.
You can also add a result to the environment manually by using this method.
In this case, you must be adding a 'Result' object (which has an implicit 'name' attribute used to key the environment).
If you want to add something manually, you can use the add_objects
method.
Each item is added with a _REF_ID
attribute, which is a unique identifier used to identify the object in the environment.
If duplicate objects are detected, they are added with a duplicate _REF_ID
entry detailing that they are a duplicate,
as well as the _REF_ID
of the original object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_name
|
str
|
The name of the tool called that the result belongs to. |
required |
result
|
Result
|
The result to add to the environment. |
required |
include_duplicates
|
bool
|
Optional. Whether to include duplicate objects in the environment.
Defaults to |
False
|
Source code in elysia/tree/objects.py
add_objects(tool_name, name, objects, metadata={}, include_duplicates=False)
Adds an object to the environment. Is not called automatically by the tree, so you must manually call this method. This is useful if you want to add an object to the environment manually that doesn't come from a Result object.
Each item is added with a _REF_ID
attribute, which is a unique identifier used to identify the object in the environment.
If duplicate objects are detected, they are added with a duplicate _REF_ID
entry detailing that they are a duplicate,
as well as the _REF_ID
of the original object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_name
|
str
|
The name of the tool called that the result belongs to. |
required |
name
|
str
|
The name of the result. |
required |
objects
|
list[dict]
|
The objects to add to the environment. |
required |
metadata
|
dict
|
Optional. The metadata of the objects to add to the environment. Defaults to an empty dictionary. |
{}
|
include_duplicates
|
bool
|
Optional. Whether to include duplicate objects in the environment.
Defaults to |
False
|
Source code in elysia/tree/objects.py
find(tool_name, name, index=None)
Finds a corresponding list of objects in the environment.
Keyed via tool_name
and name
. See the base class description for more information on how the environment is keyed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_name
|
str
|
The name of the tool called that the result belongs to. |
required |
name
|
str
|
The name of the result. |
required |
index
|
int | None
|
The index of the object to find.
If |
None
|
Returns:
Type | Description |
---|---|
list[dict]
|
if |
dict
|
if |
None
|
If the |
Source code in elysia/tree/objects.py
is_empty()
Check if the environment is empty.
The "SelfInfo" key is not counted towards the empty environment.
If the .remove
method has been used, this is accounted for (e.g. empty lists count towards an empty environment).
Source code in elysia/tree/objects.py
remove(tool_name, name, index=None)
Replaces the list of objects for the given tool_name
and name
with an empty list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_name
|
str
|
The name of the tool called that the result belongs to. |
required |
name
|
str
|
The name of the result. |
required |
index
|
int | None
|
The index of the object to remove.
If |
None
|
Source code in elysia/tree/objects.py
replace(tool_name, name, objects, metadata={}, index=None)
Replaces the list of objects for the given tool_name
and name
with the given list of objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool_name
|
str
|
The name of the tool called that the result belongs to. |
required |
name
|
str
|
The name of the result. |
required |
objects
|
list[dict]
|
The objects to replace the existing objects with. |
required |
metadata
|
dict
|
The metadata of the objects to replace the existing objects with. |
{}
|
index
|
int | None
|
The index of the object to replace.
If |
None
|
Source code in elysia/tree/objects.py
to_json(remove_unserialisable=False)
Converts the environment to a JSON serialisable format. Used to access specific objects from the environment.
Source code in elysia/tree/objects.py
TreeData
Store of data across the tree. This includes things like conversation history, actions, decisions, etc. These data are given to ALL agents, so every agent is aware of the stage of the decision processes.
This also contains functions that process the data into an LLM friendly format, such as a string with extra description. E.g. the number of trees completed is converted into a string (i/N) and additional warnings if i is close to N.
The TreeData has the following objects:
- collection_data (CollectionData): The collection metadata/schema, which contains information about the collections used in the tree.
This is the store of data that is saved by the
preprocess
function, and retrieved on initialisation of this object. - atlas (Atlas): The atlas, described in the Atlas class.
- user_prompt (str): The user's prompt.
- conversation_history (list[dict]): The conversation history stored in the current tree, of the form:
- environment (Environment): The environment, described in the Environment class.
- tasks_completed (list[dict]): The tasks completed as a list of dictionaries. This is separate from the environment, as it separates what tasks were completed in each prompt in which order.
- num_trees_completed (int): The current level of the decision tree, how many iterations have been completed so far.
- recursion_limit (int): The maximum number of iterations allowed in the decision tree.
- errors (dict): A dictionary of self-healing errors that have occurred in the tree. Keyed by the function name that caused the error.
In general, you should not initialise this class directly. But you can access the data in this class to access the relevant data from the tree (in e.g. tool construction/usage).
Source code in elysia/tree/objects.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 |
|
output_collection_metadata(collection_names=None, with_mappings=False)
Outputs the full metadata for the given collection names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
with_mappings
|
bool
|
Whether to output the mappings for the collections as well as the other metadata. |
False
|
Returns:
Source code in elysia/tree/objects.py
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 |
|
output_collection_return_types()
Outputs the return types for the collections in the tree data. Essentially, this is a list of the keys that can be used to map the objects to the frontend.
Returns:
Type | Description |
---|---|
dict
|
Source code in elysia/tree/objects.py
tasks_completed_string()
Output a nicely formatted string of the tasks completed so far, designed to be used in the LLM prompt.
This is where the outputs of the llm_message
fields are displayed.
You can use this if you are interfacing with LLMs in tools, to help it understand the context of the tasks completed so far.
Returns:
Type | Description |
---|---|
str
|
A separated and formatted string of the tasks completed so far in an LLM-parseable format. |