Skip to content

[api][plan][runtime] Introduce AGENT resource type and sub-agent invocation API - #938

Open
pltbkd wants to merge 3 commits into
apache:mainfrom
pltbkd:subagent-framework
Open

[api][plan][runtime] Introduce AGENT resource type and sub-agent invocation API#938
pltbkd wants to merge 3 commits into
apache:mainfrom
pltbkd:subagent-framework

Conversation

@pltbkd

@pltbkd pltbkd commented Jul 29, 2026

Copy link
Copy Markdown

Design discussion: #909

Purpose of change

Introduces AGENT as a first-class resource type and the caller-facing sub-agent invocation API across Java / Python / YAML, per discussion #909.

SubagentSetup is the general sub-agent framework. This PR lands the framework and the one way to plug into it today: a custom SubagentSetup implementation. Registering an Agent directly as an internal sub-agent is a follow-up addition.

Included:

  • ResourceType.AGENT; register via addResource(name, AGENT, setup) and via YAML subagents:.
  • Subagent (caller interface) + SubagentSetup (base) + Result + BaseSubagentCallable (captures failures into Result).
  • call() / asAsyncCallable() run through durable execution; a deterministic (sessionId, callId) identity lets failover replay reuse cached results instead of re-invoking. Use asAsyncCallable() instead of callAsync() to support batch async execution.
  • sessionId is framework-generated and deterministic; callers may pass their own to continue a session. callId is auto-generated from the per-session conversation ordinal.

Evolved from the #909 proposal during review:

  • Result carries a serializable errorMessage (the failure's full stack trace) instead of a live Exception, so it survives durable persistence.
  • The durable id is derived solely from (sessionId, callId).

Notes

  • Follow-up additions: ChatModel calling sub-agents (sub-agent-as-tool dispatch), and internal sub-agent (registering an Agent directly as an AGENT resource, compiled into a scoped child plan, and its isolated execution).
  • Cross-language execution (an action calling a sub-agent implemented in the other language) is not supported yet; registration round-trips across the plan-JSON boundary, execution will be added later.
  • Timeout / cancellation semantics are not included yet; planned as a follow-up.
  • Result and the parallel async primitive (executeAllAsync) overlap with Parallel Tool Execution ([Feature] Parallel Tool Call Execution #926) and can be aligned/iterated during review.

Tests

  • Java unit: AGENT registration, plan compilation (SubagentSetup + YAML descriptor), and deterministic-id context / failover-recovery / operator-integration tests.
  • Python unit: mirrors the Java surface (registration, plan resources, id delegation).
  • e2e: ExternalSubagentTest — programmatic and YAML-declared sub-agent invocation (including failure surfaced via Result) on a real Flink job.

API

Additive public API, kept semantically aligned across Java / Python / YAML: ResourceType.AGENT, Subagent, SubagentSetup, Result, BaseSubagentCallable, RunnerContext#nextSessionId() / nextCallId(sessionId), and the YAML subagents: block.

No breaking changes to existing APIs.

Documentation

  • doc-needed but deferred: add once the internal sub-agent lands and the API stabilizes
  • doc-not-needed
  • doc-included

@pltbkd
pltbkd force-pushed the subagent-framework branch from 9356349 to 875b513 Compare July 29, 2026 16:13
@github-actions github-actions Bot added doc-needed Your PR changes impact docs. fixVersion/0.4.0 priority/major Default priority of the PR or issue. labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-needed Your PR changes impact docs. fixVersion/0.4.0 priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant