onboarding.mdx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. ---
  2. title: "Onboarding"
  3. description: "Learn how to templatize your agents on our marketplace."
  4. icon: "store"
  5. ---
  6. When posting an agency on our marketplace, you can define a custom `OnboardingTool` to allow end users to customize your agents for their own businesses.
  7. ## Why Customization is Important?
  8. When building AI agents, you might encounter clients who want to deploy agents for the same roles.
  9. For example, almost every company employs an **accountant**. And so, if you built an accounting agent for one company, you might want to reuse it later.
  10. However, although the **general process** for the same role across various companies is similar, the **specific process** is always unique.
  11. For example, one company might do accounting **weekly**, another one **monthly**. One company might use **Xero**, another one **Quick books**. One company prefers to send invoices via **email**, another one via their **customer portal**, and so on.
  12. As you can see, **even if you built an agent for the same role at one company, it’s not gonna be useful at another company**.
  13. ## How Agencii Solves Agent Onboarding
  14. On our platform, we tackle this issue by creating a custom `OnboardingTool` class.
  15. Inside this tool class, you can define all the parameters that you need in order to customize your agents before deployment.
  16. For our accounting agent above, for example, this class might look like this:
  17. ```python
  18. from agency_swarm.tools import BaseTool
  19. from pydantic import Field
  20. import os
  21. from dotenv import load_dotenv
  22. from typing import Literal
  23. load_dotenv()
  24. class OnboardingTool(BaseTool):
  25. """
  26. Customizes the accounting agent based on the client's specific accounting processes,
  27. software, and preferences before deployment.
  28. """
  29. agent_name: str = Field(
  30. ...,
  31. description="Name of your accounting agent visible to the user."
  32. )
  33. business_overview: str = Field(
  34. ...,
  35. description="Brief business overview including industry, size, and accounting needs."
  36. )
  37. accounting_frequency: Literal["weekly", "monthly", "quarterly"] = Field(
  38. ...,
  39. description="How often accounting tasks should be performed."
  40. )
  41. accounting_software: Literal["xero", "quickbooks", "freshbooks", "sage", "other"] = Field(
  42. ...,
  43. description="The accounting software platform the client uses."
  44. )
  45. invoice_delivery_method: Literal["email", "customer_portal", "both"] = Field(
  46. ...,
  47. description="Preferred method for sending invoices to clients."
  48. )
  49. def run(self):
  50. """
  51. Programmatically writes a JSON config containing all user-provided accounting parameters
  52. to onboarding_config.json, in the exact same directory as this tool file.
  53. """
  54. import json
  55. # Get tool directory path
  56. tool_dir = os.path.dirname(os.path.abspath(__file__))
  57. config_path = os.path.join(tool_dir, "onboarding_config.json")
  58. # Dynamically collect all pydantic model fields into a dict
  59. config = self.model_dump()
  60. # Write config file
  61. try:
  62. with open(config_path, "w", encoding="utf-8") as f:
  63. json.dump(config, f, indent=2, ensure_ascii=False)
  64. return f"Accounting agent configuration created at: {config_path}"
  65. except Exception as e:
  66. return f"Error writing config file: {str(e)}"
  67. if __name__ == "__main__":
  68. # Test with sample accounting client data
  69. tool = OnboardingTool(
  70. agent_name="Acme Corp Accounting Agent",
  71. business_overview="Mid-size manufacturing company with 50 employees.",
  72. accounting_frequency="monthly",
  73. accounting_software="xero",
  74. invoice_delivery_method="customer_portal"
  75. )
  76. print(tool.run())
  77. ```
  78. **Key things to note**:
  79. - `OnboardingTool` must extend `BaseTool` class.
  80. - File name must be `onboarding_tool.py`
  81. - The file needs to be placed in the **repository root directory**.
  82. - All field descriptions will be displayed during the onboarding process on our platform.
  83. - We will replace “_” with spaces, capitalize fields names and display them as titles, unless you `ui:title` parameter is provided.
  84. ## How This Will Look On Agencii
  85. When users deploy your agents from the marketplace, we will parse this class into a JSON schema and display it as a form:
  86. ![onboarding form example](/images/platform/onboarding_form.png)
  87. All that the user who wants to deploy your agency needs to do is simply fill out this form! That's it!
  88. ## Step-by-Step Guide: How to Create Your Own Agent Onboarding Form
  89. 1. **Copy our template and place it in `onboarding_tool.py` file in the root directory:**
  90. ```python
  91. from agency_swarm.tools import BaseTool
  92. from pydantic import Field
  93. import os
  94. from dotenv import load_dotenv
  95. from typing import Literal
  96. load_dotenv()
  97. class OnboardingTool(BaseTool):
  98. """
  99. Customizes your agent based on client-specific requirements before deployment.
  100. Replace the fields below with parameters relevant to your use case.
  101. """
  102. # String fields - use for names, descriptions, and text inputs
  103. agent_name: str = Field(
  104. ...,
  105. description="Name of your agent visible to the user."
  106. )
  107. business_overview: str = Field(
  108. ...,
  109. description="Brief overview of the client's business or requirements."
  110. )
  111. # String fields for additional context
  112. additional_notes: str = Field(
  113. ...,
  114. description="Any additional notes or special requirements for the agent."
  115. )
  116. def run(self):
  117. """
  118. Saves the configuration as a Python file with a config object
  119. """
  120. import pprint
  121. tool_dir = os.path.dirname(os.path.abspath(__file__))
  122. config_path = os.path.join(tool_dir, "onboarding_config.py")
  123. config = self.model_dump(mode="python")
  124. try:
  125. # Generate Python code with Python-safe literals (None/True/False)
  126. python_code = (
  127. "# Auto-generated onboarding configuration\n\n"
  128. f"config = {pprint.pformat(config, sort_dicts=True)}\n"
  129. )
  130. with open(config_path, "w", encoding="utf-8") as f:
  131. f.write(python_code)
  132. return f"Configuration saved at: {config_path}\n\nYou can now import it with:\nfrom onboarding_config import config"
  133. except Exception as e:
  134. return f"Error writing config file: {str(e)}"
  135. if __name__ == "__main__":
  136. tool = OnboardingTool(
  137. agent_name="Example Agent",
  138. business_overview="Example business description",
  139. additional_notes="Any special requirements go here"
  140. )
  141. print(tool.run())
  142. ```
  143. 2. Add your own specific fields with pydantic that are required to fine-tune your agents:
  144. ```python
  145. # Example: Adding Literal field (dropdown menu)
  146. from typing import Literal
  147. class OnboardingTool(BaseTool):
  148. # ...
  149. # Literal field - creates a dropdown with predefined options
  150. model: Literal["gpt-4o", "gpt-5.4-mini"] = Field(
  151. ...,
  152. description="Select the AI model to use for the agent."
  153. )
  154. # ...
  155. ```
  156. 3. **Execute the tool file:**
  157. ```python
  158. python onboarding_tool.py
  159. ```
  160. This will generate `onboarding_config.py` next to your onboarding tool file.
  161. <aside>
  162. In most cases, you don’t need to change the `run` method. You can simply use the values from `config.py` in your code. (See steps below)
  163. </aside>
  164. 4. **Customize your agents**
  165. Use the values from the generated [config.py](http://config.py) file in your code to customize your agents:
  166. ```python
  167. from agency_swarm import Agent
  168. from onboarding_config import config
  169. import os
  170. current_dir = os.path.dirname(os.path.abspath(__file__))
  171. instructions_path = os.path.join(current_dir, "instructions.md")
  172. def render_instructions():
  173. with open(instructions_path, "r") as file:
  174. instructions = file.read()
  175. instructions = instructions.format(
  176. agent_name=config["agent_name"],
  177. business_overview=config["business_overview"],
  178. additional_notes=config["additional_notes"]
  179. )
  180. return instructions
  181. rag_agent = Agent(
  182. name=onboarding_config["agent_name"],
  183. description=onboarding_config["agent_description"],
  184. instructions=render_instructions(),
  185. files_folder="./files",
  186. model=config["model"],
  187. )
  188. ```
  189. In this example we:
  190. - Customized the instructions.
  191. - Customized the model.
  192. 5. Deploy and list on marketplace
  193. 1. Deploy your agent as usual, just make sure to commit the default `onboarding_config`for your own account.
  194. 2. Test the agency is working as expected on your account first.
  195. 3. List your agent on our marketplace by going to https://agencii.ai/marketplace/
  196. That’s it! This is how simple it is to customize and scale your agents with our platform.
  197. ## Advanced Fields & Parameters
  198. We use [react-jsonschema-form](https://rjsf-team.github.io/react-jsonschema-form/docs/) to render the onboarding form.
  199. You can use the following uiSchema parameters to customize the form:
  200. - `ui:widget`: controls which UI component is used for the field. (e.g. `text`, `textarea`, etc.)
  201. - `ui:options`: controls widget-specific options (e.g. `rows`, `inputType`, `label`, etc.).
  202. - `ui:title`: overrides the field’s title.
  203. - `ui:description`: overrides the field’s description.
  204. - `ui:readonly`: makes the field read-only.
  205. - `ui:disabled`: disables user interaction entirely.
  206. - `required`: belongs in the **JSON schema**, not the uiSchema.
  207. ### File Uploads
  208. To upload your files, you must add `"x-file-upload-path"` , and the type of the field must be set `list[str]` .
  209. ```python
  210. # List fields - use for multiple selections or file uploads
  211. accountant_agent_knowledge: list[str] = Field(
  212. ...,
  213. description="Files that accountant agent must have as knowledge.",
  214. json_schema_extra={
  215. "x-file-upload-path": "./accountant_agent/files", # standard JSON Schema
  216. },
  217. )
  218. ```
  219. After user uploads the files, they will be added to `./accountant_agent/files` folder.
  220. ### Multiline Text Inputs
  221. `ui:widget` parameter in `json_schema_extra` controls UI component displayed in the onboarding form
  222. ```python
  223. additional_notes: Optional[str] = Field(
  224. None,
  225. description="Any additional notes for the agent to go into prompt.",
  226. json_schema_extra={
  227. "ui:widget": "textarea",
  228. },
  229. )
  230. ```
  231. ## A Note on Form Updates
  232. - If you push a change to the form, **the users of your agents will be required to re-enter any new and updated fields**. Do this with caution!
  233. - The summary of the commit that triggered the update will be displayed to the user in the form as the reason for the update.
  234. - The new version won’t be deployed for the users until they complete an onboarding form.