agentscope-ai / agentscope-ai/QwenPaw
[Feature] Support pre-condition rules in AGENTS.md for tool calls
- Vorherrschende Sprache
- TypeScript
- Sterne
- 35k
- Forks
- 3.1k
- Ø Merge
- 1 T. 13 Std.
- Gemergte PRs (30 T.)
- 228
Beschreibung
## 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.
Beitragsleitfaden
Rechercherichtung
The issue names AGENTS.md, edit_file, memory_search, grep_search, and a check_pre_conditions entry point, but no repository files or tests. Start by locating the AGENTS.md parser and edit_file dispatch path, then trace how current-turn tool calls are recorded. Done means matching pre-condition rules block edit_file until the required search call has run, with tests covering matching and non-matching files.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- ai-infra-agents, tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100