wenjin272 opened a new pull request, #1498: URL: https://github.com/apache/flink-agents/pull/1498
Closes #1355 ### Purpose of change External subagent implementations can now depend only on the API in Java and Python. Both deferred and async extensions work with direct await, tool dispatch, and gather without constructing runtime futures. #### Runtime flow A registered setup's `submit` delegates to `RunnerContext.submitSubagent` / `submit_subagent`. The active resource cache finds its runtime executor, which assigns missing IDs, invokes the setup's callbacks through durable execution, and returns a framework-owned future. The executor receives task lifecycle notifications and tracks unresolved calls. #### Key decisions - Put service callbacks and configuration in API bases; keep scheduling, recovery state, ID allocation, and handle bookkeeping in runtime executors. - Bind executors to setup identity in the owning resource scope. Child scopes can use ancestor resources, but cannot submit a setup owned by a sibling. - Keep `submit` framework-owned instead of accepting arbitrary futures that may work for direct await but fail during tool dispatch. - Compile Java external fixtures in a separate module with API as their only Flink Agents dependency; exercise them through full Flink jobs. ### Behavioral Semantics #### Interaction decisions | Mode | First execution | Recorded terminal outcome | Pending recovery | |---|---|---|---| | Deferred | Submit returns a handle; resolving it prepares and executes the call. | Reuse the recorded outcome without preparation. | Prepare again; use the supplied reconciler, or repeat the call. | | Async | Persist the submission before returning the polling handle. | Reuse recorded submission/result outcomes. | Reconcile submission; the default queries status and submits only for NOT_STARTED. | | Internal | Execute the child graph through the existing subgraph future. | Preserve existing subgraph replay. | Preserve existing subgraph recovery. | #### Behavioral contracts - External implementations import/compile without plan or runtime dependencies. - Deferred requests stay lazy; async submission completes before its handle is returned. - Recovery reuses terminal outcomes; uncertain submissions use reconciliation. - Direct await, tool dispatch, and mixed gather accept framework-created handles. - Missing IDs are assigned deterministically; a call ID requires a session ID. - Submission requires a registered setup visible from the active resource scope. - Resolving or cancelling a call releases its pending handle; finishing with an unresolved handle fails. #### Failure behavior Expected remote failures remain unsuccessful `SubagentResult` values. Callback exceptions propagate on direct calls; tool dispatch retains its existing error-response behavior. Framework and persistence failures propagate rather than becoming service results, and a failed pending-record write prevents preparation. Malformed callback return values are not coerced into successful results. Unsupported setup types, unregistered setups, invalid ID combinations, and invalid polling intervals fail explicitly. Deferred cancellation before resolution avoids the request; async cancellation invokes the optional service callback, whose default remains a no-op. Remote submission/cancellation callbacks must be idempotent; this change does not provide service-side deduplication. ### Tests | Contract | Coverage | |---|---| | API-only external implementations | Java external fixture module; Python `test_external_implementations_import_without_plan_or_runtime` | | Deferred versus async submission timing | `DeferredSubagentSubmitTest`, `BaseAsyncSubagentSetupTest`; Python deferred/async tests | | Terminal replay and pending recovery | `SubagentPreparationRecoveryTest`, `ExternalSubagentE2ETest`; Python await-cleanup and async tests | | Direct, tool, and mixed calls | `ExternalSubagentE2ETest`; Python external and ReAct subagent E2E tests | | ID allocation and validation | Java/Python `SubagentExecutorTest` / `test_subagent_executor.py` | | Resource scope ownership | Python executor lookup test and mixed child-scope E2E | | Cancellation and pending-handle cleanup | Java/Python deferred, async, and await-cleanup tests | Local validation: Java focused subagent tests and all 10 `ExternalSubagentE2ETest` cases passed. Python API/plan/runtime regression: 3044 passed, 18 skipped; 17 related Flink 2.3 E2E cases passed. After the Python base-class rename, 123 targeted tests including 13 E2E cases passed. Ruff and formatting checks passed. Not verified locally: the complete Flink-version matrix, production remote services, and Java 21 continuation-only cases skipped under Java 11. Python skips are excluded from the passed count. <details> <summary>Implementation invariants and verification details</summary> The dependency direction remains runtime → plan → api. Executors, rather than setup resources, receive lifecycle notifications. Python registers executors during eager materialization and adopts the current task namespace when an internal setup is first resolved mid-action. Python regression command: `pytest flink_agents/api flink_agents/plan flink_agents/runtime -q`, using the project virtual environment and its site-packages path in PYTHONPATH. E2E jobs used the rebuilt Flink 2.3 distribution JAR. Recovery tests cover preparation/persistence failures and terminal replay; full-job tests cover external service integration, tool dispatch, and mixed futures. </details> ### API Java extension bases move from `org.apache.flink.agents.runtime.subagent` to `org.apache.flink.agents.api.subagent`; callback overrides become public. Python extensions move to `flink_agents.api.subagent`, and `DeferredSubagentSetup` becomes `BaseDeferredSubagentSetup`. `RunStatus` moves with the async API. The old runtime `BaseSubagentSetup` extension hierarchy is removed. Custom submission/recovery hooks must use the API callbacks, including `prepare` and `reconcileSubmitRequest` / `reconcile_submit_request`. `submit` is final in Java and marked `@final` in Python. Existing registered call forms, result contracts, and polling configuration remain available. ### Documentation - [ ] `doc-needed` - [ ] `doc-not-needed` - [x] `doc-included` ### Was this patch authored or co-authored using generative AI tooling? - [x] Yes - [ ] No Generated-by: Codex CLI 0.153.4 (GPT-6) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
