-
Notifications
You must be signed in to change notification settings - Fork 136
[python] warn when an action declares a return value #835
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
vishnuprakaz
wants to merge
1
commit into
apache:main
Choose a base branch
from
vishnuprakaz:warn-action-return-value
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.
+47
−2
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -15,7 +15,9 @@ | |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| ################################################################################# | ||
| from typing import TYPE_CHECKING, Any, Dict, List, cast | ||
| import inspect | ||
| import logging | ||
| from typing import TYPE_CHECKING, Any, Callable, Dict, List, cast | ||
|
|
||
| from pydantic import BaseModel, field_serializer, model_validator | ||
|
|
||
|
|
@@ -56,6 +58,8 @@ | |
| ) | ||
| from flink_agents.integrations.mcp.mcp import MCPServer | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| BUILT_IN_ACTIONS = [CHAT_MODEL_ACTION, TOOL_CALL_ACTION, CONTEXT_RETRIEVAL_ACTION] | ||
|
|
||
|
|
||
|
|
@@ -248,6 +252,16 @@ def _action_marker(value: Any) -> tuple | None: | |
| return inner, marker._listen_events, getattr(marker, "_target", None) | ||
|
|
||
|
|
||
| def _warn_if_action_returns_value(name: str, func: Callable) -> None: | ||
| """Warn if an action declares a non-None return type; its value is ignored.""" | ||
| return_annotation = inspect.signature(func).return_annotation | ||
| if return_annotation not in (inspect.Signature.empty, None, type(None), "None"): | ||
| logger.warning( | ||
| f"Action '{name}' declares return type '{return_annotation}', but action " | ||
| f"return values are ignored; use ctx.send_event(...) instead." | ||
| ) | ||
|
|
||
|
|
||
| def _get_actions(agent: Agent) -> List[Action]: | ||
| """Extract all registered agent actions from an agent. | ||
|
|
||
|
|
@@ -280,6 +294,8 @@ def _get_actions(agent: Agent) -> List[Action]: | |
| if marker is None: | ||
| continue | ||
| inner, listen_events, target = marker | ||
| if target is None: | ||
| _warn_if_action_returns_value(name, inner) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can move this validation to the initialize function of |
||
| exec_ = ( | ||
| _to_plan_function(target) | ||
| if target is not None | ||
|
|
||
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
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.
The warning fires for
@action-decorated methods here, but actions registered imperatively viaadd_action(name, events, func)flow through theagent.actionsloop below (around line 311) and skip this check — so a plain Python callable with-> strpassed toadd_actionhits the same silent-discard trap with no warning. Issue #834 scopes this to decorated methods, so this may be deliberate — is covering theadd_actionpath worth a follow-up, or intentionally out of scope?