Class ToolPermissionPolicy
Defines which tools an agent is permitted to use and under what conditions.
public sealed class ToolPermissionPolicy
- Inheritance
-
ToolPermissionPolicy
- Inherited Members
Examples
Example: A safe chat profile
var policy = new ToolPermissionPolicy()
.Allow("calculator", "datetime", "text", "json")
.AllowCategory("numeric", "text", "utility")
.DenyCategory("io", "net")
.SetMaxRiskLevel(ToolRiskLevel.Low);
Example: A developer assistant profile
var policy = new ToolPermissionPolicy()
.AllowCategory("data", "text", "numeric", "utility", "security")
.Allow("filesystem", "http", "websearch", "process")
.Deny("smtp", "ftp")
.RequireApproval("process", "filesystem")
.SetMaxRiskLevel(ToolRiskLevel.High);
Remarks
A permission policy controls tool access through three mechanisms:
- Allow/Deny lists: Specify which tools (by name or wildcard pattern) are permitted or blocked.
- Category rules: Allow or deny entire tool categories
(e.g.,
"io","net"). - Risk-level gates: Set a maximum risk level; tools exceeding it are blocked or require approval.
Evaluation Order: Deny rules are evaluated first and take precedence over allow rules. If no explicit rule matches, the DefaultAction determines the outcome.
Fields
- CategoryRulePrefix
The prefix of a textual approval rule naming a category:
category:io.
- RiskRulePrefix
The prefix of a textual approval rule naming a risk level:
risk:high.
Properties
- ApprovalRiskLevel
Gets or sets the risk level from which a tool needs approval: a tool whose RiskLevel is at or above it is ApprovalRequired. Default is
null(no risk-level approval rule).
- DefaultAction
Gets or sets the default action when no explicit rule matches a tool. Default is Allow.
- MaxRiskLevel
Gets or sets the maximum allowed risk level. Tools with a higher ToolRiskLevel are denied unless explicitly allowed. Default is
null(no risk-level gate).
Methods
- Allow(params string[])
Adds tool names to the allow list.
- AllowCategory(params string[])
Allows all tools in the specified categories.
- Deny(params string[])
Adds tool names to the deny list. Deny rules take precedence over allow rules.
- DenyCategory(params string[])
Denies all tools in the specified categories.
- Evaluate(ITool)
Evaluates whether the specified tool is permitted by this policy.
- RequireApproval(params string[])
Marks specific tools as requiring user approval before execution.
- RequireApprovalFor(IEnumerable<string>)
Adds approval rules written as text, the form configuration files and agent definitions carry: a tool name or wildcard pattern (
filesystem_*),category:<name>for every tool of a category, orrisk:<level>for every tool at or above a risk level (low,medium,high,critical).
- RequireApprovalForCategory(params string[])
Marks all tools in the specified categories as requiring user approval.
- RequireApprovalFromRiskLevel(ToolRiskLevel)
Marks every tool at or above
minLevelas requiring approval.
- SetMaxRiskLevel(ToolRiskLevel)
Sets the maximum allowed ToolRiskLevel. Tools exceeding this level are denied unless explicitly allowed by name.