agentscope-ai / agentscope-ai/QwenPaw
[Feature] Support pre-condition rules in AGENTS.md for tool calls
- Dominant language
- Python
- Stars
- 34.9k
- Forks
- 3.1k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 225
Description
## Problem
Agents sometimes skip critical verification steps before modifying files, even when rules are clearly defined in AGENTS.md. For example:
- Editing a date field in a Vue file without checking MEMORY.md for the correct date
- Modifying user-specific information (names, birthdays, config values) based on "memory" rather than verified data
The root cause is **behavioral, not capability-related**: the agent has access to memory tools and knows the rules, but the "get it done fast" tendency overrides "stop and check first". This is especially problematic when context gets long.
## Use Case
My agent manages a family app with hardcoded values (baby birthday, API endpoints, user preferences). When I ask it to fix a date value, it opens the file and edits directly **without querying MEMORY.md to confirm the correct value** — even though MEMORY.md contains the verified information on line 25.
This has caused real data errors (wrong birthday year) that were caught only by manual review.
## Proposed Solution
Support a `[pre-condition]` section in AGENTS.md that defines mandatory checks before specific tool calls:
```markdown
## Pre-conditions
[pre-condition:edit_file]
pattern: "*.vue", "*.ts", "*.js"
require: grep_search(MEMORY.md) OR memory_search
```
### Behavior
- Before executing `edit_file` on a file matching the pattern, the system checks if the required query has been performed **in the current turn**
- If not, the tool call is blocked with a message: "Pre-condition not met: please query MEMORY.md before editing this file"
- Only applies to `edit_file` (not `write_file` for new files)
- The check is lightweight — just verifying that a search call was made, not evaluating its result
## Why Prompt-Only Rules Are Not Enough
AGENTS.md already has rules like "check memory before modifying files". But these are treated as **reference**, not **mandatory**. The agent can and does skip them when it "feels confident" about the answer. Without enforcement, rules become suggestions.
## Why This Matters
- **Generic problem**: Any agent managing projects with personal/config data will face this
- **Low implementation cost**: Only needs a pattern-match + call-history check before tool execution
- **No performance impact**: Only activates for matching file patterns
- **Composable**: Users can define multiple pre-conditions for different tools/patterns
## Implementation Sketch
```python
def check_pre_conditions(tool_name, tool_args, config):
rules = config.get("pre_conditions", {}).get(tool_name, [])
for rule in rules:
if file_matches_pattern(tool_args["file_path"], rule["pattern"]):
if not has_called_in_turn(rule["require"]):
return PreConditionError(
f"Please call {rule['require']} before editing this file"
)
return None
```
The key insight: we don't need to evaluate the *quality* of the search result — just enforcing that the agent **paused to look** is enough to break the "edit first, verify never" pattern.
Contributor guide
Assessment
This issue has not been assessed yet.