Add support for arrays in schema

This commit is contained in:
Waleed Latif
2025-02-07 13:30:29 -08:00
parent 01d2a8acd5
commit 893954dd71
2 changed files with 50 additions and 11 deletions

View File

@@ -75,24 +75,52 @@ export const AgentBlock: BlockConfig<AgentResponse> = {
properties: {
name: {
type: 'string',
minLength: 1,
description: 'Name of the field',
},
type: {
type: 'string',
enum: ['string', 'number', 'boolean', 'array', 'object'],
description: 'Type of the field',
},
isArray: {
type: 'boolean',
description: 'Whether this field contains multiple values',
},
items: {
type: 'object',
description: 'Schema for array items (required when isArray is true)',
properties: {
type: {
type: 'string',
enum: ['string', 'number', 'boolean', 'object'],
},
properties: {
type: 'array',
items: {
type: 'object',
properties: {
name: { type: 'string' },
type: {
type: 'string',
enum: ['string', 'number', 'boolean'],
},
},
required: ['name', 'type'],
},
},
},
},
description: {
type: 'string',
description: 'Description of what this field represents',
},
},
required: ['name', 'type'],
additionalProperties: false,
},
minItems: 1,
},
},
required: ['fields'],
additionalProperties: false,
},
},
temperature: { type: 'number', required: false },

View File

@@ -296,7 +296,9 @@ export class Executor {
const response = await executeProviderRequest(providerId, {
model,
systemPrompt: inputs.systemPrompt,
context: inputs.context,
context: Array.isArray(inputs.context)
? JSON.stringify(inputs.context, null, 2)
: inputs.context,
tools: tools.length > 0 ? tools : undefined,
temperature: inputs.temperature,
maxTokens: inputs.maxTokens,
@@ -512,13 +514,22 @@ export class Executor {
// If a valid leaf is found
if (replacementValue !== undefined) {
// Replace the placeholder in the string
resolvedValue = resolvedValue.replace(
match,
typeof replacementValue === 'object'
? JSON.stringify(replacementValue)
: String(replacementValue)
)
// Special handling for context field to ensure proper formatting
if (key === 'context') {
// If it's not a string, stringify it for context
resolvedValue =
typeof replacementValue === 'string'
? replacementValue
: JSON.stringify(replacementValue, null, 2)
} else {
// For all other fields, use existing logic
resolvedValue = resolvedValue.replace(
match,
typeof replacementValue === 'object'
? JSON.stringify(replacementValue)
: String(replacementValue)
)
}
} else {
throw new Error(
`No value found at path "${path}" in block "${sourceBlock.metadata?.title}".`