Tool governance for AI agents: registry, risk levels, role-based access, visibility rules, and execution guards. The tool layer of the Autarkia agent runtime.
Tool governance for AI agents 面向 AI Agent 的工具治理层:注册表 · 显式风险分级 · 角色策略 · 可见性过滤 · 执行前拦截
大多数 agent 框架回答的是怎么调工具。这个库回答跑久了才会冒出来的那个问题:谁能调、拦在哪、失败了算谁的。
它来自一个单机长期运行的 agent 运行时:20+ 领域、约 90 个工具,按角色隔离,权限校验发生在代码里而不是提示词里。
除 pydantic 外零运行时依赖,不绑定框架:工具是普通类,注册表是普通对象,导出的 schema 任何支持 function calling 的 API 都能用。
pip install autarkia 快速开始 完整可运行版本:examples/minimal.py(无网络、无 API key)。
from pydantic import BaseModel from autarkia import BaseTool, ToolCatalog, ToolDeclaration, ToolRegistry class EchoArgs(BaseModel): text: str class EchoTool(BaseTool): name = "echo" description = "Echo the given text back." args_schema = EchoArgs async def _run(self, text: str) -> str: return text # 声明它是什么:未声明 = 不可见 catalog = ToolCatalog() catalog.declare("echo", ToolDeclaration( domain="utility", risk_level="read", load_policy="on_demand", )) registry = ToolRegistry(catalog=catalog) registry.register(EchoTool()) print(registry.get_openai_tools()) # 稳定、可缓存 角色策略与可见性过滤:
from autarkia import RolePolicyResolver, filter_tool_names profiles = { "defaults": {"on_demand": ["domain:*"]}, "roles": {"librarian": {"resident": ["echo"], "disabled": ["domain:execution"]}}, "modes": {}, "routes": [{"keywords": ["repeat"], "tools": ["echo"]}], } resolver = RolePolicyResolver(profiles, catalog=catalog) policy = resolver.resolve(scope="librarian") visible = filter_tool_names( registry.get_active_tools(), policy=policy, tool_registry=registry, ) picked = resolver.select("please repeat this", scope="librarian") 执行拦截(不需要把整个 runtime 对象塞进来):
import asyncio from autarkia import execute_tool_call result = asyncio.run(execute_tool_call( registry=registry, # 本次请求授权时用的那个注册表 tool_name="echo", arguments={"text": "hi"}, allowed_tool_names=visible, # 空列表 = 什么都不许,安全默认 user_id="user-1", context={"is_master": False}, # 额外上下文,最后合并、可覆盖派生值 )) 三层分工(为什么不是一层) 层 回答的问题 数据来源 声明 ToolDeclaration 这个工具是什么(领域、标签、风险、加载策略) 每个工具的显式声明 角色策略 RoleToolPolicy 这个角色能不能调(粗粒度闸门:resident / on_demand / disabled) 注入的 profiles 映射 可见性 filter_tool_names 此刻要不要给模型看(人设 allow/deny、mode / sensitive 覆盖) 人设的 tool_access 一句话:角色策略决定“能不能调”,可见性决定“要不要露出来”,执行边界负责“真的调的时候再查一遍”。
风险:read → write → external_write → device_read → device_control → sensitive 加载:base(常驻) / on_demand(检索发现) / hidden(存在但不广播) 和主运行时的关系 Autarkia 本身不在 PyPI 上——它是一个单机运行时,不是 SaaS。这个包把那次实验里活下来的治理层单独发出来。
Most agent frameworks answer how to call a tool. This library answers the question that shows up after your agent has been running for a while: who is allowed to call what, and what happens before it runs.
It comes from a self-hosted agent runtime that has run on a single machine for months: 20+ domains, around 90 tools, isolated per role, with permission checks in code — not prompt promises.
Zero runtime dependencies beyond pydantic. No framework lock-in: tools are plain classes, the registry is a plain object, and the exported schema works with any API that speaks function calling.
pip install autarkia Quick start Runnable end to end: examples/minimal.py — no network, no API key.
risk: read → write → external_write → device_read → device_control → sensitive load: base (always offered) / on_demand (found via search) / hidden (exists, never advertised) The bigger picture Autarkia itself is not on PyPI — it is a single-machine runtime, not a SaaS. This package ships the governance layer that survived that experiment, because it turned out to be the part other projects kept asking for.
agent autarkia function-calling llm role-based-access self-hosted tool-governance tool-registry tools
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.




