How Agents Build Muscle Memory: From Tool Calls to an Automatic Continuous‑Learning Loop

The article explains how the ECC Continuous Learning module silently watches every tool invocation of an AI agent, extracts recurring implicit habits, turns them into confidence‑scored instinct files, manages them through a CLI, and feeds them back into the agent’s memory system to create a fully automated learning feedback loop.

AliExpress Tech
AliExpress Tech
AliExpress Tech
How Agents Build Muscle Memory: From Tool Calls to an Automatic Continuous‑Learning Loop

Architecture Overview

The ECC Continuous Learning module implements a closed‑loop that automatically extracts high‑frequency behavior patterns from an agent’s tool calls. The workflow consists of four tightly coupled stages:

Project initialization – sets up hook configuration, identifies the project, and starts a guarded observer process.

Behavior collection – a observe.sh hook records every tool use into observations.jsonl, redacting sensitive fields.

Pattern recognition – the observer process is awakened (signal or timer), passes multi‑layer gating, and discovers four pattern categories.

Instinct accumulation & management – recognized patterns are written as YAML instinct files and managed via a CLI.

Project Initialization

Hooks PreToolUse and PostToolUse are registered to run the script ~/continuous-learning/hooks/observe.sh. The script records the intended action before the tool runs and the result after it finishes. Project‑level environment variables PROJECT_ID, PROJECT_NAME and PROJECT_DIR isolate observation data per repository, preventing cross‑project contamination.

A lazy‑start + auto‑recycle rule keeps the observer process from idling: it checks for active sessions every 30 minutes and exits if none are found, restarting only when a new behavior‑collection request arrives.

Behavior Collection

When an agent invokes a tool, the hook creates a JSON record containing fields such as tool_name, tool_input, session_id, and cwd. Sensitive keys (api_key, token, password, etc.) are replaced with [REDACTED] before the record is appended to observations.jsonl. Example payload from the Qoder client:

{
  "session_id": "76a3f33a-1e7e-49ab-b30d-d9d0f6f2cb98",
  "cwd": "/Users/Desktop/Test/ContinuousLearning",
  "hook_event_name": "PreToolUse",
  "tool_name": "Bash",
  "tool_input": {"command": "wc -l observations.jsonl"}
}

Pattern Recognition

After a configurable number of observations (e.g., min_obs) the collector sends SIGUSR1 to the observer. The observer first checks a series of gates:

ANALYZING lock – prevents concurrent analyses.

60 s cooldown – ignores signals arriving too soon after the previous run.

Guardian gates – active time window (8:00‑23:00), project‑level cooldown (300 s), and keyboard/mouse idle time (30 min).

If all gates pass, the observer samples the latest 500 records, builds a prompt, and launches a non‑interactive LLM subprocess. The LLM looks for four pattern types:

User correction – immediate re‑edits after an edit.

Error fix – a tool_complete event with an error followed by successful retries.

Repeated workflow – the same sequence of tools (e.g., Edit → Bash → Edit) occurring multiple times.

Tool preference – consistent choice of a specific command for a given task.

A pattern must appear three or more times before it is accepted.

Instinct Generation

When a pattern qualifies, the LLM writes an instinct file directly to ${INSTINCTS_DIR}. Each file follows a strict YAML front‑matter:

---
id: kebab-case-name
trigger: when <specific condition>
confidence: <0.3‑0.85 based on frequency>
domain: <code‑style|testing|git|debugging|workflow|file‑patterns>
source: session‑observation
scope: project
project_id: ${PROJECT_ID}
project_name: ${PROJECT_NAME}
---
# Title
## Action
<single clear sentence>
## Evidence
- Observed N times in session <id>
- Pattern: <description>
- Last observed: <date>

Confidence is calculated from occurrence count (3‑5 → 0.5, 6‑10 → 0.7, 11+ → 0.85) and decays by 0.02 per week.

Instinct Management

The instinct‑cli.py tool provides lifecycle commands: status – lists project‑level and user‑level instincts with confidence bars. import / export – deduplicates and merges instincts across projects. evolve --generate – clusters instincts (2+ similar triggers, average confidence ≥ 0.75) into Skills or Agents. promote – promotes an instinct to the user‑level directory when it appears in ≥ 2 projects with average confidence ≥ 0.8. projects – view, clean, or merge project metadata.

Directory Layout

continuous-learning/
├── .qoder/settings.json          # hook configuration
├── SKILL.md                      # skill specification
├── config.json                   # observer configuration
├── hooks/observe.sh              # captures all tool calls
├── scripts/instinct‑cli.py       # management CLI
├── agents/observer‑loop.sh       # background analysis loop
└── ...

Generated data lives under ~/.local/share/ecc‑homunculus/, with separate projects/ directories for each PROJECT_ID and a top‑level instincts/ folder for global artifacts.

Sample Instincts

verify-doc-edits-with-grep-counts

– after a markdown edit, run wc -l and grep -c to assert no duplicate content (confidence 0.85, domain testing). verify-then-report-done – always run syntax/count/tests before reporting completion (confidence 0.85, domain testing). retry-on-save-race-then-verify – on a “save failed” error, check disk state before deciding to retry (confidence 0.7, domain testing).

Relation to the Memory System

Continuous Learning operates upstream: it watches, extracts, and solidifies implicit habits into instinct files. The memory system downstream then loads high‑confidence instincts into the agent’s static or automatic memory, completing a closed loop of observation → extraction → deposition → injection → new behavior → re‑observation.

Applications

Personal habit solidification – turn unconscious tool‑selection sequences into reusable rules.

Token‑cost optimization – identify and prune high‑cost detours in debugging or data‑exploration workflows.

Business rule discovery – surface constraints such as “exposure‑UV must be deduplicated” from repeated execution patterns.

Agent evaluation – use high‑confidence good and bad cases as a baseline for regression testing.

References

https://github.com/affaan-m/ECC/tree/main/skills/continuous-learning-v2

https://github.com/humanplane/homunculus

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LLMAI automationcontinuous learningpattern recognitionagent behaviorinstinct generationtool hooks
AliExpress Tech
Written by

AliExpress Tech

Official tech channel of AliExpress International Tech Division, showcasing the latest technology developments and innovations in global e‑commerce.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.