-
Notifications
You must be signed in to change notification settings - Fork 401
Configure exit policy of AgentValidationManager using a property #1801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
deleSerna
wants to merge
7
commits into
embabel:main
Choose a base branch
from
deleSerna:ghissue-1796
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6a59f2c
Add verification for AchievesGoal
deleSerna 98da41b
Moved back the void return type check as it should not stop the agent
deleSerna daa68e5
rebase
deleSerna 6612d00
Removed redundant spaces
deleSerna 2548855
Move agent structural errors behind a flag
deleSerna 471a188
update unit tests according to the property
deleSerna c9b9d65
Dont put the agentic check behind config property
deleSerna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...bel-agent-api/src/main/kotlin/com/embabel/agent/spi/validation/AchievableGoalValidator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package com.embabel.agent.spi.validation | ||
|
|
||
| import com.embabel.agent.api.annotation.AchievesGoal | ||
| import com.embabel.agent.core.AgentScope | ||
| import com.embabel.common.core.validation.ValidationError | ||
| import com.embabel.common.core.validation.ValidationErrorCodes | ||
| import com.embabel.common.core.validation.ValidationLocation | ||
| import com.embabel.common.core.validation.ValidationResult | ||
| import com.embabel.common.core.validation.ValidationSeverity | ||
| import org.slf4j.LoggerFactory | ||
| import org.springframework.util.ReflectionUtils | ||
| import java.lang.reflect.Method | ||
|
|
||
| /** | ||
| * Validator that checks methods annotated with AchievesGoal. | ||
| * | ||
| * Specific check includes: | ||
| * - Verifying that @Action annotation is present on it. | ||
| */ | ||
| open class AchievableGoalValidator ( private val agentName: String, | ||
| private val agentClass: Class<*>, | ||
| private val agentInstance: Any, | ||
| private val requireInterfaceDeserializationAnnotations: Boolean): AgentValidator | ||
| { | ||
| private val logger = LoggerFactory.getLogger(AchievableGoalValidator::class.java) | ||
|
|
||
| private fun isMethodAnnotatedWithAchievesGoal( | ||
| method: Method, | ||
| ): Boolean { | ||
| return method.isAnnotationPresent(AchievesGoal::class.java) | ||
| } | ||
|
|
||
| override fun validate(agentScope: AgentScope): ValidationResult { | ||
| val errors = mutableListOf<ValidationError>() | ||
| ReflectionUtils.doWithMethods( | ||
| agentClass, | ||
| { method -> | ||
| if(!isActionMethod(logger,method, agentClass, requireInterfaceDeserializationAnnotations)) { | ||
| errors.add( | ||
| ValidationError( | ||
| code = ValidationErrorCodes.MISSING_ACTION_ANNOTATION, | ||
| message = "@Action annotation is missing on the method '${agentInstance.javaClass.name}.${method.name}' annotated with @AchievesGoal.", | ||
| severity = ValidationSeverity.ERROR, | ||
| location = ValidationLocation( | ||
| type = "Agent", | ||
| name = agentInstance.javaClass.name, | ||
| agentName = agentName, | ||
| component = method.name | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
| }, | ||
| { method -> isMethodAnnotatedWithAchievesGoal(method) }) | ||
| return ValidationResult(errors.isEmpty(), errors) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igordayen Can you look into EmbabelMockitoIntegrationTestBlockingTest. It's failing because the it's not returning by default.
Looks likeAutoRegistration.kt can pick up any Bean and it's really depend on this check to not behind any condition.
Therefore, I am not putting return null behind property check.