lauren-framework/lauren-ai/agent-permission-scoping

Claude Code and agent skill by lauren-framework/lauren-ai

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Scope tool execution behind permission levels (read_only, mutate, admin). Use when different users or agent roles should have different tool access rights, injecting the permission level via ToolContext metadata and declaring requirements via @set_metadata.

Install

npx vskill@latest install lauren-framework/lauren-ai/agent-permission-scoping

SKILL.md

The same SKILL.md was published earlier as lauren-framework/lauren-ai/agent-permission-scoping.

Use codemap find "ToolContext" to check the metadata injection API.

Agent Permission Scoping

Define an ordered Permission enum and check permissions inline in the tool's run() method. Declare the minimum permission level with @set_metadata for introspection and documentation. Inject the caller's permission via runner.run(metadata={"caller_permission": ...}).

Permission model

python
from enum import Enum
class Permission(str, Enum):
READ_ONLY = "read_only"
MUTATE = "mutate"
ADMIN = "admin"
PERMISSION_ORDER = {
Permission.READ_ONLY: 0,
Permission.MUTATE: 1,
Permission.ADMIN: 2,
}
def _check_permission(ctx: ToolContext, required: Permission) -> dict | None:
"""Return error dict if caller lacks required permission, else None."""
granted_str = ctx.get_metadata("caller_permission") or Permission.READ_ONLY.value
try:
granted = Permission(granted_str)
except ValueError:
granted = Permission.READ_ONLY
if PERMISSION_ORDER[granted] < PERMISSION_ORDER[required]:
return {"error": f"Permission denied: requires {required.value}, got {granted.value}"}
return None

Protected tool

Apply @set_metadata first (outermost), then @tool(). The @set_metadata decorator stores the declared minimum permission on the tool class for documentation and introspection. Permission enforcement happens in run().

python
from lauren_ai._tools import ToolContext, set_metadata, tool
@set_metadata("min_permission", "mutate")
@tool()
class UpdateRecordTool:
"""Update a database record.
Args:
record_id: The record to update.
data: The new data.
"""
async def run(self, ctx: ToolContext, record_id: str, data: str) -> dict:
err = _check_permission(ctx, Permission.MUTATE)
if err:
return err
return {"updated": record_id, "data": data}

Injecting permission at call time

Pass the permission level as metadata when invoking the runner or TestClient:

python
# Production runner
response = await runner.run(
agent_instance,
"Update record 42 with new data",
metadata={"caller_permission": "mutate"},
)
# In tests via TestClient
result = client.run("Update record 42", metadata={"caller_permission": "mutate"})

ToolContext.get_metadata("caller_permission") checks tool-level static metadata first, then delegates to AgentContext.get_metadata, which reads from the metadata dict supplied to runner.run.

AgentRunner test pattern

python
import json
from lauren_ai._agents import AgentContext, agent, use_tools
from lauren_ai._tools import ToolContext, ToolResult, set_metadata, tool
from lauren_ai._transport import Completion, TokenUsage
from lauren_ai.testing import TestClient
class _Capture:
def __init__(self):
self.captured: list[ToolResult] = []
async def on_tool_result(self, result: ToolResult, ctx: AgentContext) -> ToolResult | None:
self.captured.append(result)
return None
@agent(model=None, system="Permission test agent")
@use_tools(UpdateRecordTool, DeleteRecordTool, ReadRecordTool)
class PermissionTestAgent(_Capture):
def __init__(self):
_Capture.__init__(self)
def _c(text):
return Completion(id="c1", model="mock", content=text, tool_calls=[],
stop_reason="end_turn", usage=TokenUsage(10, 5))
def test_mutate_permission_allows_update():
agent_inst = PermissionTestAgent()
client = TestClient(agent_inst)
client.mock.queue_tool_use("update_record_tool", {"record_id": "1", "data": "x"})
client.mock.queue_response(_c("Updated."))
client.run("Update record", metadata={"caller_permission": "mutate"})
out = json.loads(agent_inst.captured[0].content)
assert "error" not in out
assert out["updated"] == "1"
def test_read_only_permission_blocks_update():
agent_inst = PermissionTestAgent()
client = TestClient(agent_inst)
client.mock.queue_tool_use("update_record_tool", {"record_id": "1", "data": "x"})
client.mock.queue_response(_c("Denied."))
client.run("Update record", metadata={"caller_permission": "read_only"})
out = json.loads(agent_inst.captured[0].content)
assert "error" in out

Reading declared minimum permission in the tool

python
required = ctx.get_metadata("min_permission") # → "mutate" (from @set_metadata)
granted = ctx.get_metadata("caller_permission") # → from runner.run(metadata=...)

ctx.get_metadata checks tool-level static metadata (TOOL_METADATA attribute) first, then agent-level runtime metadata (AgentContext.metadata).

Notes

  • Permission strings are passed as plain values in metadata.
  • @set_metadata is read-only at call time — it's for declaration and

introspection, not enforcement. Always enforce in run().

  • Decorator ordering matters: @set_metadata must be outermost (applied last),

@tool() must be innermost (applied first) so that @tool() inspects the original run() signature with ctx: ToolContext.

  • For request-level permission injection in a Lauren web app, extract the

permission from request.state in the controller and forward it as metadata={"caller_permission": user.role}.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/lauren-framework/lauren-ai/agent-permission-scoping/badge)](https://verified-skill.com/skills/lauren-framework/lauren-ai/agent-permission-scoping)

Something wrong with this skill or its page? Tell us.