agentscope-ai / agentscope-ai/QwenPaw

[Feature] Support pre-condition rules in AGENTS.md for tool calls

Aperta
#6,321 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
35k
Fork
3.1k
Merge medio
1g 13h
PR unite (30g)
228

Descrizione

## 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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
ai-infra-agents, tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.