Skip to content

[Tech Debt] Refactor AgentPlan & ResourceCache #547

@weiqingy

Description

@weiqingy

Search before asking

  • I searched in the issues and found nothing similar.

Description

AgentPlan (624 lines) mixes plan definition, resource caching/resolution, Python bridge wiring, and serialization
into one class. This makes the plan mutable after construction, prevents testing resource resolution independently,
and couples Python MCP discovery logic to the plan definition.

What is currently not ideal?

  • AgentPlan is mutable after construction — setPythonResourceAdapter() writes to the transient resourceCache
  • Resource resolution (getResource()) and cleanup (close()) are runtime concerns living on a serializable plan
    object
  • Python MCP tool/prompt discovery is entangled with the plan — AgentPlan directly references PythonMCPServer,
    PythonResourceAdapter
  • Cannot test resource resolution without constructing a full AgentPlan
  • Blocks runtime MCP reloading — the plan owns the cache, so refreshing tools requires mutating the plan

How should it be fixed?

Extract two classes:

  1. ResourceCache (~80 lines) — Lazy resource resolution, caching, dependency injection, and close/cleanup.
    Created by the operator in open(), owned by the operator lifecycle.
  2. PythonResourceBridge (~55 lines) — Static method that discovers tools/prompts from Python MCP servers and
    registers them in the cache. Called from ActionExecutionOperator.initPythonResourceAdapter().

After extraction, AgentPlan becomes an immutable data object (~490 lines) holding actions, resource providers, and
config. The removed public methods are getResource(), close(), and setPythonResourceAdapter().

Files affected

  • plan/.../AgentPlan.java — remove extracted methods and transient fields
  • plan/.../ResourceCache.javanew
  • plan/.../PythonResourceBridge.javanew
  • runtime/.../RunnerContextImpl.java — delegate to ResourceCache instead of AgentPlan
  • runtime/.../JavaRunnerContextImpl.java — constructor change
  • runtime/.../PythonRunnerContextImpl.java — constructor change
  • runtime/.../ActionExecutionOperator.java — create and own ResourceCache
  • 6 test files updated to use ResourceCache directly

References

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

Labels

priority/majorDefault priority of the PR or issue.tech debt[Issue Type] User-unaware issues, such as code refactor and infrastructure maintenance.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions