ToolsetOrchestrator
When your application needs to manage tools from multiple different sources (e.g., several distinct APIs) or wants to group tools from a single large API into logical, specialized sets, the ToolsetOrchestrator comes into play.
It's a higher-level manager responsible for creating and providing access to IToolSet instances. An IToolSet is a named collection of tools, often representing the capabilities of a "specialist" or a particular domain.
This component is key to enabling advanced agent architectures like the hierarchicalPlanner mode in ApiInteractionManager.
Key Responsibilities
Consuming
ToolProviderSourceConfigs: It takes an array ofToolProviderSourceConfigobjects. Each config describes a source of tools, primarily an OpenAPI specification.Instantiating
IToolProviders: For eachToolProviderSourceConfigof type 'openapi', it creates anOpenAPIConnectorinstance.Creating
IToolSets: Based on thetoolsetCreationStrategyin eachToolProviderSourceConfig:byTag: It creates a separateIToolSetfor each tag found in the OpenAPI specification. For example, an e-commerce API might have tags like "products", "orders", "users", leading to three distinct toolsets.allInOne: It groups all tools from that specific OpenAPI provider into a singleIToolSet.
LLM-Powered Toolset Splitting (Optional):
If an
IToolSet(whether frombyTagorallInOne) contains more tools than a configurablemaxToolsPerLogicalGroupthreshold, and if anILLMClientis provided to theToolsetOrchestrator, it will attempt to use the LLM to further divide that large toolset into smaller, more semantically coherentIToolSets.The LLM is prompted to analyze the tool definitions (summaries, descriptions) and suggest logical groupings.
If LLM splitting is not available or fails, it falls back to creating the larger, unsplit toolset.
Providing Access to Toolsets: Offers methods like
getToolsets()andgetToolset(id)for other parts of the system (likeApiInteractionManagerorDelegateToSpecialistTool) to retrieve these organized collections of tools.Managing Underlying Providers: Keeps track of the actual
IToolProviderinstances (e.g.,OpenAPIConnectors) it creates.
ToolProviderSourceConfig
This is the input configuration for the ToolsetOrchestrator:
id: A unique identifier for this source. This ID is often used to name the resulting toolsets (e.g.,petStoreApi_products,googleCalendarApi_events).openapiConnectorOptions: The configuration for theOpenAPIConnectorthat will be created for this source. Important: ThesourceIdfield withinopenapiConnectorOptionswill be automatically set byToolsetOrchestratorto match the top-levelidof theToolProviderSourceConfig.toolsetCreationStrategy:byTag: For an API with tags "A" and "B", toolsets likeid_Aandid_Bwould be created.allInOne: A single toolset, possibly namedid_allor usingallInOneToolsetName.
maxToolsPerLogicalGroup: If a toolset derived from a tag orallInOnestrategy still has too many tools (e.g., >10), LLM-splitting is attempted.llmSplittingConfig: If you provide anILLMClientto theToolsetOrchestrator's constructor, these settings will be used when it calls the LLM to suggest splits for oversized toolsets.
How it's Used
The ToolsetOrchestrator is primarily used by:
ApiInteractionManagerinhierarchicalPlannermode:AIM instantiates
ToolsetOrchestratorwith thetoolsetOrchestratorConfig.The resulting
IToolSets are then made available to theDelegateToSpecialistTool.The
PlanningAgentuses theDelegateToSpecialistToolto delegate sub-tasks, selecting a specialist (anIToolSet) by its ID.
Example Initialization (as done within ApiInteractionManager):
LLM-Powered Splitting
If a toolset (e.g., all tools under the "pets" tag in PetStore API) has, say, 25 tools, and maxToolsPerLogicalGroup is 10, the ToolsetOrchestrator (if given an llmClient) will:
Extract definitions (summary, description) of those 25 tools.
Send these definitions to an LLM (e.g., GPT-4o-mini) with a prompt asking it to:
"Organize these API operations into 2-5 smaller, coherent, non-overlapping groups based on functionality."
"Output a JSON object where keys are your suggested group names, and values are arrays of
operationIds belonging to that group."
Parse the LLM's JSON response.
For each suggested group from the LLM (e.g., "PetInventoryManagement", "PetFindingServices"):
Create a new
IToolSet.The ID might be
originalSourceId_originalTag_llmGroupName(e.g.,petStoreApi_pets_PetInventoryManagement).The tools in this new set are only those
operationIds assigned by the LLM to this group.The original, large toolset (e.g.,
petStoreApi_pets) is replaced by these smaller, LLM-defined toolsets.
This intelligent splitting helps in:
Clarity for Planning LLMs: A
PlanningAgentsees a list of more focused specialists (e.g., "PetInventorySpecialist" instead of a generic "PetStoreSpecialist" with too many options).Improved Delegation Accuracy: The planner can more easily choose the right specialist if their capabilities are well-defined and not overly broad.
Reduced Prompt Size: The
DelegateToSpecialistTool's definition (which lists available specialists) becomes more manageable.
If no llmClient is provided to the ToolsetOrchestrator, or if the LLM-splitting fails (e.g., bad JSON from LLM, LLM call error), the orchestrator falls back to creating the larger, unsplit toolset as defined by the toolsetCreationStrategy (byTag or allInOne).
The ToolsetOrchestrator is a sophisticated component that brings structure and scalability to how agents access and utilize large numbers of tools from diverse sources, especially in complex, multi-agent architectures.
Last updated