Neuroplastic memory, self-healing, and critical reasoning for AI agents — a local-first, framework-agnostic runtime.
Project description
🧠 Plasticity Agent Runtime
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.
Table of contents
- 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
Why Plasticity Agent?
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.
Feature matrix
| 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 lexical+vector | ✅ | ✅ embeddings |
| Contradiction detection | Negation/antonym/sentiment heuristic → entailment | ✅ | ✅ LLM |
| Reflection (Reflexion) | Store lessons from feedback | ✅ | ✅ LLM |
| Self-Refine | Iterative critique → improved output | ✅ | ✅ 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 | ✅ | — |
Installation
Requires Python 3.11+.
With pip
pip install plasticity-agent
With uv
uv add plasticity-agent
Optional extras
The 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 |
From source
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 tests
Verify
python -c "from plasticity_agent import PlasticAgent; print('ok')"
plasticity --help
Quickstart
from 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 upgrade
agent.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.
Use cases & examples
Every snippet below is runnable. The repo's
examples/folder has 12 complete, self-contained scripts (uv run python examples/<name>.py).
1. Neuroplastic memory
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.
2. Memory quality scoring
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).
3. Hybrid lexical + vector retrieval
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.
4. LLM-powered upgrades
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 entailment
5. Reflection (Reflexion)
lesson = 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 time
Lesson types: success, failure, risk, preference, tool_use, reasoning.
6. Self-Refine
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)
7. Sleep / consolidation
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.
8. Advisory & opt-in self-healing
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 pkg
9. Critical reasoning market
from 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.
10. Skill library
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().
11. Energy report
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..100
12. Cross-run improvement metrics
agent.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.164): plasticity +11.5, contradiction -0.328, ...'
13. OpenTelemetry export
agent = PlasticAgent(name="copilot", otel=True) # every trace event -> an OTel span
Requires pip install "plasticity-agent[otel]". Local JSONL tracing keeps working regardless.
14. Framework adapters
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-AI
Command-line interface
A 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
FastAPI server
plasticity serve # http://127.0.0.1:8000
Endpoints: 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 stack
Streamlit dashboard
plasticity dashboard # http://localhost:8501
Pages: Overview · Memories · Memory Quality · Sleep Reports · Failure Diagnostics · Reasoning Market · Skills · Energy Report.
Configuration & storage
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)
Research foundation
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.
Safety
- 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.
Testing & development
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 + wheel
Roadmap
Shipped 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).
Contributing
Issues and PRs welcome. Please run ruff, mypy, and pytest before submitting:
uv run ruff check . && uv run mypy plasticity_agent && uv run pytest
Citation
@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}
}
License
MIT © 2026 Kayariyan28
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plasticity_agent-0.2.0.tar.gz.
File metadata
- Download URL: plasticity_agent-0.2.0.tar.gz
- Upload date:
- Size: 93.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
780b312ddb23c11c4ee9f27771dbf1bb7f41ade14889c7fe247df905c88366ff
|
|
| MD5 |
c1b034a6a952f5e53feb11c45cddb0bb
|
|
| BLAKE2b-256 |
3b1bc7ad09839a0f08ee464c5957e962d687943243b9b2456d8e4923a9e8d545
|
File details
Details for the file plasticity_agent-0.2.0-py3-none-any.whl.
File metadata
- Download URL: plasticity_agent-0.2.0-py3-none-any.whl
- Upload date:
- Size: 94.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a99036824b335f35f838e8f7313005cffd6a0493de6004d89adc8b64791a4b85
|
|
| MD5 |
5c155afe715c9bcd91bbd9440443791e
|
|
| BLAKE2b-256 |
4be4e8dcb3dc2409e69bdac5e9005105684db20ac771e2a49830703cad82ce11
|