Skip to content

Commit 0de96db

Browse files
committed
Refactor agent type usage to AgentType enum
Replaces the AgentTypeString type with the AgentType enum throughout the codebase for improved type safety and consistency. Updates related interfaces, utility functions, and service methods to use AgentType directly. Also updates the create_plan API endpoint path.
1 parent 1cf5c29 commit 0de96db

File tree

4 files changed

+36
-42
lines changed

4 files changed

+36
-42
lines changed

src/frontend/src/api/apiService.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ import {
99
Step,
1010
StepStatus,
1111
AgentType,
12-
AgentTypeString,
1312
PlanMessage
1413
} from '../models';
1514

1615
// Constants for endpoints
1716
const API_ENDPOINTS = {
1817
INPUT_TASK: '/input_task',
19-
CREATE_PLAN: '/create_plan',
18+
CREATE_PLAN: '/v3/create_plan',
2019
PLANS: '/plans',
2120
STEPS: '/steps',
2221
HUMAN_FEEDBACK: '/human_feedback',
@@ -469,7 +468,7 @@ export class APIService {
469468
* @param agentType Agent type to filter by
470469
* @returns Array of steps for the specified agent
471470
*/
472-
getStepsForAgent(plan: PlanWithSteps, agentType: AgentTypeString): Step[] {
471+
getStepsForAgent(plan: PlanWithSteps, agentType: AgentType): Step[] {
473472
return plan.steps.filter(step => step.agent === agentType);
474473
}
475474

src/frontend/src/models/enums.tsx

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export enum AgentType {
1717
TECH_SUPPORT = "Tech_Support_Agent",
1818
GROUP_CHAT_MANAGER = "Group_Chat_Manager",
1919
PLANNER = "Planner_Agent",
20-
20+
2121
// Common uploadable agent types
2222
MAGENTIC_ONE = "MagenticOne",
2323
CUSTOM = "Custom",
2424
RAG = "RAG",
25-
25+
2626
// Specific agent names (can be any name with any type)
2727
CODER = "Coder",
2828
EXECUTOR = "Executor",
@@ -32,10 +32,6 @@ export enum AgentType {
3232
MAINTENANCE_KB_AGENT = "MaintanceKBAgent",
3333
}
3434

35-
/**
36-
* Type representing any agent type - either from the enum or a custom string
37-
*/
38-
export type AgentTypeString = AgentType | string;
3935

4036
/**
4137
* Utility functions for working with agent types
@@ -44,46 +40,46 @@ export class AgentTypeUtils {
4440
/**
4541
* Get display name for an agent type
4642
*/
47-
static getDisplayName(agentType: AgentTypeString): string {
43+
static getDisplayName(agentType: AgentType): string {
4844
// Convert to string first
4945
const typeStr = String(agentType);
50-
46+
5147
// Handle specific formatting for known patterns
5248
if (typeStr.includes('_Agent')) {
5349
return typeStr.replace('_Agent', '').replace('_', ' ');
5450
}
55-
51+
5652
// Handle camelCase and PascalCase names
5753
return typeStr.replace(/([A-Z])/g, ' $1').replace(/^./, str => str.toUpperCase()).trim();
5854
}
5955

6056
/**
6157
* Check if an agent type is a known/default type
6258
*/
63-
static isKnownType(agentType: AgentTypeString): boolean {
64-
return Object.values(AgentType).includes(agentType as AgentType);
59+
static isKnownType(agentType: AgentType): boolean {
60+
return Object.values(AgentType).includes(agentType);
6561
}
6662

6763
/**
6864
* Get agent type from string, with fallback to the original string
6965
*/
70-
static fromString(type: string): AgentTypeString {
66+
static fromString(type: string): AgentType {
7167
// First check if it's a known enum value
7268
const enumValue = Object.values(AgentType).find(value => value === type);
7369
if (enumValue) {
7470
return enumValue;
7571
}
76-
72+
7773
// Return the custom type as-is
78-
return type;
74+
return AgentType.CUSTOM;
7975
}
8076

8177
/**
8278
* Get agent type category
8379
*/
84-
static getAgentCategory(agentType: AgentTypeString): 'system' | 'magentic-one' | 'custom' | 'rag' | 'unknown' {
80+
static getAgentCategory(agentType: AgentType): 'system' | 'magentic-one' | 'custom' | 'rag' | 'unknown' {
8581
const typeStr = String(agentType);
86-
82+
8783
// System/Legacy agents
8884
if ([
8985
'Human_Agent', 'Hr_Agent', 'Marketing_Agent', 'Procurement_Agent',
@@ -92,39 +88,39 @@ export class AgentTypeUtils {
9288
].includes(typeStr)) {
9389
return 'system';
9490
}
95-
91+
9692
// MagenticOne framework agents
9793
if (typeStr === 'MagenticOne' || [
9894
'Coder', 'Executor', 'FileSurfer', 'WebSurfer'
9995
].includes(typeStr)) {
10096
return 'magentic-one';
10197
}
102-
98+
10399
// RAG agents
104100
if (typeStr === 'RAG' || typeStr.toLowerCase().includes('rag') || typeStr.toLowerCase().includes('kb')) {
105101
return 'rag';
106102
}
107-
103+
108104
// Custom agents
109105
if (typeStr === 'Custom') {
110106
return 'custom';
111107
}
112-
108+
113109
return 'unknown';
114110
}
115111

116112
/**
117113
* Get icon for agent type based on category and name
118114
*/
119-
static getAgentIcon(agentType: AgentTypeString, providedIcon?: string): string {
115+
static getAgentIcon(agentType: AgentType, providedIcon?: string): string {
120116
// If icon is explicitly provided, use it
121117
if (providedIcon && providedIcon.trim()) {
122118
return providedIcon;
123119
}
124-
120+
125121
const category = this.getAgentCategory(agentType);
126122
const typeStr = String(agentType);
127-
123+
128124
// Specific agent name mappings
129125
const iconMap: Record<string, string> = {
130126
'Coder': 'Terminal',
@@ -134,11 +130,11 @@ export class AgentTypeUtils {
134130
'SensorSentinel': 'BookMarked',
135131
'MaintanceKBAgent': 'Search',
136132
};
137-
133+
138134
if (iconMap[typeStr]) {
139135
return iconMap[typeStr];
140136
}
141-
137+
142138
// Category-based defaults
143139
switch (category) {
144140
case 'system':
@@ -159,45 +155,45 @@ export class AgentTypeUtils {
159155
*/
160156
static validateAgent(agent: any): { isValid: boolean; errors: string[] } {
161157
const errors: string[] = [];
162-
158+
163159
if (!agent || typeof agent !== 'object') {
164160
errors.push('Agent must be a valid object');
165161
return { isValid: false, errors };
166162
}
167-
163+
168164
// Required fields
169165
if (!agent.input_key || typeof agent.input_key !== 'string' || agent.input_key.trim() === '') {
170166
errors.push('Agent input_key is required and cannot be empty');
171167
}
172-
168+
173169
if (!agent.type || typeof agent.type !== 'string' || agent.type.trim() === '') {
174170
errors.push('Agent type is required and cannot be empty');
175171
}
176-
172+
177173
if (!agent.name || typeof agent.name !== 'string' || agent.name.trim() === '') {
178174
errors.push('Agent name is required and cannot be empty');
179175
}
180-
176+
181177
// Optional fields validation
182178
const optionalStringFields = ['system_message', 'description', 'icon', 'index_name'];
183179
optionalStringFields.forEach(field => {
184180
if (agent[field] !== undefined && typeof agent[field] !== 'string') {
185181
errors.push(`Agent ${field} must be a string if provided`);
186182
}
187183
});
188-
184+
189185
// Special validation for RAG agents
190186
if (agent.type === 'RAG' && (!agent.index_name || agent.index_name.trim() === '')) {
191187
errors.push('RAG agents must have a valid index_name specified');
192188
}
193-
189+
194190
return { isValid: errors.length === 0, errors };
195191
}
196192

197193
/**
198194
* Get all available agent types (both enum and common custom types)
199195
*/
200-
static getAllAvailableTypes(): AgentTypeString[] {
196+
static getAllAvailableTypes(): AgentType[] {
201197
return [
202198
...Object.values(AgentType),
203199
// Add other common types that might come from JSON uploads

src/frontend/src/models/plan.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AgentType, AgentTypeString, PlanStatus, StepStatus, HumanFeedbackStatus } from './enums';
1+
import { AgentType, PlanStatus, StepStatus, HumanFeedbackStatus } from './enums';
22

33
/**
44
* Base interface with common fields
@@ -49,7 +49,7 @@ export interface Step extends BaseModel {
4949
/** Action to be performed */
5050
action: string;
5151
/** Agent assigned to this step */
52-
agent: AgentTypeString;
52+
agent: AgentType;
5353
/** Current status of the step */
5454
status: StepStatus;
5555
/** Optional reply from the agent */
@@ -107,7 +107,7 @@ export interface PlanWithSteps extends Plan {
107107
*/
108108
export interface ProcessedPlanData {
109109
plan: PlanWithSteps;
110-
agents: AgentTypeString[];
110+
agents: AgentType[];
111111
steps: Step[];
112112
hasClarificationRequest: boolean;
113113
hasClarificationResponse: boolean;

src/frontend/src/services/PlanDataService.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
PlanWithSteps,
33
Step,
44
AgentType,
5-
AgentTypeString,
65
ProcessedPlanData,
76
PlanMessage,
87
} from "@/models";
@@ -44,7 +43,7 @@ export class PlanDataService {
4443
messages: PlanMessage[]
4544
): ProcessedPlanData {
4645
// Extract unique agents from steps
47-
const uniqueAgents = new Set<AgentTypeString>();
46+
const uniqueAgents = new Set<AgentType>();
4847
plan.steps.forEach((step) => {
4948
if (step.agent) {
5049
uniqueAgents.add(step.agent);
@@ -86,7 +85,7 @@ export class PlanDataService {
8685
* @param agentType Agent type to filter by
8786
* @returns Array of steps for the specified agent
8887
*/
89-
static getStepsForAgent(plan: PlanWithSteps, agentType: AgentTypeString): Step[] {
88+
static getStepsForAgent(plan: PlanWithSteps, agentType: AgentType): Step[] {
9089
return apiService.getStepsForAgent(plan, agentType);
9190
}
9291

0 commit comments

Comments
 (0)