Resolve producer modes turn allowances cache controls and shared workers
This commit is contained in:
@@ -83,10 +83,8 @@ func validateDocumentPipelinePresence(document *Document, resolution *configkit.
|
||||
}
|
||||
|
||||
func validatePipelineDocumentPresence(profile PipelineDocument, path configkit.Path, resolution *configkit.Resolution) {
|
||||
validateDocumentControls(profile.Mode, profile.MaxAdditionalTurns, profile.Cache, path, validation)
|
||||
rejectDocumentNull(resolution, path.Key("llm_profile"), profile.LLMProfile == nil)
|
||||
rejectDocumentNull(resolution, path.Key("structured_output_repair_attempts"), profile.StructuredOutputRepairAttempts == nil)
|
||||
rejectDocumentNull(resolution, path.Key("validation_policy"), profile.ValidationPolicy == nil)
|
||||
validateDocumentPolicyPresence(profile.ValidationPolicy, path.Key("validation_policy"), resolution)
|
||||
|
||||
stepsPath := path.Key("steps")
|
||||
if resolution.IsExplicit(stepsPath) && profile.Steps == nil {
|
||||
@@ -136,9 +134,6 @@ func validateOptionalBindingDocumentPresence(binding *BindingDocument, path conf
|
||||
|
||||
func validateBindingDocumentPresence(binding BindingDocument, path configkit.Path, resolution *configkit.Resolution) {
|
||||
rejectDocumentNull(resolution, path.Key("llm_profile"), binding.LLMProfile == nil)
|
||||
rejectDocumentNull(resolution, path.Key("structured_output_repair_attempts"), binding.StructuredOutputRepairAttempts == nil)
|
||||
rejectDocumentNull(resolution, path.Key("validation_policy"), binding.ValidationPolicy == nil)
|
||||
validateDocumentPolicyPresence(binding.ValidationPolicy, path.Key("validation_policy"), resolution)
|
||||
if binding.Validators == nil && resolution.IsExplicit(path.Key("validators")) {
|
||||
resolution.Error(path.Key("validators"), "must not be null")
|
||||
}
|
||||
@@ -146,7 +141,6 @@ func validateBindingDocumentPresence(binding BindingDocument, path configkit.Pat
|
||||
for index, validator := range binding.Validators {
|
||||
validatorPath := path.Key("validators").Index(index)
|
||||
rejectDocumentNull(resolution, validatorPath.Key("llm_profile"), validator.LLMProfile == nil)
|
||||
rejectDocumentNull(resolution, validatorPath.Key("structured_output_repair_attempts"), validator.StructuredOutputRepairAttempts == nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,16 +159,8 @@ func rejectDocumentNull(resolution *configkit.Resolution, path configkit.Path, i
|
||||
}
|
||||
}
|
||||
|
||||
func validateDocumentPolicyPresence(policy *ValidationPolicyDocument, path configkit.Path, resolution *configkit.Resolution) {
|
||||
if policy == nil {
|
||||
return
|
||||
}
|
||||
rejectDocumentNull(resolution, path.Key("producer_structural_failure"), policy.ProducerStructuralFailure == nil)
|
||||
rejectDocumentNull(resolution, path.Key("semantic_rejection"), policy.SemanticRejection == nil)
|
||||
rejectDocumentNull(resolution, path.Key("validator_failure"), policy.ValidatorFailure == nil)
|
||||
}
|
||||
|
||||
func normalizePipelineDocument(profile *PipelineDocument, path configkit.Path, resolution documentNormalizer, state *documentLoadState) {
|
||||
normalizeDocumentControls(&profile.Mode, &profile.Cache, path, resolution)
|
||||
normalizePipelineDocumentString(resolution, path.Key("llm_profile"), &profile.LLMProfile, "trimmed pipeline LLM profile")
|
||||
normalizeDocumentBinding(&profile.Input, path.Key("input"), resolution, state)
|
||||
if profile.Chunk != nil {
|
||||
@@ -220,6 +206,7 @@ func normalizeArtifactLaneDocument(lane *ArtifactLaneDocument, path configkit.Pa
|
||||
}
|
||||
|
||||
func normalizeDocumentBinding(binding *BindingDocument, path configkit.Path, resolution documentNormalizer, state *documentLoadState) {
|
||||
normalizeDocumentControls(&binding.Mode, &binding.Cache, path, resolution)
|
||||
normalizeDocumentValue(resolution, path.Key("module"), &binding.Module, strings.TrimSpace(binding.Module), "trimmed module identifier")
|
||||
normalizePipelineDocumentString(resolution, path.Key("llm_profile"), &binding.LLMProfile, "trimmed binding LLM profile")
|
||||
binding.References = normalizeDocumentReferences(binding.References, path.Key("references"), resolution, state)
|
||||
@@ -329,8 +316,6 @@ func validateDocumentPipelines(document *Document, validation *configkit.Validat
|
||||
|
||||
func validatePipelineDocument(profile PipelineDocument, path configkit.Path, validation *configkit.Validation) {
|
||||
validateSelectedDocumentProfile(profile.LLMProfile, path.Key("llm_profile"), validation)
|
||||
validateDocumentRepairAttempts(profile.StructuredOutputRepairAttempts, path.Key("structured_output_repair_attempts"), validation)
|
||||
validateDocumentPolicy(profile.ValidationPolicy, path.Key("validation_policy"), validation)
|
||||
validateDocumentBinding(profile.Input, path.Key("input"), "input", false, false, validation)
|
||||
if profile.Chunk != nil {
|
||||
validateDocumentBinding(*profile.Chunk, path.Key("chunk"), "chunk", true, true, validation)
|
||||
@@ -383,20 +368,12 @@ func validateDocumentLanes(lanes map[string]ArtifactLaneDocument, path configkit
|
||||
}
|
||||
|
||||
func validateDocumentBinding(binding BindingDocument, path configkit.Path, slot string, referencesAllowed, validatorsAllowed bool, validation *configkit.Validation) {
|
||||
validateDocumentControls(binding.Mode, binding.MaxAdditionalTurns, binding.Cache, path, validation)
|
||||
if strings.TrimSpace(binding.Module) == "" {
|
||||
validation.Error(path.Key("module"), "must not be empty")
|
||||
}
|
||||
validateSelectedDocumentProfile(binding.LLMProfile, path.Key("llm_profile"), validation)
|
||||
validateDocumentRepairAttempts(binding.StructuredOutputRepairAttempts, path.Key("structured_output_repair_attempts"), validation)
|
||||
if binding.Retries < 0 {
|
||||
validation.Error(path.Key("retries"), "must be greater than or equal to zero")
|
||||
}
|
||||
if binding.ValidationPolicy != nil {
|
||||
if slot != "chunk" && slot != "extract" && slot != "merge" && slot != "normalize" {
|
||||
validation.Error(path.Key("validation_policy"), "is not supported for this binding")
|
||||
}
|
||||
validateDocumentPolicy(binding.ValidationPolicy, path.Key("validation_policy"), validation)
|
||||
}
|
||||
|
||||
if len(binding.References) > 0 && !referencesAllowed {
|
||||
validation.Error(path.Key("references"), "are not supported for this binding")
|
||||
}
|
||||
@@ -416,10 +393,7 @@ func validateValidatorDocument(validator ValidatorDocument, path configkit.Path,
|
||||
validation.Error(path.Key("module"), "must not be empty")
|
||||
}
|
||||
validateSelectedDocumentProfile(validator.LLMProfile, path.Key("llm_profile"), validation)
|
||||
validateDocumentRepairAttempts(validator.StructuredOutputRepairAttempts, path.Key("structured_output_repair_attempts"), validation)
|
||||
if validator.Retries < 0 {
|
||||
validation.Error(path.Key("retries"), "must be greater than or equal to zero")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func validateDocumentReferences(references map[string]ReferenceDocument, path configkit.Path, generatedAllowed bool, validation *configkit.Validation) {
|
||||
@@ -457,39 +431,6 @@ func validateSelectedDocumentProfile(value *string, path configkit.Path, validat
|
||||
}
|
||||
}
|
||||
|
||||
func validateDocumentRepairAttempts(value *int, path configkit.Path, validation *configkit.Validation) {
|
||||
if value != nil && (*value < 0 || *value > 3) {
|
||||
validation.Error(path, "must be between zero and three")
|
||||
}
|
||||
}
|
||||
|
||||
func validateDocumentPolicy(policy *ValidationPolicyDocument, path configkit.Path, validation *configkit.Validation) {
|
||||
if policy == nil {
|
||||
return
|
||||
}
|
||||
if policy.ProducerStructuralFailure != nil {
|
||||
switch *policy.ProducerStructuralFailure {
|
||||
case pipeline.ProducerStructuralFailureFailRun, pipeline.ProducerStructuralFailureRejectOutput:
|
||||
default:
|
||||
validation.Error(path.Key("producer_structural_failure"), "must be fail_run or reject_output")
|
||||
}
|
||||
}
|
||||
if policy.SemanticRejection != nil {
|
||||
switch *policy.SemanticRejection {
|
||||
case pipeline.SemanticRejectionFailRun, pipeline.SemanticRejectionRejectOutput:
|
||||
default:
|
||||
validation.Error(path.Key("semantic_rejection"), "must be fail_run or reject_output")
|
||||
}
|
||||
}
|
||||
if policy.ValidatorFailure != nil {
|
||||
switch *policy.ValidatorFailure {
|
||||
case pipeline.ValidatorFailureWarnContinue, pipeline.ValidatorFailureFailRun:
|
||||
default:
|
||||
validation.Error(path.Key("validator_failure"), "must be warn_continue or fail_run")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sortedPipelineDocumentKeys(values map[string]PipelineDocument) []string {
|
||||
return sortedDocumentKeys(values)
|
||||
}
|
||||
@@ -508,3 +449,32 @@ func sortedDocumentKeys[T any](values map[string]T) []string {
|
||||
sort.Strings(keys)
|
||||
return keys
|
||||
}
|
||||
func normalizeDocumentControls(mode **pipeline.ExecutionMode, cache **pipeline.CacheMode, path configkit.Path, resolution documentNormalizer) {
|
||||
if *mode != nil {
|
||||
value := pipeline.ExecutionMode(strings.TrimSpace(string(**mode)))
|
||||
if **mode != value {
|
||||
normalizeDocumentValue(resolution, path.Key("mode"), mode, &value, "trimmed execution mode")
|
||||
}
|
||||
}
|
||||
if *cache != nil {
|
||||
value := pipeline.CacheMode(strings.TrimSpace(string(**cache)))
|
||||
if **cache != value {
|
||||
normalizeDocumentValue(resolution, path.Key("cache"), cache, &value, "trimmed cache mode")
|
||||
}
|
||||
}
|
||||
}
|
||||
func validateDocumentControls(mode *pipeline.ExecutionMode, turns *int, cache *pipeline.CacheMode, path configkit.Path, validation *configkit.Validation) {
|
||||
if mode != nil {
|
||||
if _, err := pipeline.ParseExecutionMode(string(*mode)); err != nil {
|
||||
validation.Error(path.Key("mode"), err.Error())
|
||||
}
|
||||
}
|
||||
if cache != nil {
|
||||
if _, err := pipeline.ParseCacheMode(string(*cache)); err != nil {
|
||||
validation.Error(path.Key("cache"), err.Error())
|
||||
}
|
||||
}
|
||||
if turns != nil && *turns < 0 {
|
||||
validation.Error(path.Key("max_additional_turns"), "must not be negative")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user