PermissionEngine
public final class PermissionEngine
io/agentscope/core/permission/PermissionEngine.java:47–335权限引擎,驱动智能体的推理、工具调用与会话执行。位于 io.agentscope.core.permission 包。核心成员包括 getContext、addRule、getAllowRules、getDenyRules、getAskRules、checkPermission。
Evaluates tool execution requests against configured permission rules.
Evaluation order:
-
Tool-level deny rules (highest priority).
-
Tool-level ask rules.
-
Tool-specific checks (bypass-immune): EXPLORE/ACCEPT_EDITS read-only handling, dangerous path checks, plus whatever the tool's own
ToolBase#checkPermissionsreturns. -
Tool-level allow rules.
-
PermissionMode#BYPASSfallback. -
Default ASK (converted to DENY under
PermissionMode#DONT_ASK).
The engine snapshots rules from the supplied PermissionContextState into its own mutable
tables on construction; the original context is never mutated. Use #addRule to extend
the engine's rule set at runtime.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public PermissionEngine(PermissionContextState context) | 初始化 `PermissionEngine` 实例。 Creates an engine seeded from the given context's rules and mode. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public PermissionContextState getContext() | 获取上下文。 Returns the underlying context (mode and working directories are read from it). |
public void addRule(PermissionRule rule) | 添加规则。 Adds a rule to the engine's internal rule set. |
public Map<String, List<PermissionRule>> getAllowRules() | 获取 `getAllowRules`。 Read-only view of the engine's current allow-rule table. |
public Map<String, List<PermissionRule>> getDenyRules() | 获取拒绝规则。 Read-only view of the engine's current deny-rule table. |
public Map<String, List<PermissionRule>> getAskRules() | 获取 `getAskRules`。 Read-only view of the engine's current ask-rule table. |
public Mono<PermissionDecision> checkPermission(ToolBase tool, Map<String, Object> toolInput) | 检查权限。 Resolves a permission decision for the given tool invocation. |
构造器详情Constructor Detail
PermissionEngine
public PermissionEngine(PermissionContextState context)
初始化 PermissionEngine 实例。
Creates an engine seeded from the given context's rules and mode.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
context | PermissionContextState | 上下文(类型 `PermissionContextState`)。permission context providing mode, working directories, and initial rules |
io/agentscope/core/permission/PermissionEngine.java:59–64方法详情Method Detail
getContext
public PermissionContextState getContext()
获取上下文。
Returns the underlying context (mode and working directories are read from it).
PermissionContextStateio/agentscope/core/permission/PermissionEngine.java:82–84addRule
public void addRule(PermissionRule rule)
添加规则。
Adds a rule to the engine's internal rule set.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rule | PermissionRule | 规则(类型 `PermissionRule`)。the rule to add; must be non-null |
io/agentscope/core/permission/PermissionEngine.java:94–106getAllowRules
public Map<String, List<PermissionRule>> getAllowRules()
获取 getAllowRules。
Read-only view of the engine's current allow-rule table.
Map<String, List<PermissionRule>>io/agentscope/core/permission/PermissionEngine.java:109–111getDenyRules
public Map<String, List<PermissionRule>> getDenyRules()
获取拒绝规则。
Read-only view of the engine's current deny-rule table.
Map<String, List<PermissionRule>>io/agentscope/core/permission/PermissionEngine.java:114–116getAskRules
public Map<String, List<PermissionRule>> getAskRules()
获取 getAskRules。
Read-only view of the engine's current ask-rule table.
Map<String, List<PermissionRule>>io/agentscope/core/permission/PermissionEngine.java:119–121checkPermission
public Mono<PermissionDecision> checkPermission(ToolBase tool, Map<String, Object> toolInput)
检查权限。
Resolves a permission decision for the given tool invocation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
tool | ToolBase | 工具(类型 `ToolBase`)。the tool being called |
toolInput | Map<String, Object> | 输入映射工具将接收。the input map the tool will receive |
Mono<PermissionDecision>io/agentscope/core/permission/PermissionEngine.java:139–178