Skip to content

Commit

Permalink
check agent id
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelcroi committed Jul 26, 2024
1 parent ff7fb97 commit 0070cf0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ export class MultiAgentOrchestrator {
}

addAgent(agent: Agent): void {
if (this.agents[agent.id]) {
throw new Error(`An agent with ID '${agent.id}' already exists.`);
}
this.agents[agent.id] = agent;
this.classifier.setAgents(this.agents);
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Classifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ describe("Classifier", () => {
expect(response.selectedAgent?.name).toBe('Math Agent');
}, 15000);

it('should throw an error when adding an agent with an existing ID', () => {
const existingAgent = new BedrockLLMAgent({
name: "EXISTING",
streaming: true,
description: 'Existing agent',
});
orchestrator.addAgent(existingAgent);

const duplicateAgent = new BedrockLLMAgent({
name: "EXISTING",
streaming: true,
description: 'Duplicate agent',
});

expect(() => {
orchestrator.addAgent(duplicateAgent);
}).toThrow(`An agent with ID '${duplicateAgent.id}' already exists.`);
});

});


Expand Down

0 comments on commit 0070cf0

Please sign in to comment.