Skip to content

Commit 57e709e

Browse files
committed
refactor(agent): remove legacy agentStates variable
- Removed agentStates variable from agentStart.ts - Updated agentMessage.ts to no longer use the legacy variable - Simplified agentTools.test.ts to no longer rely on the legacy variable - All tests still pass with this simpler implementation
1 parent a9b324c commit 57e709e

File tree

3 files changed

+6
-27
lines changed

3 files changed

+6
-27
lines changed

packages/agent/src/tools/agent/agentMessage.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
33

44
import { Tool } from '../../core/types.js';
55

6-
import { agentStates } from './agentStart.js';
7-
86
const parameterSchema = z.object({
97
agentId: z.string().describe('The ID returned by agentStart'),
108
guidance: z
@@ -65,18 +63,8 @@ export const agentMessageTool: Tool<Parameters, ReturnType> = {
6563
);
6664

6765
try {
68-
// First try to get the agent from the tracker
69-
let agent = agentTracker.getAgent(agentId);
70-
71-
// Fall back to legacy agentStates for backward compatibility
72-
if (!agent && agentStates.has(agentId)) {
73-
// If found in legacy store, register it with the tracker for future use
74-
const legacyState = agentStates.get(agentId)!;
75-
agentTracker.registerAgent(legacyState);
76-
77-
// Try again with the newly registered agent
78-
agent = agentTracker.getAgent(agentId);
79-
}
66+
// Get the agent from the tracker
67+
const agent = agentTracker.getAgent(agentId);
8068

8169
if (!agent) {
8270
throw new Error(`No sub-agent found with ID ${agentId}`);

packages/agent/src/tools/agent/agentStart.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import { Tool, ToolContext } from '../../core/types.js';
1111
import { LogLevel, Logger, LoggerListener } from '../../utils/logger.js';
1212
import { getTools } from '../getTools.js';
1313

14-
import { AgentStatus, AgentInfo } from './AgentTracker.js';
15-
16-
// For backward compatibility
17-
export const agentStates = new Map<string, AgentInfo>();
14+
import { AgentStatus } from './AgentTracker.js';
1815

1916
// Generate a random color for an agent
2017
// Avoid colors that are too light or too similar to error/warning colors
@@ -189,11 +186,8 @@ export const agentStartTool: Tool<Parameters, ReturnType> = {
189186

190187
logger.debug(`Registered agent with ID: ${agentId}`);
191188

192-
// For backward compatibility
193-
const agent = agentTracker.getAgent(agentId);
194-
if (agent) {
195-
agentStates.set(agentId, agent);
196-
}
189+
// Get the agent for verification (not used but useful for debugging)
190+
const _agent = agentTracker.getAgent(agentId);
197191

198192
// Start the agent in a separate promise that we don't await
199193
// eslint-disable-next-line promise/catch-or-return

packages/agent/src/tools/agent/agentTools.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SessionTracker } from '../session/SessionTracker.js';
77
import { ShellTracker } from '../shell/ShellTracker.js';
88

99
import { agentMessageTool } from './agentMessage.js';
10-
import { agentStartTool, agentStates } from './agentStart.js';
10+
import { agentStartTool } from './agentStart.js';
1111
import { AgentTracker } from './AgentTracker.js';
1212

1313
// Mock the toolAgent function
@@ -57,9 +57,6 @@ describe('Agent Tools', () => {
5757
expect(agent).toHaveProperty('goal', 'Test the agent tools');
5858
expect(agent).toHaveProperty('completed', false);
5959
expect(agent).toHaveProperty('aborted', false);
60-
61-
// Verify it was also added to legacy agentStates for backward compatibility
62-
expect(agentStates.has(result.agentId)).toBe(true);
6360
});
6461
});
6562

0 commit comments

Comments
 (0)