Skip to content

[plan] Extract ResourceCache and PythonResourceBridge from AgentPlan#548

Open
weiqingy wants to merge 1 commit intoapache:mainfrom
weiqingy:issue_547
Open

[plan] Extract ResourceCache and PythonResourceBridge from AgentPlan#548
weiqingy wants to merge 1 commit intoapache:mainfrom
weiqingy:issue_547

Conversation

@weiqingy
Copy link
Collaborator

Linked issue: #547

Purpose of change

AgentPlan (624 lines) mixes plan definition, resource caching/resolution, Python bridge wiring, and serialization.
This PR extracts two classes to separate concerns:

  • ResourceCache — lazy resource resolution, caching, and cleanup. Created by the operator in open(), owned by
    the operator lifecycle.
  • PythonResourceBridge — static discoverPythonMCPResources() for Python MCP tool/prompt discovery. Called
    during operator init.

After extraction, AgentPlan becomes immutable after construction (~490 lines, down from 624). The removed public
methods are getResource(), close(), and setPythonResourceAdapter().

Tests

  • mvn test -pl plan — all plan module tests pass
  • mvn test -pl runtime — all runtime module tests pass
  • ./tools/lint.sh -c — formatting check passed
  • ./tools/ut.sh -j — full Java test suite passed

API

Yes. Three public methods removed from AgentPlan:

  • getResource(String, ResourceType) — replaced by ResourceCache.getResource()
  • close() — replaced by ResourceCache.close()
  • setPythonResourceAdapter(PythonResourceAdapter) — replaced by PythonResourceBridge.discoverPythonMCPResources()

Documentation

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

@github-actions github-actions bot added priority/major Default priority of the PR or issue. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. doc-not-needed Your PR changes do not impact docs labels Feb 22, 2026
@weiqingy
Copy link
Collaborator Author

Both CI failures are unrelated to our changes:

  1. it-python [flink-2.2] — Ollama download returned HTTP 404. This is a transient infrastructure issue — the Ollama release artifact was temporarily unavailable. Nothing to fix on our side.
  2. cross-language — Py4JError / Py4JNetworkError in the cross-language e2e tests. The Java gateway crashed during test_java_chat_model_integration and subsequent tests couldn't connect. Our PR only touches plan/ and runtime/ Java code — it doesn't affect the Python-Java bridge or cross-language e2e test infrastructure.

Copy link
Collaborator

@wenjin272 wenjin272 left a comment

Choose a reason for hiding this comment

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

Thanks for your work @weiqingy and I think the separation makes sense.

Besides, I think we should also apply this separation in the python side. If possible, could you implement this in this PR?

public class ResourceCache implements AutoCloseable {

private final Map<ResourceType, Map<String, ResourceProvider>> resourceProviders;
private final Map<ResourceType, Map<String, Resource>> cache = new HashMap<>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we use ConcurrentHashMap here? For task submit by ctx.durableExecuteAsync may read/write this hashmap parallel.

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

Labels

doc-not-needed Your PR changes do not impact docs 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants