Repository navigation
feat(core): declarative tool permissions with an approval callback - #105
Merged
Merged
Conversation
gopaljigaur
commented
Oct 15, 2026
gopaljigaur
left a comment
Owner
Author
There was a problem hiding this comment.
Precedence, the fnmatchcase matching, the ValueError, the default and the raising callback all behave as described, and CI, pytest, pre-commit and mypy pass. Three findings:
denied_tool_callsis recorded in completion order and survives a failed step, so it can disagree withtool_calls(inline ontool_execution.py).- The docs do not say that approvals for tools not marked read-only are asked one at a time and hold a parallel slot while pending (inline on
docs/guide/hooks.md). - Missing tests for parallel calls, the hook's deny being recorded, and cancellation during an approval (inline on
tests/test_permissions.py).
ToolPermissions is a ToolMiddleware with allow, ask and deny rules over tool names or fnmatch patterns. A call takes the strictest rule it matches (deny, then ask, then allow) or the default; an ask call awaits an async approve callback that returns a bool or a Deny. RunResult.denied_tool_calls lists every call middleware denied in the run.
A denial was recorded inside its call's task, so parallel calls could be listed in the order they were answered, and a failed step could report a denial for a call that tool_calls does not list. The rendered result now carries the deny reason and the executor records it where it appends to tool_calls. Tests cover parallel approvals, the on_tool_start deny hook, cancelling during an approval and a step that fails after a denial.
gopaljigaur
force-pushed
the
feat/tool-permissions
branch
from
October 15, 2026 03:07
a6e90e2 to
fb20720
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds declarative tool permissions, built as one
ToolMiddleware, and a list of denied calls onRunResult.What changed
cyclops/core/permissions.py:ToolPermissions(allow=, ask=, deny=, approve=, default="allow"). Rules are tool names or patterns matched withfnmatch.fnmatchcase. A call takes the strictest rule it matches: deny, then ask, then allow; a call that matches none getsdefault. An "ask" call awaitsapprove(call)with theToolCallContext, which returnsTrueto allow,Falseto deny, orDeny(reason)to deny with a reason.askrules ordefault="ask"withoutapproveraiseValueError.RunResult.denied_tool_calls: List[DeniedToolCall](id,name,arguments,reason). When middleware returnsDeny, the rendered result carries the reason, and_ToolExecutorrecords it where it appends totool_calls: after the step, in the model's order, so a step that fails records nothing. It covers every middleware and theon_tool_starthook as well, with no state in the middleware. The list lives on the run's result, so it is per run.ToolPermissionsandDeniedToolCallare exported fromcyclopsandcyclops.core.docs/and the website.Decisions
bool | ToolApproved | ToolDeniedshape Pydantic AI uses for approvals, with the existingDenyas the denied object, so a reason is optional.before_toolalready can, instead of pausing the run and resuming it later as the OpenAI Agents SDK interruptions and LangGraph interrupts do. That needs no new run state and keeps this inside the middleware.call.annotations(destructive,read_onlyand so on) and can decide on them.Denydoes today.Tests
tests/test_permissions.pycovers allow, deny, the default, ask approved, ask refused, ask denied with a reason, patterns and precedence, a callback that raises, the denied list being per run, a naive mode denial without an id, read-only approvals running concurrently and recorded in model order, other approvals one at a time, a failed step recording no denial, and cancelling during an approval.test_middleware.pychecks a plainDenyand theon_tool_startdeny are recorded too.uv run pytest,uv run pre-commit run --all-filesanduv run mypy cyclopspass.Closes #64