用可定制规则在运行时保障大模型代理的安全与可靠。
AgentSpec: Customizable Runtime Enforcement for Safe and Reliable LLM Agents
- 设计轻量级语言AgentSpec,通过触发器、条件和执行机制定义安全规则。
- 在代码、具身智能体和自动驾驶中,90%以上案例避免了不安全执行。
- 规则可自动生成,适合需高安全性部署的复杂应用开发者。
基于大模型的智能体正广泛应用于各类场景,自动化完成复杂决策与任务执行。但其自主性带来安全风险,包括安全漏洞、法律违规及有害行为。现有防护方法在鲁棒性、可解释性和适应性方面存在不足。为此,我们提出AgentSpec——一种用于指定和执行大模型智能体运行时约束的轻量级领域特定语言。用户可通过结构化规则定义触发条件、判断条件和执行策略,确保智能体始终在预设安全边界内运行。我们在代码执行、具身智能体和自动驾驶等多个领域实现并验证了AgentSpec的适用性与有效性:在超过90%的代码代理案例中成功防止不安全执行,完全消除具身智能体的危险动作,并使自动驾驶车辆100%遵守交通法规。尽管具备强安全保障,其计算开销仅毫秒级。我们还利用大模型自动构建规则,评估显示OpenAI o1生成的规则对具身智能体的精确率达95.56%、召回率为70.96%,可识别87.26%的风险代码,并在8个自动驾驶场景中的5个有效防止违法行为。
原文摘要 · Abstract (English)
Agents built on LLMs are increasingly deployed across diverse domains, automating complex decision-making and task execution. However, their autonomy introduces safety risks, including security vulnerabilities, legal violations, and unintended harmful actions. Existing mitigation methods, such as model-based safeguards and early enforcement strategies, fall short in robustness, interpretability, and adaptability. To address these challenges, we propose AgentSpec, a lightweight domain-specific language for specifying and enforcing runtime constraints on LLM agents. With AgentSpec, users define structured rules that incorporate triggers, predicates, and enforcement mechanisms, ensuring agents operate within predefined safety boundaries. We implement AgentSpec across multiple domains, including code execution, embodied agents, and autonomous driving, demonstrating its adaptability and effectiveness. Our evaluation shows that AgentSpec successfully prevents unsafe executions in over 90% of code agent cases, eliminates all hazardous actions in embodied agent tasks, and enforces 100% compliance by autonomous vehicles (AVs). Despite its strong safety guarantees, AgentSpec remains computationally lightweight, with overheads in milliseconds. By combining interpretability, modularity, and efficiency, AgentSpec provides a practical and scalable solution for enforcing LLM agent safety across diverse applications. We also automate the generation of rules using LLMs and assess their effectiveness. Our evaluation shows that the rules generated by OpenAI o1 achieve a precision of 95.56% and recall of 70.96% for embodied agents, successfully identify 87.26% of the risky code, and prevent AVs from breaking laws in 5 out of 8 scenarios.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。