Skip to content

Commit ec30c55

Browse files
authored
fix(tools): separate tools job (#222)
1 parent 7cb333f commit ec30c55

File tree

3 files changed

+13
-84
lines changed

3 files changed

+13
-84
lines changed

packages/agent/src/agents/operators/supervisor/tools/createAgentTool.ts

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { DynamicStructuredTool } from '@langchain/core/tools';
22
import {
33
AgentConfig,
4-
McpServerConfig,
54
logger,
65
validateAgent,
76
validateAgentQuotas,
@@ -29,7 +28,7 @@ export function createAgentTool(
2928
return new DynamicStructuredTool({
3029
name: 'create_agent',
3130
description:
32-
'Create/add/make a new agent configuration for a specific user. Provide the agent profile (name, group, description) and optional configuration overrides for graph, memory, rag, plugins, mcp_servers, and prompts.',
31+
'Create a new agent configuration with default settings. Only accepts agent profile (name, group, description, contexts). All other configuration (graph, memory, rag, mcp_servers) will use default values. To modify configuration after creation, use update_agent tool.',
3332
schema: CreateAgentSchema,
3433
func: async (rawInput) => {
3534
let input: CreateAgentInput;
@@ -105,10 +104,8 @@ export function createAgentTool(
105104
notes.push(nameNote);
106105
}
107106

108-
const { id: promptId, created: promptsCreated } = await ensurePromptsId(
109-
userId,
110-
input.prompts_id
111-
);
107+
const { id: promptId, created: promptsCreated } =
108+
await ensurePromptsId(userId);
112109
if (promptsCreated) {
113110
notes.push('Default prompts initialized for the user.');
114111
}
@@ -159,52 +156,15 @@ export function createAgentTool(
159156
}
160157

161158
function buildAgentConfigFromInput(input: CreateAgentInput): AgentConfig.Input {
162-
// Build partial config from input - normalizeNumericValues will handle the rest
163-
const partialConfig: Partial<AgentConfig.Input> = {};
164-
165-
// Only add properties that are actually provided
166-
if (input.profile) {
167-
partialConfig.profile = {
159+
// Build partial config from input - only profile and prompts_id are allowed
160+
const partialConfig: Partial<AgentConfig.Input> = {
161+
profile: {
168162
name: input.profile.name.trim(),
169163
group: input.profile.group.trim(),
170164
description: input.profile.description.trim(),
171165
contexts: input.profile.contexts || [],
172-
};
173-
}
174-
175-
if (input.mcp_servers) {
176-
// Convert array to Record<string, McpServerConfig>
177-
const mcpServersRecord: Record<string, McpServerConfig> = {};
178-
for (const server of input.mcp_servers) {
179-
const { name, env, ...serverConfig } = server;
180-
181-
// Convert env array to Record<string, string>
182-
let envRecord: Record<string, string> | undefined;
183-
if (env && Array.isArray(env)) {
184-
envRecord = {};
185-
for (const envEntry of env) {
186-
envRecord[envEntry.name] = envEntry.value;
187-
}
188-
}
189-
190-
mcpServersRecord[name] = {
191-
...serverConfig,
192-
...(envRecord && { env: envRecord }),
193-
};
194-
}
195-
196-
partialConfig.mcp_servers = parseMcpServers(mcpServersRecord, {});
197-
}
198-
199-
if (input.graph)
200-
partialConfig.graph = input.graph as AgentConfig.Input['graph'];
201-
202-
if (input.memory)
203-
partialConfig.memory = input.memory as AgentConfig.Input['memory'];
204-
205-
if (input.rag) partialConfig.rag = input.rag;
206-
207-
if (input.prompts_id) partialConfig.prompts_id = input.prompts_id;
166+
},
167+
};
208168

209169
// Apply normalization using the centralized function - it handles all defaults and validation
210170
const { normalizedConfig, appliedDefaults } =
@@ -220,16 +180,6 @@ function buildAgentConfigFromInput(input: CreateAgentInput): AgentConfig.Input {
220180
return normalizedConfig;
221181
}
222182

223-
function parseMcpServers(
224-
value: Record<string, McpServerConfig> | undefined,
225-
fallback: Record<string, McpServerConfig>
226-
): Record<string, McpServerConfig> {
227-
if (value && typeof value === 'object' && !Array.isArray(value)) {
228-
return value;
229-
}
230-
return { ...fallback };
231-
}
232-
233183
async function resolveUniqueAgentName(
234184
baseName: string,
235185
group: string,

packages/agent/src/agents/operators/supervisor/tools/schemas/createAgent.schema.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
import { z } from 'zod';
2-
import {
3-
AgentProfileSchema,
4-
GraphConfigSchema,
5-
MemoryConfigSchema,
6-
RAGConfigSchema,
7-
McpServersArraySchema,
8-
} from './common.schemas.js';
2+
import { AgentProfileSchema } from './common.schemas.js';
93

10-
// Main schema for creating an agent (profile required, other fields optional)
4+
// Main schema for creating an agent (only profile and prompts_id allowed)
115
export const CreateAgentSchema = z
126
.object({
13-
profile: AgentProfileSchema.describe('Agent profile configuration'),
14-
mcp_servers: McpServersArraySchema.optional().describe(
15-
'MCP servers configuration'
7+
profile: AgentProfileSchema.describe(
8+
'Agent profile configuration (required)'
169
),
17-
memory: MemoryConfigSchema.optional().describe('Memory configuration'),
18-
rag: RAGConfigSchema.optional().describe('RAG configuration'),
19-
prompts_id: z
20-
.string()
21-
.uuid()
22-
.optional()
23-
.describe('Existing prompts configuration identifier'),
24-
graph: GraphConfigSchema.optional().describe('Graph configuration'),
2510
})
2611
.strict();
2712

packages/agent/src/agents/operators/supervisor/tools/schemas/updateAgent.schema.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@ import {
44
GraphConfigSchema,
55
MemoryConfigSchema,
66
RAGConfigSchema,
7-
McpServerConfigSchema,
87
SelectAgentSchema,
9-
McpServersArraySchema,
108
} from './common.schemas.js';
11-
import { getGuardValue } from '@snakagent/core';
129

13-
const maxMcpServer = getGuardValue('agents.mcp_servers.max_servers');
1410
// Schema for update agent - allows partial updates with nullable fields
11+
// Note: mcp_servers is NOT included here - use add_mcp_server, update_mcp_server, or remove_mcp_server tools instead
1512
export const UpdateAgentSchema = SelectAgentSchema.extend({
1613
updates: z
1714
.object({
1815
profile: AgentProfileSchema.partial()
1916
.optional()
2017
.describe('Agent profile configuration (partial)'),
21-
mcp_servers: McpServersArraySchema.optional().describe(
22-
'MCP servers configuration'
23-
),
2418
memory: MemoryConfigSchema.optional().describe('Memory configuration'),
2519
rag: RAGConfigSchema.optional().describe('RAG configuration'),
2620
prompts_id: z

0 commit comments

Comments
 (0)