Skip to content

feat(policy): support dotted paths for nested tool arguments (#22) - #158

Open
RupeshMaster wants to merge 1 commit into
CodewithJha:mainfrom
RupeshMaster:feat/policy-dotted-arg-paths
Open

RupeshMaster wants to merge 1 commit into
CodewithJha:mainfrom
RupeshMaster:feat/policy-dotted-arg-paths

Conversation

@RupeshMaster

@RupeshMaster RupeshMaster commented Nov 27, 2026 •

Copy link
Copy Markdown

Summary

  • Policy constraint field names in when / require / forbid can now be dotted paths into nested tool arguments, so recipient.domain reads {"recipient": {"domain": ...}}. Closes policy: support dotted paths for nested tool arguments #22.
  • An argument key that matches the field name verbatim still wins, so existing top-level rules behave exactly as before. A missing key, or an intermediate value that is not an object (including lists), resolves to None, the same rule as $context. paths. No wildcards or list indexes.
  • The arg_proximity fitness signal uses the same lookup. This was not in the issue's acceptance list, but without it a numeric when boundary on a nested argument (payment.amount: {gt: 200}) gives the search no gradient. Happy to split it out if you'd rather keep this PR to the evaluator.
- id: nested_refund_limit
  description: Refunds over $200 require approval
  tool: issue_refund
  kind: require_args
  when:
    payment.amount:
      gt: 200
  require:
    payment.review.approved:
      eq: true

What changed

  • mutiny_core/policy/constraints.py: new resolve_argument_value(arguments, field), used by matches_constraint_map (exported from mutiny_core.policy next to resolve_context_value).
  • mutiny_core/fitness/__init__.py: _arg_proximity reads when fields through the same helper.
  • docs/SYSTEM_DESIGN.md (constraint operators section) and CHANGELOG.md (Unreleased).
  • Tests: TestDottedArgumentPaths in tests/unit/test_policy_evaluator.py (require, forbid, when, deeper paths, missing and non-object intermediates, $context comparison, verbatim-key precedence, YAML load) and one fitness test. Existing tests are untouched.

Type of change

Checklist

  • I read CONTRIBUTING.md (where to ask, how reviews work, how to run tests)
  • Linked related issue (Fixes #N) or Discussion when applicable
  • Core stays free of framework SDK imports (adapters own glue)
  • Tests added or updated when behavior changes (uv run pytest tests/unit -q)
  • Docs / README claims match reality (no PyPI / multi-adapter claims unless shipped)
  • One concern per PR when possible
  • Authorized testing only — no open-internet attack-proxy behavior

Test plan

  • Python lint: uv run --locked ruff check → all checks passed
  • Backend tests: uv run pytest tests/unit tests/integration tests/reliability -q → 880 passed. Run locally on Python 3.12 only (macOS, OPENAI_API_KEY unset); 3.11 is left for CI.
  • CLI smoke: from a copy of examples/openai_support_agent, mutiny --help, mutiny init, mutiny run with MUTINY_SAMPLE_OFFLINE=1 and empty OPENAI_API_KEY / FEATHERLESS_API_KEY → violation found, regression saved.
  • Web typecheck + build: not run; apps/web is not touched.
  • Package build + isolated artifact gate: tests/unit/test_package_release.py passed as part of the unit run; ./scripts/verify_release_artifacts.sh not run.

Extra checks:

  • 21 of the new tests fail on main (ee7e898) and pass with this change.
  • End to end with a throwaway TargetAdapter whose issue_refund tool takes {"payment": {"amount": ..., "review": {"approved": false}}} and the policy above: mutiny run finds nested_refund_limit in generation 0 and mutiny test replays it; on main the same project ends with no violation after 48 candidates.

Notes

Constraint field names in when / require / forbid can now walk nested
tool arguments, so `recipient.domain` reads {"recipient": {"domain": ...}}.

- An argument key that matches the field name verbatim still wins, so
  existing top-level rules behave as before.
- A missing key or a non-object intermediate (including lists) resolves
  to None, the same rule as $context paths.
- The arg-proximity fitness signal follows the same paths, so numeric
  when-boundaries on nested arguments still guide the search.

Closes CodewithJha#22
@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

@RupeshMaster is attempting to deploy a commit to the priyanshu's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

policy: support dotted paths for nested tool arguments

1 participant