diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/404.html b/404.html new file mode 100644 index 00000000..4a8fb499 --- /dev/null +++ b/404.html @@ -0,0 +1,644 @@ + + + +
+ + + + + + + + + + + + + + + + + + +An Agency
is a collection of Agents that can communicate with one another.
Here are the primary benefits of using an Agency, instead of an individual agent:
+Scalability: As the complexity of your integration increases, you can keep adding more and more agents.
+Tip
+It is recommended to start from as few agents as possible, fine tune them until they are working as expected, and only then add new agents to the agency. If you add too many agents at first, it will be difficult to debug and understand what is going on.
+Unlike all other frameworks, communication flows in Agency Swarm are not hierarchical or sequential. Instead, they are uniform. You can define them however you want. But keep in mind that they are established from left to right inside the agency_chart
. So, in the example below, the CEO can initiate communication and send tasks to the Developer and the Virtual Assistant, and they can respond in to him in the same thread, but the Developer or the VA cannot initiate a conversation and assign tasks to the CEO. You can add as many levels of communication as you want.
from agency_swarm import Agency
+
+agency = Agency([
+ ceo, dev # CEO and Developer will be the entry point for communication with the user
+ [ceo, dev], # CEO can initiate communication with Developer
+ [ceo, va], # CEO can initiate communication with Virtual Assistant
+ [dev, va] # Developer can initiate communication with Virtual Assistant
+])
+
All agents added inside the top level list of agency_chart
without being part of a second list, can talk to the user.
To stream the conversation between agents, you can use the get_completion_stream
method with your event handler like below. The process is extremely similar to the one in the official documentation.
The only difference is that you must extend the AgencyEventHandler
class, which has 2 additional properties: agent_name
and recipient_agent_name
, to get the names of the agents communicating with each other. (See the on_text_created
below.)
from typing_extensions import override
+from agency_swarm import AgencyEventHandler
+
+class EventHandler(AgencyEventHandler):
+ @override
+ def on_text_created(self, text) -> None:
+ # get the name of the agent that is sending the message
+ print(f"\n{self.recipient_agent_name} @ {self.agent_name} > ", end="", flush=True)
+
+ @override
+ def on_text_delta(self, delta, snapshot):
+ print(delta.value, end="", flush=True)
+
+ def on_tool_call_created(self, tool_call):
+ print(f"\n{self.recipient_agent_name} > {tool_call.type}\n", flush=True)
+
+ def on_tool_call_delta(self, delta, snapshot):
+ if delta.type == 'code_interpreter':
+ if delta.code_interpreter.input:
+ print(delta.code_interpreter.input, end="", flush=True)
+ if delta.code_interpreter.outputs:
+ print(f"\n\noutput >", flush=True)
+ for output in delta.code_interpreter.outputs:
+ if output.type == "logs":
+ print(f"\n{output.logs}", flush=True)
+
+ @classmethod
+ def on_all_streams_end(cls):
+ print("\n\nAll streams have ended.") # Conversation is over and message is returned to the user.
+
+response = agency.get_completion_stream("I want you to build me a website", event_handler=EventHandler)
+
Also, there is an additional class method on_all_streams_end
which is called when all streams have ended. This method is needed because, unlike in the official documentation, your event handler will be called multiple times and probably by even multiple agents.
If you would like to use asynchronous communication between agents, you can specify a async_mode
parameter. This is useful when you want your agents to execute multiple tasks concurrently. Only threading
mode is supported for now.
With this mode, the response from the SendMessage
tool will be returned instantly as a system notification with a status update. The recipient agent will then continue to execute the task in the background. The caller agent can check the status (if task is in progress) or the response (if the task is completed) with the GetResponse
tool.
You can share instructions between all agents in the agency by adding a shared_instructions
parameter to the agency. This is useful for providing additional context about your environment, defining processes, mission, technical details, and more.
You can add shared files for all agents in the agency by specifying a folder path in a shared_files
parameter. This is useful for sharing common resources that all agents need to access.
If you would like to use a different file path for the settings, other than default settings.json
, you can specify a settings_path
parameter. All your agent states will then be saved and loaded from this file. If this file does not exist, it will be created, along with new Assistants on your OpenAI account.
You can also specify parameters like temperature
, top_p
, max_completion_tokens
, max_prompt_tokens
and truncation_strategy
, parameters for the entire agency. These parameters will be used as default values for all agents in the agency, however, you can still override them for individual agents by specifying them in the agent's constructor.
When it comes to running the agency, you have 3 options:
+response = agency.get_completion("I want you to build me a website",
+ additional_instructions="This is an additional instruction for the task.",
+ tool_choice={"type": "function", "function": {"name": "SendMessage"}},
+ attachments=[],
+ )
+print(response)
+
To talk to one of the top level agents when running the agency from your terminal, you can use mentions feature, similar to how you would use it inside ChatGPT. Simply mention the agent name in the message like @Developer I want you to build me a website
. The message will then be sent to the Developer agent, instead of the CEO. You can also use tab to autocomplete the agent name after the @
symbol.
If you would like to delete the agency and all its agents with all associated files and vector stores, you can use the delete
method.
Agents are essentially wrappers for Assistants in OpenAI Assistants API.
+Agent
classThe Agent
class contains a lot of convenience methods to help you manage the state of your assistant, upload files, attach tools, and more.
When it comes to creating your agent, you have 3 options:
+To define your agent in the code, you can simply instantiate the Agent
class and pass the required parameters.
from agency_swarm import Agent
+
+agent = Agent(name="My Agent",
+ description="This is a description of my agent.",
+ instructions="These are the instructions for my agent.",
+ tools=[ToolClass1, ToolClass2],
+ temperature=0.3,
+ max_prompt_tokens=25000
+ )
+
This CLI command simplifies the process of creating a structured environment for each agent.
+agency-swarm create-agent-template --name "AgentName" --description "Agent Description" [--path "/path/to/directory"] [--use_txt]
+
When you run the create-agent-template
command, it creates the following folder structure for your agent:
/your-specified-path/
+│
+├── agency_manifesto.md or .txt # Agency's guiding principles (created if not exists)
+└── AgentName/ # Directory for the specific agent
+ ├── files/ # Directory for files that will be uploaded to openai
+ ├── schemas/ # Directory for OpenAPI schemas to be converted into tools
+ ├── tools/ # Directory for tools to be imported by default.
+ ├── AgentName.py # The main agent class file
+ ├── __init__.py # Initializes the agent folder as a Python package
+ └── instructions.md or .txt # Instruction document for the agent
+
files
: This folder is used to store files that will be uploaded to OpenAI. You can use any of the acceptable file formats. After file is uploaded, an id will be attached to the file name to avoid re-uploading the same file twice.schemas
: This folder is used to store OpenAPI schemas that will be converted into tools automatically. All you have to do is put the schema in this folder, and specify it when initializing your agent.tools
: This folder is used to store tools in the form of Python files. Each file must have the same name as the tool class for it to be imported by default. For example, ExampleTool.py
must contain a class called ExampleTool
.The AgentName.py
file will contain the following code:
from agency_swarm.agents import Agent
+
+class AgentName(Agent):
+ def __init__(self):
+ super().__init__(
+ name="agent_name",
+ description="agent_description",
+ instructions="./instructions.md",
+ files_folder="./files",
+ schemas_folder="./schemas",
+ tools_folder="./tools",
+ temperature=0.3,
+ max_prompt_tokens=25000,
+ examples=[]
+ )
+
+ def response_validator(self, message: str) -> str:
+ """This function is used to validate the response before sending it to the user or another agent."""
+ if "bad word" in message:
+ raise ValueError("Please don't use bad words.")
+
+ return message
+
To initialize the agent, you can simply import the agent and instantiate it:
+ +You can now also provide few-shot examples for each agent. These examples help the agent to understand how to respond. The format for examples follows message object format on OpenAI:
+examples=[
+ {
+ "role": "user",
+ "content": "Hi!",
+ "attachments": [],
+ "metadata": {},
+ },
+ {
+ "role": "assistant",
+ "content": "Hi! I am the CEO. I am here to help you with your tasks. Please tell me what you need help with.",
+ "attachments": [],
+ "metadata": {},
+ }
+]
+
+agent.examples = examples
+
or you can also provide them when initializing the agent in init method:
+ +For the most complex and requested use cases, we will be creating premade agents that you can import and reuse in your own projects. To import an existing agent, you can run the following CLI command:
+ +This will copy all your agent source files locally. You can then import the agent as shown above. To check available agents, simply run this command without any arguments.
+ + + + + + + + + + + + + +Many organizations are concerned about data privacy and sharing their data with OpenAI. However, using Azure ensures that your data is processed in a secure environment, allowing you to utilize the OpenAI API without even sharing data with OpenAI itself.
+Before you begin, ensure that you have the following:
+To use Azure OpenAI, you need to change OpenAI client with AzureOpenAI client. Here is an example of how you can do it in agency swarm:
+from openai import AzureOpenAI
+from agency_swarm import set_openai_client
+
+client = AzureOpenAI(
+ api_key=os.getenv("AZURE_OPENAI_KEY"),
+ api_version="2024-02-15-preview",
+ azure_endpoint=os.getenv("AZURE_ENDPOINT"),
+ timeout=5,
+ max_retries=5,
+)
+
+set_openai_client(client)
+
Then, you also have to replace model
parameter inside each agent with your model deployment name from Azure. Here is an example of how you can do it:
Then, you can run your agency as usual:
+ +Retrieval is not supported yet
+Currently, Azure OpenAI does not support the Retrieval
tool. You can only use CodeInterpreter
or custom tools made with the BaseTool
class.
You can find an example notebook for using Azure OpenAI in the notebooks folder.
+ + + + + + + + + + + + + +All tools in Agency Swarm are created using Instructor.
+The only difference is that you must extend the BaseTool
class and implement the run
method with your logic inside. For many great examples on what you can create, checkout Instructor Cookbook.
This is an example of how to convert an extremely useful tool for RAG applications from instructor. It allows your agents to not only answer questions based on context, but also to provide the exact citations for the answers. This way your users can be sure that the information is always accurate and reliable.
+from agency_swarm.tools import BaseTool, BaseModel
+from pydantic import Field, model_validator, FieldValidationInfo
+from typing import List
+import re
+
+class Fact(BaseModel):
+ fact: str = Field(...)
+ substring_quote: List[str] = Field(...)
+
+ @model_validator(mode="after")
+ def validate_sources(self, info: FieldValidationInfo) -> "Fact":
+ text_chunks = info.context.get("text_chunk", None)
+ spans = list(self.get_spans(text_chunks))
+ self.substring_quote = [text_chunks[span[0] : span[1]] for span in spans]
+ return self
+
+ def get_spans(self, context):
+ for quote in self.substring_quote:
+ yield from self._get_span(quote, context)
+
+ def _get_span(self, quote, context):
+ for match in re.finditer(re.escape(quote), context):
+ yield match.span()
+
+class QuestionAnswer(BaseModel):
+ question: str = Field(...)
+ answer: List[Fact] = Field(...)
+
+ @model_validator(mode="after")
+ def validate_sources(self) -> "QuestionAnswer":
+ self.answer = [fact for fact in self.answer if len(fact.substring_quote) > 0]
+ return self
+
Context Retrieval
+In the original Instructor example, the context is passed into the prompt beforehand, which is typical for standard non-agent LLM applications. However, in the context of Agency Swarm, we must allow the agents to retrieve the context themselves.
+To allow your agents to retrieve the context themselves, we must split QuestionAnswer
into two separate tools: QueryDatabase
and AnswerQuestion
. We must also retrieve context from shared_state
, as the context is not passed into the prompt beforehand, and FieldValidationInfo
is not available in the validate_sources
method.
QueryDatabase
tool will:shared_state
. If it is, raise an error. (This means that the agent retrieved the context twice, without answering the question in between, which is most likely a hallucination.)shared_state
.class QueryDatabase(BaseTool):
+ """Use this tool to query a vector database to retrieve the relevant context for the question."""
+ question: str = Field(..., description="The question to be answered")
+
+ def run(self):
+ # Check if context is already retrieved
+ if self.shared_state.get("context", None) is not None:
+ raise ValueError("Context already retrieved. Please proceed with the AnswerQuestion tool.")
+
+ # Your code to retrieve the context here
+ context = "This is a test context"
+
+ # Then, save the context to the shared state
+ self.shared_state.set("context", context)
+
+ return f"Context retrieved: {context}.\n\n Please proceed with the AnswerQuestion tool."
+
Shared State
+shared_state
is a state that is shared between all tools, across all agents. It allows you to control the execution flow, share data, and provide instructions to the agents based on certain conditions or actions performed by other agents.
AnswerQuestion
tool will:shared_state
to answer the question with a list of facts.shared_state
after the question is answered. (This is done, so the next question can be answered with a fresh context.)class AnswerQuestion(BaseTool):
+ answer: str = Field(..., description="The answer to the question, based on context.")
+ sources: List[Fact] = Field(..., description="The sources of the answer")
+
+ def run(self):
+ # Remove the context after question is answered
+ self.shared_state.set("context", None)
+
+ # additional logic here as needed, for example save the answer to a database
+
+ return "Success. The question has been answered." # or return the answer, if needed
+
+ @model_validator(mode="after")
+ def validate_sources(self) -> "QuestionAnswer":
+ # In "Agency Swarm", context is directly extracted from `shared_state`
+ context = self.shared_state.get("context", None) # Highlighting the change
+ if context is None:
+ # Additional check to ensure context is retrieved before proceeding
+ raise ValueError("Please retrieve the context with the QueryDatabase tool first.")
+ self.answer = [fact for fact in self.answer if len(fact.substring_quote) > 0]
+ return self
+
Fact
toolThe Fact
tool will stay primarily the same. The only difference is that we must extract the context from the shared_state
inside the validate_sources
method. The run
method is not needed, as this tool only validates the input from the model.
class Fact(BaseTool):
+ fact: str = Field(...)
+ substring_quote: List[str] = Field(...)
+
+ def run(self):
+ pass
+
+ @model_validator(mode="after")
+ def validate_sources(self) -> "Fact":
+ context = self.shared_state.get("context", None)
+ text_chunks = context.get("text_chunk", None)
+ spans = list(self.get_spans(text_chunks))
+ self.substring_quote = [text_chunks[span[0] : span[1]] for span in spans]
+ return self
+
+ # Methods `get_spans` and `_get_span` remain unchanged
+
To implement tools with Instructor in Agency Swarm, generally, you must:
+BaseTool
class.run
method with your execution logic inside.Tool factory is a class that allows you to create tools from different sources. You can create tools from Langchain, OpenAPI schemas. However, it is preferable to implement tools from scratch using Instructor, as it gives you a lot more control.
+Not recommended
+This method is not recommended, as it does not provide the same level of type checking, error correction and tool descriptions as Instructor. However, it is still possible to use this method if you prefer.
+ + +# using local file
+with open("schemas/your_schema.json") as f:
+ tools = ToolFactory.from_openapi_schema(
+ f.read(),
+ )
+
+# using requests
+tools = ToolFactory.from_openapi_schema(
+ requests.get("https://api.example.com/openapi.json").json(),
+)
+
Use enumerators or Literal types instead of strings to allow your agents to perform only certain actions or commands, instead of executing any arbitrary code. This makes your whole system a lot more reliable.
+ +Provide additional instructions to the agents in the run
method of the tool as function outputs. This allows you to control the execution flow, based on certain conditions.
class QueryDatabase(BaseTool):
+ question: str = Field(...)
+
+ def run(self):
+ # query your database here
+ context = query_database(self.question)
+
+ if context is None:
+ raise ValueError("No context found. Please propose to the user to change the topic.")
+ else:
+ self.shared_state.set("context", context)
+ return "Context retrieved. Please proceed with explaining the answer."
+
shared_state
to validate actions taken by other agents, before allowing them to proceed with the next action.
+class Action2(BaseTool):
+ input: str = Field(...)
+
+ def run(self):
+ if self.shared_state.get("action_1_result", None) is "failure":
+ raise ValueError("Please proceed with the Action1 tool first.")
+ else:
+ return "Success. The action has been taken."
+
one_call_at_a_time
class attribute to prevent multiple instances of the same tool from running at the same time. This is useful when you want your agents to see the results of the previous action before proceeding with the next one.
+
+Agent
+
+
+agency_swarm/agents/agent.py
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 +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 |
|
__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-4-turbo', validation_attempts=1, max_prompt_tokens=None, max_completion_tokens=None, truncation_strategy=None, examples=None)
+
+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 |
+
+ Dict
+ |
+
+
+
+ The response format for the OpenAI API. 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-4-turbo-preview". + |
+
+ 'gpt-4-turbo'
+ |
+
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
+ |
+
This constructor sets up the agent with its unique properties, initializes the OpenAI client, reads instructions if provided, and uploads any associated files.
+ +agency_swarm/agents/agent.py
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 |
|
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.
+ +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.
+ +self: Returns the agent instance for chaining methods or further processing.
+agency_swarm/agents/agent.py
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 |
|
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. + |
+
agency_swarm/agents/agent.py
Agency
+
+
+agency_swarm/agency/agency.py
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 +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 |
|
__init__(agency_chart, shared_instructions='', shared_files=None, async_mode=None, 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
+ |
+
+
+
+ The mode for asynchronous message processing. Defaults to None. + |
+
+ None
+ |
+
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.
+ +agency_swarm/agency/agency.py
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 |
|
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.
+ +agency_swarm/agency/agency.py
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 |
|
get_completion(message, message_files=None, yield_messages=False, recipient_agent=None, additional_instructions=None, attachments=None, tool_choice=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
+ |
+
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. + |
+
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)
+
+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
+ |
+
Returns:
+Type | +Description | +
---|---|
+ | +
+
+
+ Final response: Final response from the main thread. + |
+
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 + | +
agency_swarm/agency/agency.py
run_demo()
+
+Executes agency in the terminal with autocomplete for recipient agent names.
+ +agency_swarm/agency/agency.py
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 |
|
ToolFactory
+
+
+agency_swarm/tools/ToolFactory.py
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 +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 |
|
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. + |
+
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. + |
+
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. + |
+
agency_swarm/tools/ToolFactory.py
from_openai_schema(schema, callback)
+
+
+ staticmethod
+
+
+Converts an OpenAI schema into a BaseTool. Nested propoerties without refs are not supported yet.
+ + + +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. + |
+
agency_swarm/tools/ToolFactory.py
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 |
|
from_openapi_schema(schema, headers=None, params=None)
+
+
+ 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
+ |
+
Returns:
+Type | +Description | +
---|---|
+ List[Type[BaseTool]]
+ |
+
+
+
+ A list of BaseTools. + |
+
agency_swarm/tools/ToolFactory.py
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 |
|
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. + |
+
agency_swarm/tools/ToolFactory.py
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 |
|