eemario commented on code in PR #1444:
URL: https://github.com/apache/flink-agents/pull/1444#discussion_r4690585061
##########
python/flink_agents/plan/routing/validation.py:
##########
@@ -55,15 +56,33 @@ def custom_executor_class(path: str) ->
tuple[type[CustomRoutingExecutor], bool]
def validate_routing(
providers: dict[ResourceType, dict[str, ResourceProvider]],
+ *,
+ allow_java: bool = False,
) -> None:
- """Validate native Python routers after local and shared resources
merge."""
- for name, provider in providers.get(ResourceType.MODEL_ROUTER, {}).items():
+ """Validate native Python routers and name the router resource they
provide.
+
+ Runs when a plan is built and when one is restored, so a descriptor
written by
+ hand, loaded from YAML or read from a serialized plan meets the same
checks as
+ one built with ``ModelRouter.of(...)``. Each declaration is then provided
as
+ ``flink_agents.plan.routing.model_router.ModelRouter``, which only decodes
it.
+ ``allow_java`` keeps the Java routers of a restored Java plan, which the
Java
+ plan validates and Python never provides.
+ """
+ routers = providers.get(ResourceType.MODEL_ROUTER, {})
+ for name, provider in list(routers.items()):
check_model_name_collision(name, ResourceType.MODEL_ROUTER, providers)
if not isinstance(provider, PythonResourceProvider):
+ if allow_java:
+ continue
msg = (
f"Model router '{name}' must use a Python descriptor in a
Python agent."
)
raise TypeError(msg)
- router = ModelRouter(**provider.descriptor.arguments)
- if router.strategy.type == RoutingStrategyType.CUSTOM:
- custom_executor_class(router.strategy.executor_class)
+ declaration = RouterDeclaration(**provider.descriptor.arguments)
Review Comment:
Could we check that the effective `default_model` is still a candidate after
the provider applies `ModelRouter.*` configuration? I tried declaring
`ModelRouter.of("small").strategy(Strategies.rules({})).build()` and setting
`agent.ModelRouter.default_model: outside` in `config.yaml`.
On the base commit, creating the router raises a `ValidationError` with “The
default model must be a candidate.” On this branch, the descriptor passes
validation here because it has no explicit `default_model`. The provider then
fills in `outside` from configuration, and a request with no matching rule
selects `outside` even though `small` is the only declared candidate.
Would it make sense to add a regression test for this configuration path so
the candidate check also covers the settings used at runtime?
--
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]