update
This commit is contained in:
@@ -23,6 +23,7 @@ export class DualAgentOrchestrator {
|
||||
private tools: Map<string, BaseToolWrapper> = new Map();
|
||||
private isRunning = false;
|
||||
private conversationHistory: interfaces.IAgentMessage[] = [];
|
||||
private ownsSmartAi = true; // true if we created the SmartAi instance, false if it was provided
|
||||
|
||||
constructor(options: interfaces.IDualAgentOptions) {
|
||||
this.options = {
|
||||
@@ -32,18 +33,15 @@ export class DualAgentOrchestrator {
|
||||
...options,
|
||||
};
|
||||
|
||||
// Create SmartAi instance
|
||||
this.smartai = new plugins.smartai.SmartAi(options);
|
||||
|
||||
// Get providers
|
||||
this.driverProvider = this.getProviderByName(this.options.defaultProvider!);
|
||||
this.guardianProvider = this.options.guardianProvider
|
||||
? this.getProviderByName(this.options.guardianProvider)
|
||||
: this.driverProvider;
|
||||
|
||||
// Create agents
|
||||
this.driver = new DriverAgent(this.driverProvider, options.driverSystemMessage);
|
||||
this.guardian = new GuardianAgent(this.guardianProvider, options.guardianPolicyPrompt);
|
||||
// Use existing SmartAi instance if provided, otherwise create a new one
|
||||
if (options.smartAiInstance) {
|
||||
this.smartai = options.smartAiInstance;
|
||||
this.ownsSmartAi = false; // Don't manage lifecycle of provided instance
|
||||
} else {
|
||||
this.smartai = new plugins.smartai.SmartAi(options);
|
||||
this.ownsSmartAi = true;
|
||||
}
|
||||
// Note: Don't access providers here - they don't exist until start() is called
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,8 +73,13 @@ export class DualAgentOrchestrator {
|
||||
*/
|
||||
public registerTool(tool: BaseToolWrapper): void {
|
||||
this.tools.set(tool.name, tool);
|
||||
this.driver.registerTool(tool);
|
||||
this.guardian.registerTool(tool);
|
||||
// Register with agents if they exist (they're created in start())
|
||||
if (this.driver) {
|
||||
this.driver.registerTool(tool);
|
||||
}
|
||||
if (this.guardian) {
|
||||
this.guardian.registerTool(tool);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,8 +103,26 @@ export class DualAgentOrchestrator {
|
||||
* Initialize all tools (eager loading)
|
||||
*/
|
||||
public async start(): Promise<void> {
|
||||
// Start smartai
|
||||
await this.smartai.start();
|
||||
// Start smartai only if we created it (external instances should already be started)
|
||||
if (this.ownsSmartAi) {
|
||||
await this.smartai.start();
|
||||
}
|
||||
|
||||
// NOW get providers (after they've been initialized by smartai.start())
|
||||
this.driverProvider = this.getProviderByName(this.options.defaultProvider!);
|
||||
this.guardianProvider = this.options.guardianProvider
|
||||
? this.getProviderByName(this.options.guardianProvider)
|
||||
: this.driverProvider;
|
||||
|
||||
// NOW create agents with initialized providers
|
||||
this.driver = new DriverAgent(this.driverProvider, this.options.driverSystemMessage);
|
||||
this.guardian = new GuardianAgent(this.guardianProvider, this.options.guardianPolicyPrompt);
|
||||
|
||||
// Register any tools that were added before start() with the agents
|
||||
for (const tool of this.tools.values()) {
|
||||
this.driver.registerTool(tool);
|
||||
this.guardian.registerTool(tool);
|
||||
}
|
||||
|
||||
// Initialize all tools
|
||||
const initPromises: Promise<void>[] = [];
|
||||
@@ -124,9 +145,16 @@ export class DualAgentOrchestrator {
|
||||
}
|
||||
|
||||
await Promise.all(cleanupPromises);
|
||||
await this.smartai.stop();
|
||||
|
||||
// Only stop smartai if we created it (don't stop external instances)
|
||||
if (this.ownsSmartAi) {
|
||||
await this.smartai.stop();
|
||||
}
|
||||
|
||||
this.isRunning = false;
|
||||
this.driver.reset();
|
||||
if (this.driver) {
|
||||
this.driver.reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user