| 112 | |
| 113 | // Simplified response format generator that matches the agent block schema structure |
| 114 | const generateResponseFormat = (metrics: Metric[]) => { |
| 115 | // Filter out invalid/incomplete metrics first |
| 116 | const validMetrics = metrics.filter((m) => m?.name) |
| 117 | |
| 118 | // Create properties for each metric |
| 119 | const properties: Record<string, any> = {} |
| 120 | |
| 121 | // Add each metric as a property |
| 122 | validMetrics.forEach((metric) => { |
| 123 | // We've already filtered, but double-check just in case |
| 124 | if (metric?.name) { |
| 125 | properties[metric.name.toLowerCase()] = { |
| 126 | type: 'number', |
| 127 | description: `${metric.description || ''} (Score between ${metric.range?.min ?? 0}-${metric.range?.max ?? 'N/A'})`, // Safely access range |
| 128 | } |
| 129 | } else { |
| 130 | logger.warn('Skipping invalid metric during response format property generation:', metric) |
| 131 | } |
| 132 | }) |
| 133 | |
| 134 | // Return a proper JSON Schema format |
| 135 | return { |
| 136 | name: 'evaluation_response', |
| 137 | schema: { |
| 138 | type: 'object', |
| 139 | properties, |
| 140 | // Use only valid, lowercase metric names for the required array |
| 141 | required: validMetrics |
| 142 | .filter((metric) => metric?.name) |
| 143 | .map((metric) => metric.name.toLowerCase()), |
| 144 | additionalProperties: false, |
| 145 | }, |
| 146 | strict: true, |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | export const EvaluatorBlock: BlockConfig<EvaluatorResponse> = { |
| 151 | type: 'evaluator', |