agentleFS
raia-liveraia-live/amfs/.cursor/rules/amfs-memory.mdc

amfs / rules

Cursor rule83 starsChanged 8 months agoApache-2.0View on GitHub

Rules for using AMFS (Agent Memory File System) as a persistent agent brain across coding sessions

  • Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.

    Of the Cursor rule files we read, the 1,533 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

Show its rules and text

We split this amfs-memory.mdc into the rules it gives an agent

18 rules. About 0 are common, 8 are distinctive, and 10 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 10

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Always pass model= with your LLM model name (e.g.

    line 19
  2. Very specific:

    Use amfs_whoami() to check the active identity.

    line 23
  3. Distinctive:

    Use kebab-case role/domain names that persist across conversations about the same topic.

    line 26
  4. Distinctive:

    If you're continuing work a previous agent started, use the same name to build on their knowledge.

    line 29
  5. Distinctive:

    When encountering errors: Check if the Cortex or another agent already has context.

    line 56
  6. Distinctive:

    When discovering a pattern: Write it with pattern_refs for cross-referencing.

    line 76
  7. Very specific:

    Not for reads or searches: Use amfs_record_context for what you *learned*.

    line 118
  8. Distinctive:

    No round-trip, no separate commit: Commit once at the end, whatever the final outcome.

    line 130
  9. Very specific:

    After a bug or minor setback: amfs_commit_outcome("<ticket>", "minor_failure")

    line 143
  10. Very specific:

    After a severe failure: amfs_commit_outcome("<incident-id>", "critical_failure") or "failure"

    line 144
  11. Distinctive:

    Before making similar decisions: Check if a past trace already covers this area.

    line 149
  12. Very specific:

    Use hierarchical paths: {repo}/{service-or-module}

    line 157
  13. Very specific:

    When you call amfs_write, the response includes a quality field with a score and any issues found.

    line 173
  14. Very specific:

    If the quality score is below 0.8, review the issues array and consider calling amfs_write again with an improved value.

    line 174
  15. Very specific:

    Use amfs_recall for specific keys you remember, amfs_search for broader queries.

    line 184
  16. Very specific:

    Use amfs_read_from when you know which agent has the knowledge you need.

    line 185
  17. Distinctive:

    Don't write trivial information (e.g.

    line 186
  18. Distinctive:

    Keep values concise but informative — think of it as writing a note to a colleague.

    line 187

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
amfs-memory.mdc
---
description: Rules for using AMFS (Agent Memory File System) as a persistent agent brain across coding sessions
globs:
alwaysApply: true
---

# AMFS Memory — Agent Behavioral Rules

You have access to AMFS (Agent Memory File System) through MCP tools. AMFS gives you a **persistent brain** — memory that survives across sessions, agents, and machines. Use it to build institutional knowledge over time.

## MANDATORY FIRST STEP: Set Your Identity

> **You MUST call `amfs_set_identity` before doing anything else.** Without it, all your work is attributed to a generic default and you won't appear as a distinct agent on the AMFS dashboard.

```
amfs_set_identity("<role-name>", "<one-line description of current task>", model="<your-model-name>")
```

Always pass `model=` with your LLM model name (e.g. `"claude-4-opus"`, `"gpt-4o"`, `"claude-3.5-sonnet"`). This is recorded in decision traces so we know which model made each decision.

**Sticky identity**: Once set, the identity is saved to `~/.amfs/.identity` and automatically restored in future sessions — even across process restarts (e.g. Claude Desktop). You only need to call `amfs_set_identity` again to change roles or update the description.

Use `amfs_whoami()` to check the active identity. Use `amfs_reset_identity()` to clear it.

**Naming rules:**
- Use **kebab-case role/domain names** that persist across conversations about the same topic.
- Good: `"dashboard-agent"`, `"stripe-agent"`, `"api-agent"`, `"infra-agent"`, `"mcp-agent"`
- Bad: `"fix-button-color"` (too specific — won't be reused), `"agent-1"` (meaningless)
- If you're continuing work a previous agent started, **use the same name** to build on their knowledge.
- The description should say what you're doing *right now* (e.g. `"Fixing tag rollback for slashed names"`).

## When to GET BRIEFED (start every session with context)

- **Before starting any work**: Get a compiled briefing from the Memory Cortex. This gives you pre-compiled knowledge about the entities you're about to work on — what other agents know, recent risks, external events, and confidence-ranked facts. This is your most important first step.
  ```
  amfs_briefing(entity_path="<repo>/<module>")
  ```
- **Read the evidence sections first.** The lead digest carries `validated` (entries every outcome confirmed — act on these), `discredited` (entries a failure gated, with `replaced_by` where known — avoid these) and `regime_shift` (long-validated entries that recently started failing — something changed; verify before reusing anything in the scope). Each `hot_context` row has an `evidence_status`: `untested`, `validated`, `contested` or `discredited`. `compact=True` returns just the lead digest with these sections.
- The briefing also carries `tried_here` (actions taken on this entity and how each fared) and, under a regime shift, an `explore` line with the untried action assigned to you. Pass `since=<iso timestamp>` on a repeat call to get only what changed.
- Then recall your own specific memories and search for details:
  ```
  amfs_recall("<repo>/<module>", "<relevant-key>")
  amfs_search(entity_path="<repo>/<service-or-module>")
  ```
- **Before choosing among a fixed set of actions** (a tool with an enum `action`, a runbook with numbered fixes): retrieve with the candidates and follow the recommendation.
  ```
  amfs_retrieve(query="<the task>", entity_path="<repo>/<module>", include_priors=True,
                candidate_actions=["resolve:resend_email", "resolve:update_payment_method"], compact=True)
  ```
  `action_priors` lists each action's won/lost here on similar tasks; `recommendation.mode` is `act` (take `suggested_action`), `explore` (everything tried here failed or a regime shift is flagged — try `suggested_action` first; it is assigned per agent so peers explore different actions), or `escalate` (every candidate has been tried and failed — escalate on the first attempt). `compact=True` keeps the first two hits full and the rest as one-liners; priors and recommendation are always complete.
- **Before making architectural decisions**: Get a briefing first, then check specific patterns.
  ```
  amfs_briefing(entity_path="<repo>/<module>")
  amfs_search(query="<topic>", min_confidence=0.5)
  ```
- **When encountering errors**: Check if the Cortex or another agent already has context.
  ```
  amfs_briefing(entity_path="<repo>/<module>")
  amfs_search(query="<error-keyword>")
  ```

## When to READ FROM another agent

- **When consulting another agent's work**: Explicitly read from their brain so the knowledge transfer is tracked.
  ```
  amfs_read_from("<agent_id>", "<repo>/<module>", "<key>")
  ```
- **When you know which agent has the answer**: Direct cross-agent read is faster and more traceable than search.

## When to WRITE memory (form a memory)

- **After completing a task**: Form a memory of what was done and why.
  ```
  amfs_write("<repo>/<module>", "task-summary-<short-desc>", "<what you did and key decisions>")
  ```
- **When discovering a pattern**: Write it with pattern_refs for cross-referencing.
  ```
  amfs_write("<repo>/<module>", "pattern-<name>", "<pattern description>", pattern_refs=["related-key"])
  ```
- **When finding a bug or risk**: Record it so other agents are warned. Use `memory_type="belief"` for hypotheses.
  ```
  amfs_write("<repo>/<module>", "risk-<name>", "<what could go wrong>", confidence=0.8, memory_type="belief")
  ```
- **When making a non-obvious decision**: Record the reasoning for future agents.
  ```
  amfs_write("<repo>/<module>", "decision-<topic>", "<decision and rationale>")
  ```
- **When logging actions taken**: Record what you did so future agents can retrace steps. Experiences decay slower.
  ```
  amfs_write("<repo>/<module>", "action-<desc>", "<what you did>", memory_type="experience")
  ```
- **When consulting external tools or APIs**: Record the context so decision traces are complete.
  ```
  amfs_record_context("<label>", "<summary of what was found>", source="<tool name>")
  ```

## When to RECORD DECISIONS (build the causal chain)

- **When a decision is made** (by you or the user): Record it so the decision trace is complete.
  ```
  amfs_record_context("user-decision", "User chose thread-local approach over request-scoped", source="chat")
  amfs_record_context("architecture-decision", "Using uvx for distribution — no source code needed", source="analysis")
  ```
- **When consulting external tools or APIs**: Record the context so decision traces are complete.
  ```
  amfs_record_context("pagerduty-incidents", "3 SEV-1 in last 24h", source="PagerDuty API")
  ```
- Record contexts **as they happen** during the session, not all at the end. This preserves the causal order.

## When to RECORD ACTIONS (what you did, not what you learned)

- **Right after taking a consequential action**: deploying, rolling back, editing a file, refunding, sending, opening a PR, changing a setting.
  ```
  amfs_record_action("deploy_rollback", {"service": "checkout", "to_version": "v41"})
  amfs_record_action("refund_payment", {"charge_id": "ch_123"}, result="refunded")
  ```
- **Record failures too** — pass `success=False`. A trace committed as a failure is far more useful when it shows what was attempted.
- **Not for reads or searches.** Use `amfs_record_context` for what you *learned*; this is for what you *did*.
- **Use the real tool name, consistently.** The same action should always be recorded under the same name. When the action is one of a fixed set, pass `action_key="<tool>:<action>"` (derived from an `action` argument otherwise) — it is what the outcome is credited to and what the next agent's `action_priors` count over. Never put free text in an action key.
- AMFS cannot observe this by itself — it sees only its own tools, so a call to your deploy or refund tool is invisible unless you record it. Together with `task_input` below it forms a complete record: what you were asked, and what you did about it.

## When an APPROACH FAILS (mark the attempt before trying another)

- **The moment a remembered fix, runbook step or pattern did not work** and you are about to try something else:
  ```
  amfs_record_attempt(summary="restarted worker per runbook; queue still stuck")
  amfs_record_attempt(outcome_type="failure", causal_entry_keys=["acme/support/fix-restart"])
  ```
- Everything read and done since the previous attempt is attributed to it. At `commit_outcome` those entries receive the failure and only what you read afterwards is credited with the success — the stale memory loses confidence instead of being reinforced by your recovery, and a `lesson-contrast-*` entry is written naming what failed and what worked.
- **No round-trip, no separate commit.** Commit once at the end, whatever the final outcome; the attempts travel inside the same trace.

## When to COMMIT OUTCOMES (capture the full trace)

- **After completing a significant task**: This snapshots all reads, writes, decisions, contexts, and recorded actions from the session into a persisted `DecisionTrace`. Always do this at the end of meaningful work.
  ```
  amfs_commit_outcome("tenant-rls-fix", "success",
                      task_input="tenant queries leaking across accounts",
                      response_text="Added the tenant_id predicate to the RLS policy; the leak is closed.")
  amfs_commit_outcome("mcp-pypi-publish", "success")
  ```
- **Pass `task_input` whenever you have it** — the request that started the work, in the words it arrived in (the user's ask, the alert payload, the ticket body). Without it the trace records what you decided but not what you were asked, which is the half that makes it reusable. Secrets are scanned and redacted before storage.
- **Pass `response_text` on every commit** — your final message to the user, in full. AMFS sees only its own tools, so what you answered is invisible unless you hand it over here; a judge grading the answer reads nothing otherwise.
- After a **bug or minor setback**: `amfs_commit_outcome("<ticket>", "minor_failure")`
- After a **severe failure**: `amfs_commit_outcome("<incident-id>", "critical_failure")` or `"failure"`
- **Don't skip this step** — without `commit_outcome`, the decision trace is lost when the session ends.

## When to BROWSE TRACES (learn from past decisions)

- **Before making similar decisions**: Check if a past trace already covers this area.
  ```
  amfs_list_traces(entity_path="<repo>/<module>", limit=5)
  amfs_get_trace("<trace-id>")
  ```

## Entity naming convention

Use hierarchical paths: `{repo}/{service-or-module}`

Examples:
- `amfs/core-engine` — the core AMFS engine
- `myapp/checkout-service` — a checkout service
- `myapp/auth` — authentication module

## Confidence guidelines

- `1.0` — verified fact, tested pattern, confirmed decision
- `0.7-0.9` — high confidence based on analysis, not yet validated in production
- `0.4-0.6` — hypothesis, initial observation, needs validation
- `< 0.4` — speculative, early signal

## Quality Feedback on Writes

When you call `amfs_write`, the response includes a `quality` field with a score and any issues found.
If the quality score is below 0.8, review the `issues` array and consider calling `amfs_write` again
with an improved value. Common issues:
- **too_short**: Value lacks detail. Add specifics: what, why, key parameters.
- **missing_pattern_refs**: Related entries exist. Add pattern_refs to link them.
- **belief_no_rationale**: Beliefs should explain reasoning (use "because", "hypothesis").
- **overconfident_belief**: Beliefs should have confidence < 0.9.

## Important

- **Always start with `amfs_briefing`** — this gives you compiled, ranked knowledge from the Cortex before you even start looking.
- Use `amfs_recall` for specific keys you remember, `amfs_search` for broader queries.
- Use `amfs_read_from` when you know which agent has the knowledge you need.
- Don't write trivial information (e.g. "added a comment"). Write things that would help a future agent.
- Keep values concise but informative — think of it as writing a note to a colleague.
- Confidence decays over time. Entries validated by outcomes decay slower.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.