---
name: memory-evolution
description: Compile agent memory and propose guarded improvements to agents, workflows, and Pi shortcuts.
---

## collect-memory
role: memory
output: memory-candidates.md

Inspect the user's supplied lesson, recent safe daily logs, agent self-evaluations, run artifacts if present, and current prompt/workflow files for: {goal}

Classify candidates as `stable-rule`, `project-convention`, `user-preference`, `workflow-fix`, `model-weakness`, `one-off`, or `hypothesis`.

Tool policy: do not call `glob` or any unavailable abstract discovery tool. Use bash discovery only: `rg --files`, `rg -n`, `find`, `sed`, `nl`, and `git grep`. If a tool returns `Tool <name> not found`, stop using it immediately; if the same tool error repeats twice, stop the task and report the blocker. Do not repeat failed tool calls or shell commands. If a command exits non-zero with no useful output, do not retry it unchanged; inspect source/tests or change the hypothesis first. If a focused test fails, use the failure location to inspect and fix code/tests; do not repeatedly grep test output for unrelated terms. After two failed verification attempts without a code or test change, stop and report the blocker. Do not continue after five consecutive calls that add no new information. Treat semantically equivalent commands as repeats even when numeric limits or filters change; do not widen `sed`, `head`, `tail`, or `git diff | grep` ranges step by step.

## compile-memory
role: memory
dependsOn: collect-memory
reads: memory-candidates.md
output: compiled-memory.md

Update reviewed project memory under `docs/agent-memory/` when the candidate is durable and safe to store. Update `index.md` and `log.md`. Do not store secrets or raw transcripts.

## propose-prompt-evolution
role: prompt-evolution
dependsOn: compile-memory
reads: compiled-memory.md
output: prompt-evolution-proposal.md

Create or update a proposal under `docs/agent-memory/prompt-evolution/`. If evidence is strong and scope is narrow, apply the smallest patch to `.pi/teams/agents/`, `.pi/teams/workflows/`, `.pi/teams/teams/`, or `.pi/prompts/`.

## critique
role: critic
dependsOn: propose-prompt-evolution
reads: prompt-evolution-proposal.md
verify: true

Challenge the proposed memory and prompt changes for overfitting, prompt drift, missing evidence, safety issues, and weak validation.

## validate
role: reviewer
dependsOn: critique
verify: true

Run static checks and `/team-validate` when practical. Report any validation that could not be run.

## gitops
role: gitops
dependsOn: validate
verify: true

If files changed and validation is sufficient, commit them on a feature branch and push.
