Refactor Agent Input Validation to use AJV/JSON Schema
Problem
Currently, DelegateToAgentTool relies on a manual switch statement to map our custom InputConfig types to Zod validators. This approach is brittle, duplicates validation logic, and limits us to a small subset of JSON Schema features (blocking the use of enum, oneOf, nested objects, etc.).
Goal
Refactor the agent input system to use standard JSONSchema7 definitions and leverage our existing AJV-based SchemaValidator. This unifies validation logic across tools and agents.
Implementation Plan
1. Extend SchemaValidator
Update packages/core/src/utils/schemaValidator.ts to expose a schema validation method:
static validateSchema(schema: unknown): string | null {
if (!schema) return null;
const isValid = ajValidator.validateSchema(schema);
return isValid ? null : ajValidator.errorsText(ajValidator.errors);
}
2. Update Type Definitions
Replace the custom input mapping in packages/core/src/agents/types.ts with standard JSON Schema:
import type { JSONSchema7 } from 'json-schema';
export interface InputConfig {
/** Standard JSON Schema for validation and tool generation */
inputSchema: JSONSchema7;
}
3. Refactor DelegateToAgentTool
Remove the Zod mapping logic in packages/core/src/agents/delegate-to-agent-tool.ts. Instead, validate schemas at registration and merge them directly:
// Proposed logic
const agentSchemas = definitions.map((def) => {
const schemaError = SchemaValidator.validateSchema(def.inputConfig.inputSchema);
if (schemaError) throw new Error(`Invalid schema for ${def.name}: ${schemaError}`);
return {
type: 'object',
properties: {
agent_name: { const: def.name, description: def.description },
...def.inputConfig.inputSchema.properties,
},
required: ['agent_name', ...(def.inputConfig.inputSchema.required || [])],
};
});
Migration Checklist
- [ ] Add
validateSchematoSchemaValidator - [ ] Update
InputConfiginterface (consider temporary deprecation period for old format) - [ ] Refactor
DelegateToAgentToolto consume JSON Schema - [ ] Update
CodebaseInvestigatorAgentand other existing agents to the new schema format - [ ] Verify validation occurs at agent registration time
Hi , I will work on this.
This seems more complex than I expected. I'll pass on this one for now.
/assign
👋 @jonathanh1, you've been assigned to this issue! Thank you for taking the time to contribute. Make sure to check out our contributing guidelines.
@jonathanh1 and @psinha40898 , thank you for the PRs! Because this issue is on the critical path for a major feature, it makes sense for a maintainer to tackle it. My apologies for the churn.