Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions models/src/agent_control_models/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ class SteeringContext(BaseModel):
type TemplateValue = str | bool | list[str]
type JsonValue = JSONValue

MAX_CONDITION_DEPTH = 12
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think a normal usecase would need this much depth? what was hte motivation behind doubling it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They might depending on how complex the Control is, which they might get complex if we generate them using LLMs (which i did for Leon The Controller).

IMO we should not dictate a shallow depth just because we are afraid users will misuse it. We should leave it up to them. We should have some depth that prevents some perf issues tho, so I would push this limit even higher in the future.

_TEMPLATE_PARAMETER_NAME_RE = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$")
MAX_TEMPLATE_DEFINITION_DEPTH = 12
MAX_TEMPLATE_DEFINITION_DEPTH = MAX_CONDITION_DEPTH
MAX_TEMPLATE_DEFINITION_NODES = 1000


Expand Down Expand Up @@ -524,9 +525,6 @@ def normalize_decision(cls, value: str) -> ActionDecision:
return normalize_action(value)


MAX_CONDITION_DEPTH = 6


def _validate_common_control_constraints(
condition: ConditionNode,
action: ControlAction,
Expand Down
19 changes: 17 additions & 2 deletions models/tests/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,28 @@ def test_condition_iter_leaves_preserves_left_to_right_order() -> None:

def test_condition_depth_limit_is_enforced() -> None:
# Given: a condition tree nested deeper than the allowed maximum
allowed_depth = _leaf("input")
for _ in range(11):
allowed_depth = {"not": allowed_depth}

control = ControlDefinition.model_validate(
{
"execution": "server",
"scope": {"step_types": ["llm"], "stages": ["pre"]},
"condition": allowed_depth,
"action": {"decision": "deny"},
}
)

assert control.condition.max_depth() == 12

too_deep = _leaf("input")
for _ in range(6):
for _ in range(12):
too_deep = {"not": too_deep}

with pytest.raises(
ValidationError,
match="Condition nesting depth exceeds maximum of 6",
match="Condition nesting depth exceeds maximum of 12",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the constant MAX_CONDITION_DEPTH here instead?

):
# When: validating the deep condition tree
ControlDefinition.model_validate(
Expand Down
Loading