Files
freemo 93e3893d69
CI / lint (pull_request) Successful in 14s
CI / typecheck (pull_request) Successful in 34s
CI / security (pull_request) Successful in 29s
CI / quality (pull_request) Successful in 15s
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 14s
CI / unit_tests (pull_request) Successful in 2m4s
CI / integration_tests (pull_request) Successful in 2m50s
CI / coverage (pull_request) Successful in 4m15s
CI / docker (pull_request) Successful in 42s
CI / lint (push) Successful in 12s
CI / typecheck (push) Successful in 31s
CI / quality (push) Successful in 16s
CI / security (push) Successful in 31s
CI / build (push) Successful in 16s
CI / unit_tests (push) Successful in 3m23s
CI / benchmark-regression (push) Has been skipped
CI / docker (push) Successful in 42s
CI / integration_tests (push) Successful in 4m11s
CI / coverage (push) Successful in 4m8s
CI / benchmark-publish (push) Successful in 16m5s
CI / benchmark-regression (pull_request) Successful in 29m59s
feat(validation): implement tool wrapping runtime (wraps + transform delegation)
Implement the runtime execution engine for validation tool wrapping,
as specified in docs/specification.md § Tool Wrapping.

WrappedToolExecutor resolves wraps references and delegates execution
to wrapped tools, supporting composable wrapping chains with cycle
detection and depth limiting (max 10 levels).

ArgumentMapper translates arguments between wrapper and wrapped tool
schemas using the argument_mapping configuration. Supports both
forwarded parameter names and literal fixed values.

TransformExecutor runs user-supplied transform functions in a
sandboxed Python environment with restricted builtins (no imports,
no filesystem, no network access). Validates that transforms return
proper validation-format dicts with a passed boolean.

Wired into the tool package public API via tool/__init__.py exports.
All new error types (WrappedToolNotFoundError, WrappingCycleError,
WrappingDepthExceededError, TransformExecutionError) provide clear
diagnostic messages.

Tests: 20 Behave scenarios covering argument mapping, transform
execution, simple/chained delegation, error handling, and sandbox
restrictions. 8 Robot Framework integration smoke tests. ASV
benchmarks for delegation overhead measurement.

ISSUES CLOSED: #543
2026-03-04 18:21:19 +00:00

43 lines
1.1 KiB
Python

"""Robot helper: verify WrappedToolExecutor delegates to wrapped tool."""
from cleveragents.domain.models.core.tool import (
Tool,
ToolCapability,
ToolSource,
ToolType,
Validation,
ValidationMode,
)
from cleveragents.tool.wrapping import WrappedToolExecutor
tool = Tool(
name="local/run",
description="run",
source=ToolSource.BUILTIN,
capability=ToolCapability(read_only=True),
)
val = Validation(
name="local/check",
description="check",
source=ToolSource.WRAPPED,
tool_type=ToolType.VALIDATION,
mode=ValidationMode.REQUIRED,
wraps="local/run",
transform='def transform(x):\n return {"passed": True, "data": x}\n',
)
lookup = lambda n: tool if n == "local/run" else None # noqa: E731
called: list[str] = []
def executor_fn(n: str, a: dict) -> dict: # type: ignore[type-arg]
"""Record tool call and return output."""
called.append(n)
return {"result": "ok"}
ex = WrappedToolExecutor(lookup, executor_fn)
r = ex.execute(val, {"a": 1})
assert r["passed"] is True
assert "local/run" in called
print("OK")