Sxnan commented on code in PR #854:
URL: https://github.com/apache/flink-agents/pull/854#discussion_r3510361547


##########
python/flink_agents/plan/tools/function_tool.py:
##########
@@ -40,11 +46,28 @@ class FunctionTool(Tool):
     """
 
     func: PythonFunction | JavaFunction
+    injected_args: dict[str, InjectedArg] = Field(default_factory=dict)
+
+    @model_validator(mode="before")
+    @classmethod
+    def _normalize_injected_args(cls, data: dict) -> dict:
+        if isinstance(data, dict) and "injected_args" in data:
+            data = dict(data)
+            data["injected_args"] = 
normalize_injected_args(data["injected_args"])
+        return data
 
     @model_validator(mode="after")
     def _eager_derive_python_metadata(self) -> "FunctionTool":
+        if isinstance(self.func, PythonFunction):
+            callable_ = self.func.as_callable()
+            self.injected_args = merge_injected_args(
+                getattr(callable_, "_injected_args", None),
+                self.injected_args,
+                tool_name=callable_.__qualname__,
+            )
+            validate_injected_arg_names(callable_, self.injected_args)
         if self.metadata is None and isinstance(self.func, PythonFunction):
-            self.metadata = _python_metadata(self.func)
+            self.metadata = _python_metadata(self.func, 
list(self.injected_args))

Review Comment:
   The `PythonFunction` path here passes `list(self.injected_args)` into the 
schema derivation — but the `JavaFunction` path below 
(`set_java_resource_adapter` → `_java_metadata(self.func)`) drops 
`self.injected_args` entirely. For a `type: java` tool whose `injected_args` 
are declared only in YAML (loader `_build_tool` does store them on this 
FunctionTool), `_java_metadata` → `JavaResourceAdapter.getJavaToolMetadata` 
ends up calling the no-injected-args overload 
`ToolMetadataFactory.fromStaticMethod(method)`, so the injected param leaks 
into the model-facing schema unless the Java method also has 
`@ToolParam(injected = true)`. Execution-time injection still works, so this is 
a schema leak, not a broken call. The injected-aware overload 
`fromStaticMethod(method, names)` already exists — threading the names through 
`_java_metadata` and `getJavaToolMetadata` closes the gap (the reverse bridge 
already does this via `getInjectedArgNames()`).



##########
python/flink_agents/runtime/python_java_utils.py:
##########
@@ -149,7 +151,9 @@ def get_python_tool_metadata(module: str, qual_name: str) 
-> Dict[str, str]:
     callable_ = descriptor.as_callable()
     name = callable_.__name__
     description = (parse(callable_.__doc__).description or "") if 
callable_.__doc__ else ""
-    args_schema_model = create_schema_from_function(name, callable_)
+    args_schema_model = create_schema_from_function(

Review Comment:
   Mirror direction: a Python function declared with 
`@tool(injected_args={...})` but referenced from a Java agent's YAML without 
re-declaring `injected_args` loses its injection entirely — this only excludes 
the names Java passes (YAML-declared), never reads the callable's 
`_injected_args`, so the param leaks into the schema; and `invoke_python_tool` 
calls the function with only the model kwargs, so nothing is injected at 
execution time and the call fails on the missing required param. If decorator 
declarations aren't meant to cross the language boundary, this deserves a loud 
error or a docs note instead of a silent failure.



-- 
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]

Reply via email to