Enforcing Temporal Constraints for LLM Agents

Adharsh Kamath, Sishen Zhang, Changming Xu, Shubham Ugare, Gagandeep Singh, Sasa Misailovic

TL;DR

Agent-C is a novel runtime-monitoring framework that brings formal verification to LLM tool-calling agents by enforcing temporal safety constraints (e.g., "always authenticate a user before fetching their data"). By combining a custom domain-specific language, automated translation to first-order logic, and incremental SMT solving during token generation, Agent-C guarantees 100% safety compliance while surprisingly boosting the agent's overall task utility.

What Problem Does This Paper Address?

As Large Language Model (LLM) agents are increasingly deployed to handle real-world tasks—like managing retail orders or booking flights—they are granted the power to call external tools and modify databases. This introduces massive safety and security risks. While existing guardrails can catch isolated instances of toxic or unsafe text, they fail to handle temporal safety policies: rules that govern the ordering and sequencing of actions over time.

For example, an agent shouldn't process a refund to an unverified payment method or disclose a Social Security Number before a user logs in. Current guardrails rely on fuzzy natural language prompts or post-hoc monitoring, neither of which provide formal guarantees. If an agent decides to bypass authentication under an adversarial prompt injection attack, traditional guardrails are often powerless to stop the tool call before the damage is already done.

Overview of Agent-C preventing an unsafe tool call compared to a generic agent framework.

Methods

The authors introduce Agent-C, a framework that intercepts tool calls during the LLM's token generation phase to ensure strict policy compliance. Its architecture relies on three main pillars:

  1. A Temporal Domain-Specific Language (DSL): Developers can precisely write safety properties using intuitive temporal predicates like Before, After, Seq, Forall, and Exists. Crucially, the DSL supports state checks via developer-defined "state-projection maps," allowing the policy to reason about the underlying database state (e.g., checking if an order status is actually "pending" before allowing a cancellation).
  2. First-Order Logic & SMT Solving: Agent-C maintains an execution trace of all tool inputs, outputs, and states. At each step, it translates the DSL specification and the current trace into a First-Order Logic formula. It then queries the Z3 SMT solver incrementally to verify if a proposed tool call would violate the policy.
  3. Constrained Generation with Backtracking:
  4. For Open-Weight Models (e.g., Qwen3): Agent-C integrates directly into the token decoding process. If a partial tool call or argument violates a constraint, the system backtracks to the last safe choice and forces the LLM to sample an alternative, compliant path.
  5. For Closed-Source Models (e.g., GPT-5, Claude 4.5): Because commercial APIs don't expose token probabilities, Agent-C implements a coarser "reprompting" mechanism, rejecting non-compliant full tool calls and prompting the model to regenerate.

Datasets

The framework was evaluated using $\tau$-bench, a standard benchmark for tool-use agents simulating real-world customer service environments:

  • Retail Scenario: 115 tasks involving database queries for orders, user profiles, and item modifications.
  • Airline Scenario: 50 tasks focused on flight bookings, cancellations, and reservation adjustments.

To rigorously test safety, the authors extended $\tau$-bench by introducing 17 adversarial benchmarks for each scenario. In these adversarial tasks, a simulated user actively employs prompt injection or deceptive framing to trick the agent into violating policies (e.g., attempting to cancel someone else's flight or bypass identity verification).

Key Insights and Ideas

  • The Utility-Safety Win-Win: Conventionally, adding strict guardrails degrades an LLM's performance on benign tasks because it restricts the model's flexibility. Agent-C flips this narrative. By proactively steering the LLM away from illegal states and providing immediate feedback, it helps the agent find valid alternative strategies to complete the user's task, thereby improving utility.
  • State Matters as Much as History: Purely tracking the history of tool calls is insufficient for safety. Many temporal rules depend on the state of the system (e.g., "only return items if the order status is 'delivered'"). Integrating state-projection maps directly into the formal verification loop is a vital design choice.
  • Bootstrapping Specs with LLMs: Writing formal logic specs is hard for software engineers. The authors found that frontier models like Claude Sonnet 4.5 can successfully translate natural language policy documents into correct Agent-C DSL specifications, drastically lowering the barrier to adoption.

Key Results

Agent-C was evaluated against state-of-the-art baselines like AgentSpec and DynaGuard across multiple open and closed models:

  • Perfect Safety: Agent-C achieved 100% conformance and 0% harm across all models (Qwen3-8B/14B/32B, Claude Sonnet 4.5, GPT-5) in both benign and adversarial environments. Unrestricted models failed significantly under attack, with Claude Sonnet 4.5 exhibiting harmful behavior 29.41% of the time on adversarial retail tasks.
  • Utility Boost: On closed frontier models, Agent-C pushed task utility from 77.4% to 80.46% for Claude Sonnet 4.5 and from 83.7% to 100% conformance for GPT-5, while simultaneously increasing task completion rates. For open-weights models (Qwen3-32B), utility skyrocketed from 25.52% (unrestricted) to 53.31%.
  • Token Efficiency: Thanks to fine-grained grammar-guided backtracking, the open-weights version of Agent-C reduced input token overhead by up to 40% and output tokens by up to 54% compared to naive reprompting methods.

Limitations and Future Work

  • Closed-Source API Overhead: For commercial models behind APIs, the lack of token-level access forces a coarse resampling strategy. This reprompting increases latency and token costs as the conversation lengthens.
  • DSL Expressiveness: The current DSL represents a "Next-free" fragment of Linear Temporal Logic (LTL), meaning it cannot explicitly constrain actions to happen immediately at the very next step. The authors note that adding a Next operator is a clear avenue for future expansion.
  • Global Consistency Assumption: Agent-C assumes that the underlying tool state is globally consistent and not being modified concurrently by external processes during the verification step. Real-world distributed systems might violate this assumption, requiring more complex transactional locking mechanisms.

Summary updated

BibTeX
@inproceedings{kamath2026enforcing,
  author = {Adharsh Kamath and Sishen Zhang and Changming Xu and Shubham Ugare and Gagandeep Singh and Sasa Misailovic},
  title = {{Enforcing Temporal Constraints for LLM Agents}},
  booktitle = {VerifAI-2 @ ICLR},
  year = {2026},
  url = {https://openreview.net/forum?id=VeRehDnGJJ},
}
Figure