API Reference
Agent
Source code in agency_swarm/agents/agent.py
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 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 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 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 |
|
__init__(id=None, name=None, description=None, instructions='', tools=None, tool_resources=None, temperature=None, top_p=None, response_format='auto', tools_folder=None, files_folder=None, schemas_folder=None, api_headers=None, api_params=None, file_ids=None, metadata=None, model='gpt-4o-2024-08-06', validation_attempts=1, max_prompt_tokens=None, max_completion_tokens=None, truncation_strategy=None, examples=None, file_search=None, parallel_tool_calls=True, refresh_from_id=True)
Initializes an Agent with specified attributes, tools, and OpenAI client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
Loads the assistant from OpenAI assistant ID. Assistant will be created or loaded from settings if ID is not provided. Defaults to None. |
None
|
name
|
str
|
Name of the agent. Defaults to the class name if not provided. |
None
|
description
|
str
|
A brief description of the agent's purpose. Defaults to None. |
None
|
instructions
|
str
|
Path to a file containing specific instructions for the agent. Defaults to an empty string. |
''
|
tools
|
List[Union[Type[BaseTool], Type[Retrieval], Type[CodeInterpreter]]]
|
A list of tools (as classes) that the agent can use. Defaults to an empty list. |
None
|
tool_resources
|
ToolResources
|
A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs. Defaults to None. |
None
|
temperature
|
float
|
The temperature parameter for the OpenAI API. Defaults to None. |
None
|
top_p
|
float
|
The top_p parameter for the OpenAI API. Defaults to None. |
None
|
response_format
|
Union[str, Dict, type]
|
The response format for the OpenAI API. If BaseModel is provided, it will be converted to a response format. Defaults to None. |
'auto'
|
tools_folder
|
str
|
Path to a directory containing tools associated with the agent. Each tool must be defined in a separate file. File must be named as the class name of the tool. Defaults to None. |
None
|
files_folder
|
Union[List[str], str]
|
Path or list of paths to directories containing files associated with the agent. Defaults to None. |
None
|
schemas_folder
|
Union[List[str], str]
|
Path or list of paths to directories containing OpenAPI schemas associated with the agent. Defaults to None. |
None
|
api_headers
|
Dict[str, Dict[str, str]]
|
Headers to be used for the openapi requests. Each key must be a full filename from schemas_folder. Defaults to an empty dictionary. |
None
|
api_params
|
Dict[str, Dict[str, str]]
|
Extra params to be used for the openapi requests. Each key must be a full filename from schemas_folder. Defaults to an empty dictionary. |
None
|
metadata
|
Dict[str, str]
|
Metadata associated with the agent. Defaults to an empty dictionary. |
None
|
model
|
str
|
The model identifier for the OpenAI API. Defaults to "gpt-4o". |
'gpt-4o-2024-08-06'
|
validation_attempts
|
int
|
Number of attempts to validate the response with response_validator function. Defaults to 1. |
1
|
max_prompt_tokens
|
int
|
Maximum number of tokens allowed in the prompt. Defaults to None. |
None
|
max_completion_tokens
|
int
|
Maximum number of tokens allowed in the completion. Defaults to None. |
None
|
truncation_strategy
|
TruncationStrategy
|
Truncation strategy for the OpenAI API. Defaults to None. |
None
|
examples
|
List[Dict]
|
A list of example messages for the agent. Defaults to None. |
None
|
file_search
|
FileSearchConfig
|
A dictionary containing the file search tool configuration. Defaults to None. |
None
|
parallel_tool_calls
|
bool
|
Whether to enable parallel function calling during tool use. Defaults to True. |
True
|
refresh_from_id
|
bool
|
Whether to load and update the agent from the OpenAI assistant ID when provided. Defaults to True. |
True
|
This constructor sets up the agent with its unique properties, initializes the OpenAI client, reads instructions if provided, and uploads any associated files.
Source code in agency_swarm/agents/agent.py
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 |
|
delete()
Deletes assistant, all vector stores, and all files associated with the agent.
get_openapi_schema(url)
Get openapi schema that contains all tools from the agent as different api paths. Make sure to call this after agency has been initialized.
Source code in agency_swarm/agents/agent.py
init_oai()
Initializes the OpenAI assistant for the agent.
This method handles the initialization and potential updates of the agent's OpenAI assistant. It loads the assistant based on a saved ID, updates the assistant if necessary, or creates a new assistant if it doesn't exist. After initialization or update, it saves the assistant's settings.
Output
self: Returns the agent instance for chaining methods or further processing.
Source code in agency_swarm/agents/agent.py
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 |
|
response_validator(message)
Validates the response from the agent. If the response is invalid, it must raise an exception with instructions for the caller agent on how to proceed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The response from the agent. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The validated response. |
Source code in agency_swarm/agents/agent.py
Agency
Source code in agency_swarm/agency/agency.py
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 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 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 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 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 |
|
__init__(agency_chart, shared_instructions='', shared_files=None, async_mode=None, send_message_tool_class=SendMessage, settings_path='./settings.json', settings_callbacks=None, threads_callbacks=None, temperature=0.3, top_p=1.0, max_prompt_tokens=None, max_completion_tokens=None, truncation_strategy=None)
Initializes the Agency object, setting up agents, threads, and core functionalities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
agency_chart
|
List
|
The structure defining the hierarchy and interaction of agents within the agency. |
required |
shared_instructions
|
str
|
A path to a file containing shared instructions for all agents. Defaults to an empty string. |
''
|
shared_files
|
Union[str, List[str]]
|
A path to a folder or a list of folders containing shared files for all agents. Defaults to None. |
None
|
async_mode
|
str
|
Specifies the mode for asynchronous processing. In "threading" mode, all sub-agents run in separate threads. In "tools_threading" mode, all tools run in separate threads, but agents do not. Defaults to None. |
None
|
send_message_tool_class
|
Type[SendMessageBase]
|
The class to use for the send_message tool. For async communication, use |
SendMessage
|
settings_path
|
str
|
The path to the settings file for the agency. Must be json. If file does not exist, it will be created. Defaults to None. |
'./settings.json'
|
settings_callbacks
|
SettingsCallbacks
|
A dictionary containing functions to load and save settings for the agency. The keys must be "load" and "save". Both values must be defined. Defaults to None. |
None
|
threads_callbacks
|
ThreadsCallbacks
|
A dictionary containing functions to load and save threads for the agency. The keys must be "load" and "save". Both values must be defined. Defaults to None. |
None
|
temperature
|
float
|
The temperature value to use for the agents. Agent-specific values will override this. Defaults to 0.3. |
0.3
|
top_p
|
float
|
The top_p value to use for the agents. Agent-specific values will override this. Defaults to None. |
1.0
|
max_prompt_tokens
|
int
|
The maximum number of tokens allowed in the prompt for each agent. Agent-specific values will override this. Defaults to None. |
None
|
max_completion_tokens
|
int
|
The maximum number of tokens allowed in the completion for each agent. Agent-specific values will override this. Defaults to None. |
None
|
truncation_strategy
|
dict
|
The truncation strategy to use for the completion for each agent. Agent-specific values will override this. Defaults to None. |
None
|
This constructor initializes various components of the Agency, including CEO, agents, threads, and user interactions. It parses the agency chart to set up the organizational structure and initializes the messaging tools, agents, and threads necessary for the operation of the agency. Additionally, it prepares a main thread for user interactions.
Source code in agency_swarm/agency/agency.py
delete()
This method deletes the agency and all its agents, cleaning up any files and vector stores associated with each agent.
demo_gradio(height=450, dark_mode=True, **kwargs)
Launches a Gradio-based demo interface for the agency chatbot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
height
|
int
|
The height of the chatbot widget in the Gradio interface. Default is 600. |
450
|
dark_mode
|
bool
|
Flag to determine if the interface should be displayed in dark mode. Default is True. |
True
|
**kwargs
|
Additional keyword arguments to be passed to the Gradio interface. |
{}
|
This method sets up and runs a Gradio interface, allowing users to interact with the agency's chatbot. It includes a text input for the user's messages and a chatbot interface for displaying the conversation. The method handles user input and chatbot responses, updating the interface dynamically.
Source code in agency_swarm/agency/agency.py
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 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 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 |
|
get_completion(message, message_files=None, yield_messages=False, recipient_agent=None, additional_instructions=None, attachments=None, tool_choice=None, verbose=False, response_format=None)
Retrieves the completion for a given message from the main thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The message for which completion is to be retrieved. |
required |
message_files
|
list
|
A list of file ids to be sent as attachments with the message. When using this parameter, files will be assigned both to file_search and code_interpreter tools if available. It is recommended to assign files to the most sutiable tool manually, using the attachments parameter. Defaults to None. |
None
|
yield_messages
|
bool
|
Flag to determine if intermediate messages should be yielded. Defaults to True. |
False
|
recipient_agent
|
Agent
|
The agent to which the message should be sent. Defaults to the first agent in the agency chart. |
None
|
additional_instructions
|
str
|
Additional instructions to be sent with the message. Defaults to None. |
None
|
attachments
|
List[dict]
|
A list of attachments to be sent with the message, following openai format. Defaults to None. |
None
|
tool_choice
|
dict
|
The tool choice for the recipient agent to use. Defaults to None. |
None
|
parallel_tool_calls
|
bool
|
Whether to enable parallel function calling during tool use. Defaults to True. |
required |
verbose
|
bool
|
Whether to print the intermediary messages in console. Defaults to False. |
False
|
response_format
|
dict
|
The response format to use for the completion. |
None
|
Returns:
Type | Description |
---|---|
Generator or final response: Depending on the 'yield_messages' flag, this method returns either a generator yielding intermediate messages or the final response from the main thread. |
Source code in agency_swarm/agency/agency.py
get_completion_parse(message, response_format, message_files=None, recipient_agent=None, additional_instructions=None, attachments=None, tool_choice=None, verbose=False)
Retrieves the completion for a given message from the main thread and parses the response using the provided pydantic model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The message for which completion is to be retrieved. |
required |
response_format
|
type(BaseModel
|
The response format to use for the completion. |
required |
message_files
|
list
|
A list of file ids to be sent as attachments with the message. When using this parameter, files will be assigned both to file_search and code_interpreter tools if available. It is recommended to assign files to the most sutiable tool manually, using the attachments parameter. Defaults to None. |
None
|
recipient_agent
|
Agent
|
The agent to which the message should be sent. Defaults to the first agent in the agency chart. |
None
|
additional_instructions
|
str
|
Additional instructions to be sent with the message. Defaults to None. |
None
|
attachments
|
List[dict]
|
A list of attachments to be sent with the message, following openai format. Defaults to None. |
None
|
tool_choice
|
dict
|
The tool choice for the recipient agent to use. Defaults to None. |
None
|
verbose
|
bool
|
Whether to print the intermediary messages in console. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
T
|
Final response: The final response from the main thread, parsed using the provided pydantic model. |
Source code in agency_swarm/agency/agency.py
get_completion_stream(message, event_handler, message_files=None, recipient_agent=None, additional_instructions=None, attachments=None, tool_choice=None, response_format=None)
Generates a stream of completions for a given message from the main thread.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The message for which completion is to be retrieved. |
required |
event_handler
|
type(AgencyEventHandler
|
The event handler class to handle the completion stream. https://github.com/openai/openai-python/blob/main/helpers.md |
required |
message_files
|
list
|
A list of file ids to be sent as attachments with the message. When using this parameter, files will be assigned both to file_search and code_interpreter tools if available. It is recommended to assign files to the most sutiable tool manually, using the attachments parameter. Defaults to None. |
None
|
recipient_agent
|
Agent
|
The agent to which the message should be sent. Defaults to the first agent in the agency chart. |
None
|
additional_instructions
|
str
|
Additional instructions to be sent with the message. Defaults to None. |
None
|
attachments
|
List[dict]
|
A list of attachments to be sent with the message, following openai format. Defaults to None. |
None
|
tool_choice
|
dict
|
The tool choice for the recipient agent to use. Defaults to None. |
None
|
parallel_tool_calls
|
bool
|
Whether to enable parallel function calling during tool use. Defaults to True. |
required |
Returns:
Type | Description |
---|---|
Final response: Final response from the main thread. |
Source code in agency_swarm/agency/agency.py
get_customgpt_schema(url)
Returns the OpenAPI schema for the agency from the CEO agent, that you can use to integrate with custom gpts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
Your server url where the api will be hosted. |
required |
Source code in agency_swarm/agency/agency.py
run_demo()
Executes agency in the terminal with autocomplete for recipient agent names.
Source code in agency_swarm/agency/agency.py
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 |
|
ToolFactory
Source code in agency_swarm/tools/ToolFactory.py
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 343 344 345 |
|
from_file(file_path)
staticmethod
Dynamically imports a BaseTool class from a Python file within a package structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The file path to the Python file containing the BaseTool class. |
required |
Returns:
Type | Description |
---|---|
Type[BaseTool]
|
The imported BaseTool class. |
Source code in agency_swarm/tools/ToolFactory.py
from_langchain_tool(tool)
staticmethod
Converts a langchain tool into a BaseTool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool
|
The langchain tool to convert. |
required |
Returns:
Type | Description |
---|---|
Type[BaseTool]
|
A BaseTool. |
Source code in agency_swarm/tools/ToolFactory.py
from_langchain_tools(tools)
staticmethod
Converts a list of langchain tools into a list of BaseTools.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tools
|
List
|
The langchain tools to convert. |
required |
Returns:
Type | Description |
---|---|
List[Type[BaseTool]]
|
A list of BaseTools. |
Source code in agency_swarm/tools/ToolFactory.py
from_openai_schema(schema, callback)
staticmethod
Converts an OpenAI schema into a BaseTool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
Dict[str, Any]
|
The OpenAI schema to convert. |
required |
callback
|
Any
|
The function to run when the tool is called. |
required |
Returns:
Type | Description |
---|---|
Type[BaseTool]
|
A BaseTool. |
Source code in agency_swarm/tools/ToolFactory.py
from_openapi_schema(schema, headers=None, params=None, strict=False)
staticmethod
Converts an OpenAPI schema into a list of BaseTools.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
Union[str, dict]
|
The OpenAPI schema to convert. |
required |
headers
|
Dict[str, str]
|
The headers to use for requests. |
None
|
params
|
Dict[str, Any]
|
The parameters to use for requests. |
None
|
strict
|
bool
|
Whether to use strict OpenAI mode. |
False
|
Returns: A list of BaseTools.
Source code in agency_swarm/tools/ToolFactory.py
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 |
|
get_openapi_schema(tools, url, title='Agent Tools', description='A collection of tools.')
staticmethod
Generates an OpenAPI schema from a list of BaseTools.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tools
|
List[Type[BaseTool]]
|
BaseTools to generate the schema from. |
required |
url
|
str
|
The base URL for the schema. |
required |
title
|
The title of the schema. |
'Agent Tools'
|
|
description
|
The description of the schema. |
'A collection of tools.'
|
Returns:
Type | Description |
---|---|
str
|
A JSON string representing the OpenAPI schema with all the tools combined as separate endpoints. |