forked from cleveragents/cleveragents-core
93e3893d69
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
29 lines
727 B
Python
29 lines
727 B
Python
"""Robot helper: verify WrappedToolExecutor raises on missing tool."""
|
|
|
|
from cleveragents.domain.models.core.tool import (
|
|
ToolSource,
|
|
ToolType,
|
|
Validation,
|
|
ValidationMode,
|
|
)
|
|
from cleveragents.tool.wrapping import WrappedToolExecutor, WrappedToolNotFoundError
|
|
|
|
val = Validation(
|
|
name="local/check",
|
|
description="check",
|
|
source=ToolSource.WRAPPED,
|
|
tool_type=ToolType.VALIDATION,
|
|
mode=ValidationMode.REQUIRED,
|
|
wraps="local/missing",
|
|
transform='def transform(x):\n return {"passed": True}\n',
|
|
)
|
|
ok = False
|
|
try:
|
|
WrappedToolExecutor(
|
|
lambda n: None,
|
|
lambda n, a: {},
|
|
).execute(val, {})
|
|
except WrappedToolNotFoundError:
|
|
ok = True
|
|
print(f"error_raised={ok}")
|