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
ToolProviderSourceConfig
s: It takes an array ofToolProviderSourceConfig
objects. Each config describes a source of tools, primarily an OpenAPI specification.Instantiating
IToolProvider
s: For eachToolProviderSourceConfig
of type 'openapi', it creates anOpenAPIConnector
instance.Creating
IToolSet
s: Based on thetoolsetCreationStrategy
in eachToolProviderSourceConfig
:byTag
: It creates a separateIToolSet
for 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 frombyTag
orallInOne
) contains more tools than a configurablemaxToolsPerLogicalGroup
threshold, and if anILLMClient
is provided to theToolsetOrchestrator
, it will attempt to use the LLM to further divide that large toolset into smaller, more semantically coherentIToolSet
s.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 (likeApiInteractionManager
orDelegateToSpecialistTool
) to retrieve these organized collections of tools.Managing Underlying Providers: Keeps track of the actual
IToolProvider
instances (e.g.,OpenAPIConnector
s) it creates.
ToolProviderSourceConfig
ToolProviderSourceConfig
This is the input configuration for the ToolsetOrchestrator
:
interface ToolProviderSourceConfig {
id: string; // e.g., 'petStoreApi', 'googleCalendarApi'
type?: 'openapi'; // Currently primary type
openapiConnectorOptions: Omit<OpenAPIConnectorOptions, 'sourceId'>;
toolsetCreationStrategy?: 'byTag' | 'allInOne'; // Default: 'byTag' if tags exist, else 'allInOne'
allInOneToolsetName?: string;
allInOneToolsetDescription?: string;
maxToolsPerLogicalGroup?: number; // Default: e.g., 10
llmSplittingConfig?: { // Settings for the LLM used for splitting
model: string;
temperature?: number;
maxTokens?: number;
};
}
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 theOpenAPIConnector
that will be created for this source. Important: ThesourceId
field withinopenapiConnectorOptions
will be automatically set byToolsetOrchestrator
to match the top-levelid
of theToolProviderSourceConfig
.toolsetCreationStrategy
:byTag
: For an API with tags "A" and "B", toolsets likeid_A
andid_B
would be created.allInOne
: A single toolset, possibly namedid_all
or usingallInOneToolsetName
.
maxToolsPerLogicalGroup
: If a toolset derived from a tag orallInOne
strategy still has too many tools (e.g., >10), LLM-splitting is attempted.llmSplittingConfig
: If you provide anILLMClient
to 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:
ApiInteractionManager
inhierarchicalPlanner
mode:AIM instantiates
ToolsetOrchestrator
with thetoolsetOrchestratorConfig
.The resulting
IToolSet
s are then made available to theDelegateToSpecialistTool
.The
PlanningAgent
uses theDelegateToSpecialistTool
to delegate sub-tasks, selecting a specialist (anIToolSet
) by its ID.
Example Initialization (as done within ApiInteractionManager
):
import { ToolsetOrchestrator, ToolProviderSourceConfig, ILLMClient } from '@ulifeai/agentb';
// Assuming llmClient is an initialized ILLMClient instance
// Assuming petStoreConfig and calendarConfig are ToolProviderSourceConfig objects
const orchestratorConfigs: ToolProviderSourceConfig[] = [petStoreConfig, calendarConfig];
const orchestrator = new ToolsetOrchestrator(orchestratorConfigs, llmClient); // Pass LLM client for splitting
async function setup() {
await orchestrator.ensureInitialized(); // Creates all toolsets
const allToolsets = await orchestrator.getToolsets();
console.log("Available Toolsets (Specialists):");
for (const ts of allToolsets) {
console.log(`- ID: ${ts.id}, Name: ${ts.name}, Tools: ${ts.tools.length}`);
// For debugging, list tools in each set:
// for (const tool of ts.tools) {
// const def = await tool.getDefinition();
// console.log(` - ${def.name}`);
// }
}
const petStoreProductTools = await orchestrator.getToolset('petStoreApi_products'); // Example ID
if (petStoreProductTools) {
// ...
}
}
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
operationId
s 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
operationId
s 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
PlanningAgent
sees 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