Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add agents/microsoft/apm/algorithmic-patternsgit clone --depth 1 https://github.com/microsoft/apmWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00000 | $0.01264 |
| Opus 5 | $0.00000 | $0.00632 |
| Sonnet 5 | $0.00000 | $0.00253 |
| Haiku 4.5 | $0.00000 | $0.00126 |
Grade A, and why
algorithmic-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 153 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Algorithmic Performance Patterns
Load this reference when the PR diff touches code outside the transport/cache layer -- i.e. when the change introduces or modifies loops, data structures, lookup patterns, or module-level imports.
Big O Quick Reference
| Pattern | Complexity | Red Flag |
|---|---|---|
| Dict/set lookup | O(1) | Fine |
List .append |
O(1) amortised | Fine |
x in list |
O(n) | Use a set if called in a loop |
| Nested loops over same collection | O(n^2) | Extract an index dict first |
| Sort inside a loop | O(n^2 log n) | Sort once outside the loop |
any(pred(x) for x in coll) in a loop |
O(n*m) | Build a set/dict pre-loop |
| Unconditional full-dir scan on every write | O(n) per write = O(n^2) total | Track running total; scan only when needed |
| Linear search for identity match | O(n) per lookup | Build {identity: index} once |
Anti-Patterns to Flag
1. Missing Index on Repeated Lookup
# BAD: O(n) per call, called m times = O(n*m)
def has_item(collection, key):
return any(item.key == key for item in collection)
# GOOD: O(1) per call after O(n) setup
_index = {item.key for item in collection}
def has_item(key):
return key in _index
Flag when: a function does linear scan AND is called from within a loop or from a method called repeatedly during resolution/install.
2. Unconditional Expensive Operation
# BAD: scans entire cache dir on every store()
def store(self, url, body):
self._write(url, body)
self._enforce_size_cap() # full scandir every time
# GOOD: fast-path skip when clearly under budget
def store(self, url, body):
self._write(url, body)
self._tracked_size += len(body)
if self._tracked_size > MAX_SIZE:
self._enforce_size_cap() # scan only when needed
Flag when: an expensive operation (directory walk, sort, full re-computation) runs unconditionally on every call to a high-frequency method.
3. Triple-Pass Where Single-Pass Suffices
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- yesterday First seen · 153 lines · 0 tokens per session scan A 278321484288
algorithmic-patterns is an agent published in the GitHub repository microsoft/apm (3,668 stars, last pushed yesterday), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,264 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other agents, from other repositories
prompt-pipeline-runner
Executes the six-stage prompt-writer pipeline and produces two mandatory output artifacts (ready-to-run prompt, confidence report).
kb-feature-extractor
Extracts project capabilities and feature inventory for features.md from pre-filtered anchor-class files.
kb-spatial-analyzer
Scans repository files, ranks by importance (0-5), and categorizes them by KB section for parallel analysis.
project-documenter
Generates a digestible 3-tier/9-section birds-eye-view document from KB + codebase, with per-claim provenance in hidden HTML comments.
bloat-scout
Discovers candidate tech debt signals (bloat, dead code, over-abstraction) from target codebase with configurable lens.
kb-concept-extractor
Extracts domain concepts and terminology for conceptmap.md from pre-filtered files.