Skip to content

Commit dbd5120

Browse files
committed
fix(core): auto-filter tool arguments based on JSON Schema
- Updated zenml_wrapper.py to fetch tool schema and filter tool_args before execution. - This prevents 'Unexpected keyword argument' errors from Zem's auto-chaining. - Reverted **kwargs in argilla/server.py as it is no longer needed and not supported by FastMCP.
1 parent e2ea6db commit dbd5120

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "xfmr-zem"
3-
version = "0.3.8"
3+
version = "0.3.9"
44
description = "Zem: Unified Data Pipeline Framework (ZenML + NeMo Curator + DataJuicer) for multi-domain processing"
55
readme = "README.md"
66
requires-python = ">=3.10,<3.13"

src/xfmr_zem/servers/argilla/server.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def create_dataset(
7070
guidelines: str = "",
7171
api_url: Optional[str] = None,
7272
api_key: Optional[str] = None,
73-
**kwargs: Any,
7473
) -> Dict[str, Any]:
7574
"""
7675
Tạo hoặc lấy dataset trên Argilla server.
@@ -136,7 +135,6 @@ def push_records(
136135
batch_size: int = 200,
137136
api_url: Optional[str] = None,
138137
api_key: Optional[str] = None,
139-
**kwargs: Any,
140138
) -> Dict[str, Any]:
141139
"""
142140
Đẩy records từ pipeline vào Argilla dataset.
@@ -456,7 +454,6 @@ def annotation_progress(
456454
workspace: str = "admin",
457455
api_url: Optional[str] = None,
458456
api_key: Optional[str] = None,
459-
**kwargs: Any,
460457
) -> Dict[str, Any]:
461458
"""
462459
Thống kê tiến độ annotation của dataset.
@@ -622,7 +619,6 @@ def create_user(
622619
workspace: Optional[str] = None,
623620
api_url: Optional[str] = None,
624621
api_key: Optional[str] = None,
625-
**kwargs: Any,
626622
) -> Dict[str, Any]:
627623
"""
628624
Tạo user mới trên Argilla server.

src/xfmr_zem/zenml_wrapper.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,25 @@ def mcp_generic_step(
195195
command = server_config.get("command", "python")
196196
args = server_config.get("args", [])
197197
env = server_config.get("env", os.environ.copy())
198+
199+
# Filter tool_args based on tool's inputSchema
200+
try:
201+
tools = list_mcp_tools(command, args, env)
202+
target_tool = next((t for t in tools if t["name"] == tool_name), None)
203+
if target_tool and "inputSchema" in target_tool:
204+
schema = target_tool["inputSchema"]
205+
properties = schema.get("properties", {})
206+
valid_keys = set(properties.keys())
207+
208+
# Filter arguments
209+
original_args = tool_args.copy()
210+
tool_args = {k: v for k, v in tool_args.items() if k in valid_keys}
211+
212+
removed_keys = set(original_args.keys()) - valid_keys
213+
if removed_keys:
214+
logger.info(f"[{server_name}] Lọc bỏ tham số dư thừa cho '{tool_name}': {removed_keys}")
215+
except Exception as e:
216+
logger.warning(f"[{server_name}] Không thể lấy schema để lọc tham số cho '{tool_name}': {e}")
198217

199218
logger.info(f"[{server_name}] Executing tool '{tool_name}'")
200219
start_time = time.time()

0 commit comments

Comments
 (0)