AS AgentScopeAPI 手册 / API Reference
类class agentscope.permission

PermissionEngine

class PermissionEngine
源码Source agentscope/permission/_engine.py:17–848

权限引擎,驱动智能体的推理、工具调用与会话执行。位于 agentscope.permission 包。核心成员包括 add_rule、check_permission。

Evaluates tool execution requests against configured permission rules. Matching strategy is delegated to each tool's :meth:ToolBase.match_rule:

  • Bash tools: substring / prefix wildcard matching against the command
  • Write/Read/Edit tools: glob matching against file paths
  • Other tools: generic pattern matching (or tool-name-level only)

Each :class:PermissionMode has its own _check_<mode> method so that mode policies are self-contained and readable in isolation. See :meth:check_permission for the dispatcher and the individual methods for per-mode evaluation order.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(context: PermissionContext) -> None
初始化 `PermissionEngine` 实例。
Initialize the permission engine.

方法摘要Method Summary

方法Method说明Description
def add_rule(rule: PermissionRule) -> None
添加规则。
Add a permission rule to the context.
async def check_permission(tool: ToolBase, tool_input: dict[str, Any]) -> PermissionDecisionasync
检查权限用于工具执行请求。
Check permission for a tool execution request.

构造器详情Constructor Detail

PermissionEngine

def __init__(context: PermissionContext) -> None

初始化 PermissionEngine 实例。

Initialize the permission engine.

示例Example

>>> context = PermissionContext(mode=PermissionMode.ACCEPT_EDITS)
    >>> engine = PermissionEngine(context)
参数Parameters
名称Name类型Type说明Description
contextPermissionContext上下文(类型 `PermissionContext`)。The permission context containing rules and mode
源码Source agentscope/permission/_engine.py:33–47

方法详情Method Detail

add_rule

def add_rule(rule: PermissionRule) -> None

添加规则。

Add a permission rule to the context.

示例Example

>>> engine.add_rule(PermissionRule(
    ...     tool_name="Bash",
    ...     rule_content="git:*",
    ...     behavior=PermissionBehavior.ALLOW,
    ... ))
参数Parameters
名称Name类型Type说明Description
rulePermissionRule权限规则到添加。The permission rule to add
返回Returns None
无返回值。No value is returned.
源码Source agentscope/permission/_engine.py:49–75

check_permission

async def check_permission(tool: ToolBase, tool_input: dict[str, Any]) -> PermissionDecision
async

检查权限用于工具执行请求。

Dispatches to a per-mode private method so each mode's policy is self-contained and readable in isolation: - DEFAULT → :meth:_check_default - EXPLORE → :meth:_check_explore - ACCEPT_EDITS → :meth:_check_accept_edits - BYPASS → :meth:_check_bypass - DONT_ASK → :meth:`_che…

参数Parameters
名称Name类型Type说明Description
toolToolBase工具(类型 `ToolBase`)。The tool instance being called.
tool_inputdict[str, Any]工具输入(类型 `dict[str, Any]`)。The tool input data, used for rule matching and tool-specific checks.
返回Returns PermissionDecision
返回PermissionDecision。`PermissionDecision`:
源码Source agentscope/permission/_engine.py:77–115
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.