Neuroplastic memory, self-healing, and critical reasoning for AI agents.
A local-first, framework-agnostic Python runtime that gives agents an evolving memory, sleep-like consolidation, reflection, advisory (opt-in executable) self-healing, a critic-driven reasoning market, a skill library, and thermodynamic-style reliability reporting.
- Why Plasticity Agent?
- Feature matrix
- Installation
- Quickstart
- Use cases & examples
- 1. Neuroplastic memory
- 2. Memory quality scoring
- 3. Hybrid lexical + vector retrieval
- 4. LLM-powered upgrades
- 5. Reflection (Reflexion)
- 6. Self-Refine
- 7. Sleep / consolidation
- 8. Advisory & opt-in self-healing
- 9. Critical reasoning market
- 10. Skill library
- 11. Energy report
- 12. Cross-run improvement metrics
- 13. OpenTelemetry export
- 14. Framework adapters
- Command-line interface
- FastAPI server
- Streamlit dashboard
- Configuration & storage
- Research foundation
- Safety
- Testing & development
- Roadmap
- Contributing
- Citation
- License
Most "agent memory" is a vector store: embed text, do nearest-neighbour search, done. That captures similarity but not plasticity — it doesn't model how a memory's value changes as it is used, contradicted, consolidated, or forgotten.
Plasticity Agent treats memory as a living system with explicit signals — salience, confidence, usage, contradiction, decay, reward — and a set of processes that act on them: quality scoring, decay/forgetting, sleep-like consolidation, contradiction detection, and skill mining. A vector backend is optional (and pluggable); the plasticity logic is the point.
Everything ships with a deterministic baseline so it runs fully offline with zero model
calls — then upgrades to LLM-powered behaviour the moment you pass a single llm_callback, and
to hybrid semantic retrieval the moment you pass embeddings=. Every LLM path falls back to the
deterministic one if a call or parse fails, so nothing ever hard-depends on a model.
| Capability | What it does | Deterministic | LLM/vector upgrade |
|---|---|---|---|
| Neuroplastic memory | 5 memory types with plasticity signals | ✅ | — |
| Memory quality | Utility scoring + keep/decay/consolidate/review/prune | ✅ | — |
| Retrieval | Lexical; hybrid+vector with a backend (semantic needs sentence-transformers) |
✅ | ✅ embeddings |
| Contradiction detection | Negation/antonym(stemmed)/sentiment/numeric heuristic — precision-first | ✅ | ✅ LLM |
| Reflection (Reflexion) | Store lessons from feedback | ✅ | ✅ LLM |
| Self-Refine | Critique + notes (deterministic) → full rewrite (LLM) | ✅ | ✅ LLM |
| Sleep / consolidation | Decay, dedup, gist, skill mining, constitution governance | ✅ | ✅ embeddings |
| Self-healing | Diagnose → advisory plan → opt-in sandboxed apply | ✅ | — |
| Reasoning market | 6 critics bid; auction selects winner | ✅ | ✅ LLM critic |
| Skill library | Successful traces → reusable skills | ✅ | — |
| Energy report | Entropy, contradiction, waste, temperature → plasticity score | ✅ | — |
| Improvement metrics | Checkpoint health; prove the agent got better | ✅ | — |
| Observability | Stream trace events to OpenTelemetry | ✅ | — |
Requires Python 3.11+.
pip install plasticity-agentuv add plasticity-agentThe core install has everything you need for offline, deterministic use plus the FastAPI server and Streamlit dashboard. Heavyweight/semantic backends are opt-in:
pip install "plasticity-agent[otel]" # OpenTelemetry trace export
pip install "plasticity-agent[docs]" # MkDocs site
pip install "plasticity-agent[dev]" # pytest, ruff, mypy, numpy, otel
# Optional embedding/vector backends (installed on demand, not via an extra):
pip install sentence-transformers # true semantic embeddings
pip install faiss-cpu # large-scale ANN index
pip install numpy # accelerates the built-in vector index| Extra | Adds | For |
|---|---|---|
otel |
opentelemetry-api, opentelemetry-sdk |
Tracing/observability |
docs |
mkdocs, mkdocs-material |
Building the docs site |
dev |
pytest, ruff, mypy, numpy, opentelemetry-sdk |
Contributing |
git clone https://github.com/Kayariyan28/Plasticity-Agent.git
cd Plasticity-Agent
uv sync --all-extras # or: pip install -e ".[dev]"
uv run pytest # 122 testspython -c "from plasticity_agent import PlasticAgent; print('ok')"
plasticity --helpfrom plasticity_agent import PlasticAgent
agent = PlasticAgent(
name="research_copilot",
model="openai:gpt-5.5",
memory="./memory",
self_heal=True,
reasoning_market=True,
sleep_cycle=True,
)
result = agent.run(
"Read this paper, extract claims, critique methodology, and produce a reproducible summary."
)
agent.reflect(reward=0.8)
agent.sleep()
print(agent.energy_report())With no llm_callback configured the runtime returns a structured advisory response (it still
recalls relevant memories and asks the reasoning market for a suggested action) and traces the
run. Wire a model in one line:
def my_llm(prompt: str, **kwargs) -> str:
... # call your LLM of choice; return text
return "the model's answer"
agent = PlasticAgent(name="copilot", llm_callback=my_llm) # reflection, contradiction,
# critics, self-refine all upgradeagent.run(...) accepts three things:
- a Python callable → it's executed and traced;
- a string +
llm_callback→ the model is called; - a string + no callback → a structured advisory plan is returned.
Every snippet below is runnable. The repo's
examples/folder has 12 complete, self-contained scripts (uv run python examples/<name>.py).
from plasticity_agent import PlasticAgent
agent = PlasticAgent(name="demo", memory="./memory")
agent.remember("User prefers concise, well-cited answers.", "constitutional", tags=["user_preference"])
agent.remember("Cache warmup reduced p95 latency by 40%.", "semantic", tags=["important"], reward=0.9)
agent.remember("Tried retrying the flaky upload; it worked.", "episodic", reward=0.4)
for hit in agent.recall("latency cache"):
print(hit.score, hit.memory.content, "·", hit.match_reason)Memory types: episodic, semantic, procedural, reflective, constitutional. Each memory
carries salience, confidence, usage_count, contradiction_score, decay_rate, and
reward.
m = agent.remember("Cache warmup reduced p95 latency.", "semantic", tags=["important"], reward=0.9)
report = agent.memory.evaluate_memory(m)
print(report.utility_score, report.recommendation, report.reasons)
# 0.71 'consolidate' ['high recurrence/salience (...)']utility = 0.25*salience + 0.20*confidence + 0.15*usage + 0.15*reward
+ 0.10*recency - 0.20*contradiction - 0.10*decay # clamped to [0, 1]
Recommendations: keep · consolidate · review · decay · prune (pruning is the only destructive op and is always explicit; constitutional/important memories are protected).
Recall is lexical by default and becomes hybrid the moment you set an embedding backend — no other code changes.
# Zero-dependency hashing vectors, semantic transformers, or any embed callable:
agent = PlasticAgent(name="copilot", embeddings="hashing")
# agent = PlasticAgent(name="copilot", embeddings="st:all-MiniLM-L6-v2") # pip install sentence-transformers
# agent = PlasticAgent(name="copilot", embeddings=lambda texts: my_embed(texts))
agent.remember("Cache warmup reduced p95 latency by 40%", "semantic")
hit = agent.recall("latency cache performance")[0]
print(hit.match_reason) # "lexical overlap on: cache, latency · semantic cos=0.41"Embeddings are persisted in SQLite; a NumPy-accelerated VectorIndex (with an optional FAISS
variant) narrows candidates for large corpora, and relevance is
(1-α)·lexical + α·cosine.
Honest note on backends. The default
embeddings="hashing"is a structural embedding (token feature-hashing): fast, deterministic, zero-dependency — but it only matches on shared tokens, so it will not retrieve pure synonyms/paraphrases (e.g. "make responses faster" won't match a memory about "latency"). For genuine semantic recall useembeddings="st:all-MiniLM-L6-v2"(pip install sentence-transformers) or your own embeddings callable. The hybrid scoring, persistence, and index are identical across backends.
One callback upgrades reflection, contradiction detection, the reasoning market, and self-refine — each with a deterministic fallback:
agent = PlasticAgent(name="copilot", llm_callback=my_llm)
# or use the components directly:
from plasticity_agent import Reflector, ReasoningMarket, ContradictionChecker
Reflector(llm=my_llm).create_lesson(...)
ReasoningMarket(llm=my_llm).deliberate("...") # adds an LLM critic to the panel
ContradictionChecker(llm=my_llm).pair("ship it", "do not ship it") # semantic entailmentlesson = agent.reflect(
task="call the pricing tool",
error="TypeError: missing 1 required positional argument: 'sku'",
reward=-0.6,
)
print(lesson.lesson_type) # 'tool_use'
# stored automatically as a reflective memory for next timeLesson types: success, failure, risk, preference, tool_use, reasoning.
result = agent.refine("It will always work, probably.", rubric="accuracy, safety, completeness")
print(result.critique) # flags vague phrasing, unsupported claims, ...
print(result.improvement_score) # 0.46
print(result.refined_output)The deterministic refiner critiques and appends actionable notes — it does not rewrite the text. For an actual critique-and-rewrite, pass a model:
SelfRefine(llm_callback=lambda prompt, rubric: my_llm(prompt))(or give the agent anllm_callback).
report = agent.sleep()
print(report.summary)
# Analyzed N traces; decayed ..., merged ... duplicates, consolidated ...,
# found ... contradictions, ... constitution conflicts, created ... skills,
# suggested ... policies. Plasticity score XX/100.Sleep decays weak memories, de-duplicates, consolidates reflective clusters into semantic gist, mines procedural memories + skills from repeated successes, detects contradictions, governs the constitution, and suggests advisory prompt policies. All counts are real.
Advisory by default — it diagnoses and recommends, never editing your files:
try:
import nonexistent_pkg
except Exception as error:
plan = agent.heal(error)
print(plan.diagnosis.failure_type) # 'missing_dependency'
for step in plan.steps:
print("-", step)Execution is strictly opt-in, allowlisted, no-shell, and timed:
from plasticity_agent import RepairConsent
agent.apply_repair(error) # advisory: runs nothing
agent.apply_repair(error, RepairConsent(allow_apply=True, allow_install=True, dry_run=True)) # shows the command
agent.apply_repair(error, RepairConsent(allow_apply=True, allow_install=True, dry_run=False)) # installs the pkgfrom plasticity_agent import ReasoningMarket
result = ReasoningMarket().deliberate(
task="Choose best repair strategy for schema error",
context={"error": "missing required argument"},
)
print(result.winner.critic_name, "->", result.winner.action)
for line in result.audit_trail:
print(line)Six critics — Skeptic, Builder, Risk Analyst, Evidence Auditor, Game Theorist, Compression
Critic (plus an LLM critic when configured) — each submit a scored Proposal; the auction ranks
by 0.25·truth + 0.20·reward + 0.15·confidence + 0.10·novelty + 0.10·reversibility − 0.10·risk − 0.10·cost.
agent.skills.save("debug_import_error", {"steps": ["read traceback", "check pkg name", "uv add"]})
print(agent.skills.find("import error")[0].name) # 'debug_import_error'Skills are also mined automatically from repeated successful traces during agent.sleep().
energy = agent.energy_report()
print(energy.memory_entropy, energy.contradiction_pressure, energy.token_waste)
print(energy.confidence_temperature) # 'stable' | 'warm' | 'unstable'
print(energy.plasticity_score) # 0..100agent.checkpoint("before")
# ... the agent learns, consolidates, resolves contradictions ...
agent.checkpoint("after")
report = agent.improvement()
print(report.improved, report.summary)
# True 'Over 2 checkpoints the agent improved (score +0.135): contradiction -0.328, grounded-utility +..., skills +0 ...'The verdict rewards reduced contradiction, grounded utility (utility weighted by how much each memory is actually recalled), and learned skills — it deliberately ignores raw salience/reward, so you can't fake improvement by storing high-reward memories that are never used.
agent = PlasticAgent(name="copilot", otel=True) # every trace event -> an OTel spanRequires pip install "plasticity-agent[otel]". Local JSONL tracing keeps working regardless.
Wrap any callable or framework agent so it gains tracing, memory, and advisory healing:
from plasticity_agent.adapters import GenericAdapter, LangGraphAdapter
wrapped = GenericAdapter(agent).wrap_callable(my_function)
graph_runner = LangGraphAdapter(agent).wrap(my_compiled_graph) # also CrewAI / OpenAI-Agents / Pydantic-AIA beautiful Typer + Rich console:
plasticity init ./memory
plasticity remember "User prefers concise answers" --type constitutional --tag user_preference
plasticity recall "preferences"
plasticity evaluate
plasticity sleep ./agent_runs
plasticity report
plasticity heal "ModuleNotFoundError: No module named 'pandas'"
plasticity apply "ModuleNotFoundError: No module named 'rich'" --install # dry run
plasticity apply "ModuleNotFoundError: No module named 'rich'" --install --execute # run it
plasticity market "Choose a rollout strategy"
plasticity skills
plasticity metrics --checkpoint
plasticity export ./backup.jsonl
plasticity serve
plasticity dashboard$ plasticity sleep ./agent_runs
✓ 128 traces analyzed
✓ 41 weak memories decayed
✓ 17 memories consolidated
✓ 6 contradictions detected
✓ 4 reusable skills created
✓ 2 prompt policies improved
✓ agent plasticity score: 78/100
plasticity serve # http://127.0.0.1:8000Endpoints: GET /health, GET /memories, POST /memories, POST /recall, POST /sleep,
POST /heal, POST /market, GET /report, GET /skills.
from plasticity_agent.server.api import build_app
app = build_app(memory_dir="./memory") # mount in your own ASGI stackplasticity dashboard # http://localhost:8501Pages: Overview · Memories · Memory Quality · Sleep Reports · Failure Diagnostics · Reasoning Market · Skills · Energy Report.
Local-first. State lives under one directory (default ./memory):
memory/
├── plasticity.sqlite # memories + embedding vectors + skills
├── metrics.sqlite # improvement-metric snapshots
└── traces/
└── YYYY-MM-DD.jsonl # append-only trace events
from plasticity_agent import PlasticityConfig, PlasticAgent
config = PlasticityConfig.from_memory_dir("./agent_state")
agent = PlasticAgent(name="copilot", config=config)These theories are used as software metaphors and design principles, not as claims of biological equivalence or consciousness:
- Complementary learning systems — fast episodic memory + slower semantic consolidation.
- Synaptic homeostasis — sleep-like compression, forgetting, and strengthening.
- Reflexion (Shinn et al., 2023) — agents improve by storing lessons from feedback.
- Self-Refine (Madaan et al., 2023) — iterative self-critique and improvement.
- Voyager (Wang et al., 2023) — successful traces become a reusable skill library.
- Game / auction theory — critics bid; an auction selects the best next action.
- Free-energy principle / thermodynamics — reduce uncertainty, contradiction, and waste.
- No consciousness or biological claims. This is engineering inspired by these ideas.
- Self-healing is advisory by default; execution is strictly opt-in. Only narrow, reversible
repairs (currently
pip install <pkg>) are eligible, and only with an explicitRepairConsent(allow_apply=True, the capability flag, anddry_run=False). The sandbox uses a hard allowlist, validated package names, no shell, and a timeout — and never edits, moves, or deletes your source files. - Local-first. Nothing leaves your machine unless you wire an
llm_callback, an embedding backend, or an OTel exporter that does. - Pruning is the only destructive memory op and is always explicit; constitutional and important memories are protected.
git clone https://github.com/Kayariyan28/Plasticity-Agent.git
cd Plasticity-Agent
uv sync --all-extras
uv run pytest # 122 tests
uv run ruff check . # lint
uv run mypy plasticity_agent # types (clean)
uv build # sdist + wheelShipped in v0.2.0: LLM-powered reflection / contradiction / critics / self-refine, pluggable hybrid vector retrieval, opt-in sandboxed healing, cross-run improvement metrics, OpenTelemetry export, concurrency-safe storage, and tested framework adapters.
Next (v0.3.0): native OTLP push exporter and metrics export, an inverted-index lexical candidate stage for million-scale hybrid recall, async LLM batching, automatic embedding backfill/migration, and a richer constitution policy engine (severity tiers + remediation).
Issues and PRs welcome. Please run ruff, mypy, and pytest before submitting:
uv run ruff check . && uv run mypy plasticity_agent && uv run pytestLive download stats for plasticity-agent:
- pepy.tech — total + daily/monthly trend, version & Python breakdown: https://pepy.tech/project/plasticity-agent
- PyPIStats — official PyPI download stats with charts: https://pypistats.org/packages/plasticity-agent
- Quick CLI check:
pipx run pypistats recent plasticity-agent # last day/week/month pipx run pypistats python_minor plasticity-agent
The Downloads/month badge at the top updates automatically from PyPIStats.
Heads-up on the data lag. PyPI download counts come from a BigQuery dataset that ingests ~1–2 days after downloads happen. Right after a fresh release, pepy.tech and PyPIStats show no data — pepy's project page/badge will even 404 until the first downloads are recorded. Both self-populate automatically once data lands; no action needed. Once pepy is live you can add a total-downloads badge:
https://static.pepy.tech/badge/plasticity-agent.
@software{plasticity_agent_2026,
title = {Plasticity Agent Runtime: Neuroplastic memory, self-healing, and critical reasoning for AI agents},
author = {Kayariyan28},
year = {2026},
version = {0.2.0},
url = {https://github.com/Kayariyan28/Plasticity-Agent}
}MIT © 2026 Kayariyan28