MemoryOps
MemoryOps is a set of patterns for using Cache Memory and Repo Memory to persist state across workflow runs. Use memory to record progress, resume after interruptions, share data between workflows, support incremental processing, analyze trends, and coordinate multi-step tasks.
flowchart LR r1([Run 1]) --> s1[memory\nstate 1] s1 --> r2([Run 2]) r2 --> s2[memory\nstate 2] s2 --> r3([Run 3])When prompting agents to use memory, high-level descriptions are often enough. You usually do not need to define a schema up front: the first run can write a practical structure, and later runs can read and evolve it as needed. That flexibility makes memory useful for stateful workflows without rigid schemas.
Memory Types
Section titled “Memory Types”Three memory stores are available:
| Cache Memory | Temporary state, session data, short-term caching | tools.cache-memory.key: my-workflow-state | /tmp/gh-aw/cache-memory/ |
| Repo Memory | Historical data, trend tracking, long-lived state | tools.repo-memory.branch-name: memory/my-workflow | /tmp/gh-aw/repo-memory/default/ |
| Comment Memory | PR or issue follow-up context, review history, iterative updates | tools.comment-memory.target: triggering | /tmp/gh-aw/comment-memory/ |
Cache Memory uses GitHub Actions cache with 7-day retention. Repo Memory stores files in a dedicated Git branch. Comment Memory stores state in a managed issue or PR comment and updates it over time.
Pattern 1: Exhaustive Processing
Section titled “Pattern 1: Exhaustive Processing”Track progress through large datasets with todo/done lists to ensure complete coverage across multiple runs.
The agent maintains a state file with items to process and completed items, updating it after each item so the workflow can resume if interrupted:
Real examples: .github/workflows/repository-quality-improver.md, .github/workflows/copilot-agent-analysis.md
Pattern 2: State Persistence
Section titled “Pattern 2: State Persistence”Save workflow checkpoints to resume long-running tasks that may timeout.
The agent stores a checkpoint with the last processed position and resumes from it each run:
Real examples: .github/workflows/daily-news.md, .github/workflows/cli-consistency-checker.md
Pattern 3: Shared Information
Section titled “Pattern 3: Shared Information”Share data between workflows using repo-memory branches. A producer workflow stores data; consumers read it using the same branch name.
Producer workflow:
Consumer workflow:
Both workflows reference the same branch:
Real examples: .github/workflows/metrics-collector.md (producer), trend analysis workflows (consumers)
Pattern 4: Data Caching
Section titled “Pattern 4: Data Caching”Cache API responses to avoid rate limits and reduce workflow time. Check for fresh cached data before making API calls. A reasonable starting point is repository metadata (24h), contributor lists (12h), issues and PRs (1h), and workflow runs (30m).
Real examples: .github/workflows/daily-news.md
Pattern 5: Trend Computation
Section titled “Pattern 5: Trend Computation”Store time-series data and compute trends, moving averages, and statistics. The agent appends new data points to a JSON Lines history file and computes trends using Python.
Real examples: .github/workflows/daily-code-metrics.md, .github/workflows/shared/charts-with-trending.md
Pattern 6: Multiple Memory Stores
Section titled “Pattern 6: Multiple Memory Stores”Use multiple memory instances for different lifecycles — cache-memory for temporary session data, separate repo-memory branches for metrics, configuration, and archives.
Pattern 7: PR Comment Memory
Section titled “Pattern 7: PR Comment Memory”Use comment memory to keep task state in the pull request discussion, so each run can continue with the latest context from the PR itself.
This works well for PRs that need multiple review cycles because state stays attached to the PR. Use a stable memory-id so repeated runs update the same state file at /tmp/gh-aw/comment-memory/<memory-id>.md; changing the memory-id writes to a different file instead.
Best Practices
Section titled “Best Practices”- Use JSON Lines for append-only logs and time-series data.
- Include lightweight metadata so later runs can understand the structure.
- Rotate old data to prevent unbounded growth.
Security Considerations
Section titled “Security Considerations”Memory stores are visible to anyone with repository access. Never store credentials, API tokens, PII, or secrets — only aggregate statistics and anonymized data.
Troubleshooting
Section titled “Troubleshooting”- Cache not persisting: Verify the cache key is consistent across runs.
- Repo memory not updating: Check that file-glob matches your files and that they stay within the max-file-size limit.
- Out of memory errors: Process data in chunks instead of loading everything at once, and rotate old data.
- Merge conflicts: Prefer append-only JSON Lines, separate branches per workflow, or include the run ID in filenames.
Related Documentation
Section titled “Related Documentation”- Cache Memory — Full cache-memory reference
- Repository Memory — Full repo-memory reference
- MCP Servers - Memory MCP server configuration
- DeterministicOps - Data preprocessing and extraction
- Safe Outputs - Storing workflow outputs
- Frontmatter Reference - Configuration options