Skip to content

[api][test] Simplify cross-language Java action declaration and add e2e coverage#827

Merged
wenjin272 merged 3 commits into
apache:mainfrom
wenjin272:polish-cro-action
Jun 10, 2026
Merged

[api][test] Simplify cross-language Java action declaration and add e2e coverage#827
wenjin272 merged 3 commits into
apache:mainfrom
wenjin272:polish-cro-action

Conversation

@wenjin272

@wenjin272 wenjin272 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Purpose of change

  • Action signatures are fixed (Event, RunnerContext), but the Python API forced callers to spell out parameter_types when declaring a Java action, while the YAML API auto-fills them. Add JavaFunction.for_action() to fill the fixed signature, share the ACTION_PARAMETER_TYPES constant with the YAML loader, and simplify the cross-language example. Tools keep explicit parameter_types since their signatures vary.
  • The cross-language YAML e2e only covered Java resources/tools. Cover the action path: a basic YAML-declared Java action (multiplyByTwo, no parameter_types written — guards the loader auto-fill), plus orchestration actions in the other language bridged by the host-native built-in chat loop with a cross-language tool — Python host + Java actions and Java host + Python actions. Reuses existing handlers; only YAML + tests are new. Ollama/test-jar skips as before.

Tests

API

Documentation

  • doc-needed
  • doc-not-needed
  • doc-included

wenjin272 and others added 2 commits June 10, 2026 11:32
…ions

Action signatures are fixed (Event, RunnerContext), but the Python API
forced callers to spell out parameter_types when declaring a Java action,
while the YAML API auto-fills them. Add JavaFunction.for_action() to fill
the fixed signature, share the ACTION_PARAMETER_TYPES constant with the
YAML loader, and simplify the cross-language example. Tools keep explicit
parameter_types since their signatures vary.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The cross-language YAML e2e only covered Java resources/tools. Cover the
action path: a basic YAML-declared Java action (multiplyByTwo, no
parameter_types written — guards the loader auto-fill), plus orchestration
actions in the other language bridged by the host-native built-in chat loop
with a cross-language tool — Python host + Java actions and Java host +
Python actions. Reuses existing handlers; only YAML + tests are new.
Ollama/test-jar skips as before.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added doc-included Your PR already contains the necessary documentation updates. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/major Default priority of the PR or issue. labels Jun 10, 2026
@wenjin272 wenjin272 self-assigned this Jun 10, 2026
@github-actions github-actions Bot added doc-included Your PR already contains the necessary documentation updates. and removed doc-included Your PR already contains the necessary documentation updates. labels Jun 10, 2026
@wenjin272 wenjin272 requested a review from wzhero1 June 10, 2026 03:38
@wenjin272 wenjin272 added priority/blocker Indicates the PR or issue that should block the release until it gets resolved. and removed priority/major Default priority of the PR or issue. labels Jun 10, 2026

@wzhero1 wzhero1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall — clean refactor + solid e2e coverage. One minor nit.

Comment thread python/flink_agents/api/function.py Outdated

#: Java parameter types of an action method. Action signatures are fixed
#: ``(Event, RunnerContext)``, so callers never have to spell them out.
ACTION_PARAMETER_TYPES: List[str] = [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this constant is never meant to be mutated — a tuple makes the contract enforceable at the language level:

ACTION_PARAMETER_TYPES: Tuple[str, ...] = (
    "org.apache.flink.agents.api.Event",
    "org.apache.flink.agents.api.context.RunnerContext",
)

for_action() already defensively copies with list(...), and pydantic v2 coerces sequences into List[str] on model creation, so all existing call sites (including the YAML loader at _resolve_action_function) would work unchanged. The only difference is that a stray .append() or [0] = ... would raise TypeError instead of silently corrupting every downstream caller in the process.

A tuple enforces the no-mutation contract at the language level; for_action
already copies into a list and pydantic coerces sequences to List[str], so all
call sites (incl. the YAML loader) are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wenjin272 wenjin272 merged commit ed04111 into apache:main Jun 10, 2026
25 checks passed

@weiqingy weiqingy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on — lifting the fixed action signature into one shared immutable ACTION_PARAMETER_TYPES tuple, consumed by both for_action and the YAML loader, is a clean single-source-of-truth move that also closes the shared-default-mutation footgun before it can exist. Reads as ready to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-included Your PR already contains the necessary documentation updates. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/blocker Indicates the PR or issue that should block the release until it gets resolved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants