plasticity-agent 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. plasticity_agent/__init__.py +139 -0
  2. plasticity_agent/adapters/__init__.py +17 -0
  3. plasticity_agent/adapters/crewai_adapter.py +38 -0
  4. plasticity_agent/adapters/generic.py +45 -0
  5. plasticity_agent/adapters/langgraph_adapter.py +39 -0
  6. plasticity_agent/adapters/openai_agents_adapter.py +38 -0
  7. plasticity_agent/adapters/pydantic_ai_adapter.py +38 -0
  8. plasticity_agent/cli.py +399 -0
  9. plasticity_agent/core/__init__.py +18 -0
  10. plasticity_agent/core/agent.py +365 -0
  11. plasticity_agent/core/config.py +63 -0
  12. plasticity_agent/core/events.py +62 -0
  13. plasticity_agent/core/runtime.py +108 -0
  14. plasticity_agent/core/trace.py +125 -0
  15. plasticity_agent/healing/__init__.py +22 -0
  16. plasticity_agent/healing/detector.py +38 -0
  17. plasticity_agent/healing/diagnosis.py +159 -0
  18. plasticity_agent/healing/repair.py +119 -0
  19. plasticity_agent/healing/sandbox.py +160 -0
  20. plasticity_agent/learning/__init__.py +21 -0
  21. plasticity_agent/learning/curriculum.py +60 -0
  22. plasticity_agent/learning/reward.py +46 -0
  23. plasticity_agent/learning/skill_library.py +222 -0
  24. plasticity_agent/llm/__init__.py +23 -0
  25. plasticity_agent/llm/client.py +145 -0
  26. plasticity_agent/memory/__init__.py +37 -0
  27. plasticity_agent/memory/consolidation.py +389 -0
  28. plasticity_agent/memory/contradiction.py +181 -0
  29. plasticity_agent/memory/embeddings.py +144 -0
  30. plasticity_agent/memory/forgetting.py +87 -0
  31. plasticity_agent/memory/memory_os.py +465 -0
  32. plasticity_agent/memory/retrieval.py +149 -0
  33. plasticity_agent/memory/salience.py +69 -0
  34. plasticity_agent/memory/schemas.py +101 -0
  35. plasticity_agent/memory/store.py +242 -0
  36. plasticity_agent/memory/vector_index.py +139 -0
  37. plasticity_agent/metrics/__init__.py +11 -0
  38. plasticity_agent/metrics/tracker.py +153 -0
  39. plasticity_agent/observability/__init__.py +7 -0
  40. plasticity_agent/observability/otel.py +53 -0
  41. plasticity_agent/reasoning/__init__.py +37 -0
  42. plasticity_agent/reasoning/auction.py +74 -0
  43. plasticity_agent/reasoning/confidence.py +46 -0
  44. plasticity_agent/reasoning/critic.py +55 -0
  45. plasticity_agent/reasoning/critics.py +236 -0
  46. plasticity_agent/reasoning/debate.py +89 -0
  47. plasticity_agent/reasoning/market.py +55 -0
  48. plasticity_agent/reflection/__init__.py +16 -0
  49. plasticity_agent/reflection/lessons.py +34 -0
  50. plasticity_agent/reflection/reflector.py +226 -0
  51. plasticity_agent/reflection/self_refine.py +137 -0
  52. plasticity_agent/server/__init__.py +12 -0
  53. plasticity_agent/server/api.py +129 -0
  54. plasticity_agent/server/dashboard.py +163 -0
  55. plasticity_agent/thermodynamics/__init__.py +26 -0
  56. plasticity_agent/thermodynamics/energy_report.py +123 -0
  57. plasticity_agent/thermodynamics/entropy.py +43 -0
  58. plasticity_agent/thermodynamics/free_energy.py +69 -0
  59. plasticity_agent-0.2.0.dist-info/METADATA +591 -0
  60. plasticity_agent-0.2.0.dist-info/RECORD +63 -0
  61. plasticity_agent-0.2.0.dist-info/WHEEL +4 -0
  62. plasticity_agent-0.2.0.dist-info/entry_points.txt +2 -0
  63. plasticity_agent-0.2.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,139 @@
1
+ """Plasticity Agent Runtime.
2
+
3
+ Neuroplastic memory, self-healing, and critical reasoning for AI agents.
4
+
5
+ A local-first, framework-agnostic runtime that gives agents an evolving memory,
6
+ sleep-like consolidation, reflection, advisory self-healing, a critic-driven
7
+ reasoning market, a skill library, and thermodynamic-style reliability reporting.
8
+
9
+ Scientific framings (complementary learning systems, synaptic homeostasis,
10
+ Reflexion, Self-Refine, Voyager-style skills, auction theory, the free-energy
11
+ principle) are used as *software metaphors and design principles* — not claims
12
+ of biological equivalence or consciousness.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ __version__ = "0.2.0"
18
+
19
+ from plasticity_agent.core.agent import PlasticAgent
20
+ from plasticity_agent.core.config import PlasticityConfig
21
+ from plasticity_agent.core.events import TraceEvent
22
+ from plasticity_agent.core.runtime import RunResult, Runtime
23
+ from plasticity_agent.core.trace import Tracer
24
+ from plasticity_agent.healing.detector import FailureDetector, detect_failures
25
+ from plasticity_agent.healing.diagnosis import FailureDiagnosis, diagnose
26
+ from plasticity_agent.healing.repair import RepairPlan, heal, plan_repair
27
+ from plasticity_agent.healing.sandbox import RepairConsent, Sandbox, SandboxResult
28
+ from plasticity_agent.learning.curriculum import Curriculum, CurriculumItem
29
+ from plasticity_agent.learning.reward import normalize_reward, shape_reward
30
+ from plasticity_agent.learning.skill_library import Skill, SkillLibrary
31
+ from plasticity_agent.llm.client import LLMClient, coerce_llm
32
+ from plasticity_agent.memory.consolidation import SleepReport
33
+ from plasticity_agent.memory.contradiction import ContradictionChecker, detect_contradiction
34
+ from plasticity_agent.memory.embeddings import (
35
+ EmbeddingBackend,
36
+ HashingEmbeddingBackend,
37
+ SentenceTransformerBackend,
38
+ get_embedder,
39
+ )
40
+ from plasticity_agent.memory.memory_os import (
41
+ MemoryOS,
42
+ compute_utility_score,
43
+ score_memory_quality,
44
+ )
45
+ from plasticity_agent.memory.salience import calculate_salience
46
+ from plasticity_agent.memory.schemas import (
47
+ Memory,
48
+ MemoryQualityReport,
49
+ MemorySearchResult,
50
+ )
51
+ from plasticity_agent.memory.vector_index import VectorIndex
52
+ from plasticity_agent.metrics.tracker import (
53
+ ImprovementReport,
54
+ ImprovementTracker,
55
+ MetricSnapshot,
56
+ )
57
+ from plasticity_agent.observability.otel import OTelExporter
58
+ from plasticity_agent.reasoning.auction import AuctionResult, run_auction, score_proposal
59
+ from plasticity_agent.reasoning.critic import Critic, Proposal
60
+ from plasticity_agent.reasoning.critics import LLMCritic
61
+ from plasticity_agent.reasoning.debate import Debate, DebateResult
62
+ from plasticity_agent.reasoning.market import ReasoningMarket
63
+ from plasticity_agent.reflection.lessons import Lesson, ReflectionInput
64
+ from plasticity_agent.reflection.reflector import Reflector
65
+ from plasticity_agent.reflection.self_refine import SelfRefine, SelfRefineResult
66
+ from plasticity_agent.thermodynamics.energy_report import EnergyReport, build_energy_report
67
+
68
+ __all__ = [
69
+ "__version__",
70
+ # core
71
+ "PlasticAgent",
72
+ "PlasticityConfig",
73
+ "Runtime",
74
+ "RunResult",
75
+ "Tracer",
76
+ "TraceEvent",
77
+ # memory
78
+ "MemoryOS",
79
+ "Memory",
80
+ "MemoryQualityReport",
81
+ "MemorySearchResult",
82
+ "SleepReport",
83
+ "calculate_salience",
84
+ "detect_contradiction",
85
+ "ContradictionChecker",
86
+ "compute_utility_score",
87
+ "score_memory_quality",
88
+ # retrieval / embeddings
89
+ "EmbeddingBackend",
90
+ "HashingEmbeddingBackend",
91
+ "SentenceTransformerBackend",
92
+ "get_embedder",
93
+ "VectorIndex",
94
+ # llm
95
+ "LLMClient",
96
+ "coerce_llm",
97
+ # reflection
98
+ "Reflector",
99
+ "Lesson",
100
+ "ReflectionInput",
101
+ "SelfRefine",
102
+ "SelfRefineResult",
103
+ # healing
104
+ "FailureDiagnosis",
105
+ "diagnose",
106
+ "RepairPlan",
107
+ "plan_repair",
108
+ "heal",
109
+ "Sandbox",
110
+ "SandboxResult",
111
+ "RepairConsent",
112
+ "FailureDetector",
113
+ "detect_failures",
114
+ # reasoning
115
+ "ReasoningMarket",
116
+ "Proposal",
117
+ "Critic",
118
+ "LLMCritic",
119
+ "AuctionResult",
120
+ "run_auction",
121
+ "score_proposal",
122
+ "Debate",
123
+ "DebateResult",
124
+ # learning
125
+ "Skill",
126
+ "SkillLibrary",
127
+ "shape_reward",
128
+ "normalize_reward",
129
+ "Curriculum",
130
+ "CurriculumItem",
131
+ # thermodynamics
132
+ "EnergyReport",
133
+ "build_energy_report",
134
+ # metrics & observability
135
+ "ImprovementTracker",
136
+ "MetricSnapshot",
137
+ "ImprovementReport",
138
+ "OTelExporter",
139
+ ]
@@ -0,0 +1,17 @@
1
+ """Framework adapters (the framework-specific ones are experimental)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from plasticity_agent.adapters.crewai_adapter import CrewAIAdapter
6
+ from plasticity_agent.adapters.generic import GenericAdapter
7
+ from plasticity_agent.adapters.langgraph_adapter import LangGraphAdapter
8
+ from plasticity_agent.adapters.openai_agents_adapter import OpenAIAgentsAdapter
9
+ from plasticity_agent.adapters.pydantic_ai_adapter import PydanticAIAdapter
10
+
11
+ __all__ = [
12
+ "GenericAdapter",
13
+ "LangGraphAdapter",
14
+ "CrewAIAdapter",
15
+ "OpenAIAgentsAdapter",
16
+ "PydanticAIAdapter",
17
+ ]
@@ -0,0 +1,38 @@
1
+ """CrewAI adapter (experimental).
2
+
3
+ Bridges a CrewAI crew to a :class:`PlasticAgent`. ``crewai`` is an optional
4
+ dependency; a clear error is raised if it is missing.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from collections.abc import Callable
10
+ from typing import Any
11
+
12
+ from plasticity_agent.adapters.generic import GenericAdapter
13
+ from plasticity_agent.core.runtime import RunResult
14
+
15
+
16
+ class CrewAIAdapter:
17
+ """Experimental bridge between CrewAI and Plasticity."""
18
+
19
+ def __init__(self, agent: Any) -> None:
20
+ self.agent = agent
21
+ self._generic = GenericAdapter(agent)
22
+
23
+ @staticmethod
24
+ def _require() -> Any:
25
+ try:
26
+ import crewai # noqa: F401
27
+ except ImportError as exc: # pragma: no cover - depends on optional dep
28
+ raise ImportError(
29
+ "CrewAIAdapter requires the optional 'crewai' package "
30
+ "(experimental). Install it with `uv add crewai`."
31
+ ) from exc
32
+ return crewai
33
+
34
+ def wrap(self, crew: Any, method: str = "kickoff") -> Callable[..., RunResult]:
35
+ """Wrap ``crew.kickoff`` (or another method) through the agent runtime."""
36
+
37
+ self._require()
38
+ return self._generic.wrap_agent(crew, method=method)
@@ -0,0 +1,45 @@
1
+ """The generic adapter.
2
+
3
+ Framework-agnostic glue: wrap any Python callable or any object exposing a
4
+ ``run``-like method so it gains Plasticity tracing, an episodic memory of each
5
+ invocation, and advisory healing on failure. The framework-specific adapters
6
+ build on this.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ from collections.abc import Callable
12
+ from typing import Any
13
+
14
+ from plasticity_agent.core.runtime import RunResult
15
+
16
+
17
+ class GenericAdapter:
18
+ """Wrap callables/agents so their runs flow through a :class:`PlasticAgent`."""
19
+
20
+ def __init__(self, agent: Any) -> None:
21
+ self.agent = agent
22
+
23
+ def wrap_callable(
24
+ self, fn: Callable[..., Any], *, reflect_on_failure: bool = False
25
+ ) -> Callable[..., RunResult]:
26
+ """Return a wrapper that runs ``fn`` through the agent runtime."""
27
+
28
+ def wrapped(*args: Any, **kwargs: Any) -> RunResult:
29
+ result = self.agent.run(lambda: fn(*args, **kwargs))
30
+ if result.status == "failed" and reflect_on_failure:
31
+ self.agent.reflect(task=result.task, error=result.error, reward=-1.0)
32
+ return result
33
+
34
+ wrapped.__name__ = getattr(fn, "__name__", "wrapped_callable")
35
+ return wrapped
36
+
37
+ def wrap_agent(self, external_agent: Any, method: str = "run") -> Callable[..., RunResult]:
38
+ """Wrap an external agent object's ``method`` (default ``run``)."""
39
+
40
+ target = getattr(external_agent, method, None)
41
+ if not callable(target):
42
+ raise AttributeError(
43
+ f"external agent has no callable '{method}' method to wrap"
44
+ )
45
+ return self.wrap_callable(target)
@@ -0,0 +1,39 @@
1
+ """LangGraph adapter (experimental).
2
+
3
+ Bridges a compiled LangGraph graph to a :class:`PlasticAgent` so each graph
4
+ invocation is traced and remembered. ``langgraph`` is an optional dependency;
5
+ this adapter raises a clear, actionable error if it is not installed.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from collections.abc import Callable
11
+ from typing import Any
12
+
13
+ from plasticity_agent.adapters.generic import GenericAdapter
14
+ from plasticity_agent.core.runtime import RunResult
15
+
16
+
17
+ class LangGraphAdapter:
18
+ """Experimental bridge between LangGraph and Plasticity."""
19
+
20
+ def __init__(self, agent: Any) -> None:
21
+ self.agent = agent
22
+ self._generic = GenericAdapter(agent)
23
+
24
+ @staticmethod
25
+ def _require() -> Any:
26
+ try:
27
+ import langgraph # noqa: F401
28
+ except ImportError as exc: # pragma: no cover - depends on optional dep
29
+ raise ImportError(
30
+ "LangGraphAdapter requires the optional 'langgraph' package "
31
+ "(experimental). Install it with `uv add langgraph`."
32
+ ) from exc
33
+ return langgraph
34
+
35
+ def wrap(self, graph: Any, method: str = "invoke") -> Callable[..., RunResult]:
36
+ """Wrap ``graph.invoke`` (or another method) through the agent runtime."""
37
+
38
+ self._require()
39
+ return self._generic.wrap_agent(graph, method=method)
@@ -0,0 +1,38 @@
1
+ """OpenAI Agents SDK adapter (experimental).
2
+
3
+ Bridges an OpenAI Agents SDK ``Agent``/``Runner`` to a :class:`PlasticAgent`.
4
+ ``openai-agents`` is an optional dependency; a clear error is raised if missing.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from collections.abc import Callable
10
+ from typing import Any
11
+
12
+ from plasticity_agent.adapters.generic import GenericAdapter
13
+ from plasticity_agent.core.runtime import RunResult
14
+
15
+
16
+ class OpenAIAgentsAdapter:
17
+ """Experimental bridge between the OpenAI Agents SDK and Plasticity."""
18
+
19
+ def __init__(self, agent: Any) -> None:
20
+ self.agent = agent
21
+ self._generic = GenericAdapter(agent)
22
+
23
+ @staticmethod
24
+ def _require() -> Any:
25
+ try:
26
+ import agents # noqa: F401 (the `openai-agents` package imports as `agents`)
27
+ except ImportError as exc: # pragma: no cover - depends on optional dep
28
+ raise ImportError(
29
+ "OpenAIAgentsAdapter requires the optional 'openai-agents' package "
30
+ "(experimental). Install it with `uv add openai-agents`."
31
+ ) from exc
32
+ return agents
33
+
34
+ def wrap(self, runner: Any, method: str = "run") -> Callable[..., RunResult]:
35
+ """Wrap a runner's ``run`` (or another method) through the agent runtime."""
36
+
37
+ self._require()
38
+ return self._generic.wrap_agent(runner, method=method)
@@ -0,0 +1,38 @@
1
+ """Pydantic AI adapter (experimental).
2
+
3
+ Bridges a Pydantic AI ``Agent`` to a :class:`PlasticAgent`. ``pydantic-ai`` is
4
+ an optional dependency; a clear error is raised if it is missing.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from collections.abc import Callable
10
+ from typing import Any
11
+
12
+ from plasticity_agent.adapters.generic import GenericAdapter
13
+ from plasticity_agent.core.runtime import RunResult
14
+
15
+
16
+ class PydanticAIAdapter:
17
+ """Experimental bridge between Pydantic AI and Plasticity."""
18
+
19
+ def __init__(self, agent: Any) -> None:
20
+ self.agent = agent
21
+ self._generic = GenericAdapter(agent)
22
+
23
+ @staticmethod
24
+ def _require() -> Any:
25
+ try:
26
+ import pydantic_ai # noqa: F401
27
+ except ImportError as exc: # pragma: no cover - depends on optional dep
28
+ raise ImportError(
29
+ "PydanticAIAdapter requires the optional 'pydantic-ai' package "
30
+ "(experimental). Install it with `uv add pydantic-ai`."
31
+ ) from exc
32
+ return pydantic_ai
33
+
34
+ def wrap(self, pydantic_agent: Any, method: str = "run_sync") -> Callable[..., RunResult]:
35
+ """Wrap a Pydantic AI agent's ``run_sync`` (or another method)."""
36
+
37
+ self._require()
38
+ return self._generic.wrap_agent(pydantic_agent, method=method)