experia 0.2.1__tar.gz
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.
- experia-0.2.1/.github/workflows/ci.yml +35 -0
- experia-0.2.1/.github/workflows/publish.yml +34 -0
- experia-0.2.1/.gitignore +165 -0
- experia-0.2.1/LICENSE +21 -0
- experia-0.2.1/PKG-INFO +102 -0
- experia-0.2.1/README.md +84 -0
- experia-0.2.1/experia/__init__.py +0 -0
- experia-0.2.1/experia/adapters/__init__.py +0 -0
- experia-0.2.1/experia/adapters/mem0.py +0 -0
- experia-0.2.1/experia/adapters/postgres.py +0 -0
- experia-0.2.1/experia/adapters/zep.py +0 -0
- experia-0.2.1/experia/context/__init__.py +0 -0
- experia-0.2.1/experia/context/builder.py +32 -0
- experia-0.2.1/experia/core/__init__.py +0 -0
- experia-0.2.1/experia/core/exceptions.py +22 -0
- experia-0.2.1/experia/core/interfaces.py +32 -0
- experia-0.2.1/experia/core/learner.py +85 -0
- experia-0.2.1/experia/core/logging.py +17 -0
- experia-0.2.1/experia/experience/__init__.py +0 -0
- experia-0.2.1/experia/experience/collector.py +0 -0
- experia-0.2.1/experia/experience/evaluator.py +38 -0
- experia-0.2.1/experia/experience/lessons.py +0 -0
- experia-0.2.1/experia/experience/llm_evaluator.py +86 -0
- experia-0.2.1/experia/experience/models.py +77 -0
- experia-0.2.1/experia/improvement/__init__.py +0 -0
- experia-0.2.1/experia/improvement/rules.py +71 -0
- experia-0.2.1/experia/improvement/strategies.py +0 -0
- experia-0.2.1/experia/integrations/__init__.py +0 -0
- experia-0.2.1/experia/integrations/langchain.py +0 -0
- experia-0.2.1/experia/integrations/langgraph.py +0 -0
- experia-0.2.1/experia/memory/__init__.py +0 -0
- experia-0.2.1/experia/memory/models.py +64 -0
- experia-0.2.1/experia/memory/store.py +224 -0
- experia-0.2.1/experia/reflection/__init__.py +0 -0
- experia-0.2.1/experia/reflection/conflict.py +0 -0
- experia-0.2.1/experia/reflection/consolidation.py +0 -0
- experia-0.2.1/idea.md +358 -0
- experia-0.2.1/pyproject.toml +47 -0
- experia-0.2.1/tests/__init__.py +0 -0
- experia-0.2.1/tests/test_learner.py +89 -0
- experia-0.2.1/tests/test_llm.py +94 -0
- experia-0.2.1/tests/test_store.py +69 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ "main" ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ "main" ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install -e ".[dev]"
|
|
28
|
+
|
|
29
|
+
- name: Lint with Ruff
|
|
30
|
+
run: |
|
|
31
|
+
ruff check .
|
|
32
|
+
|
|
33
|
+
- name: Test with pytest
|
|
34
|
+
run: |
|
|
35
|
+
pytest
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*.*.*' # Trigger only when a version tag (e.g., v0.1.0) is pushed
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
pypi-publish:
|
|
10
|
+
name: Build and publish to PyPI
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
# Required for OIDC Trusted Publishing
|
|
14
|
+
permissions:
|
|
15
|
+
id-token: write
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout code
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: '3.12'
|
|
26
|
+
|
|
27
|
+
- name: Install build tools
|
|
28
|
+
run: python -m pip install --upgrade pip build
|
|
29
|
+
|
|
30
|
+
- name: Build package
|
|
31
|
+
run: python -m build
|
|
32
|
+
|
|
33
|
+
- name: Publish to PyPI
|
|
34
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
experia-0.2.1/.gitignore
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
110
|
+
.pdm.toml
|
|
111
|
+
.pdm-python
|
|
112
|
+
.pdm-build/
|
|
113
|
+
|
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
115
|
+
__pypackages__/
|
|
116
|
+
|
|
117
|
+
# Celery stuff
|
|
118
|
+
celerybeat-schedule
|
|
119
|
+
celerybeat.pid
|
|
120
|
+
|
|
121
|
+
# SageMath parsed files
|
|
122
|
+
*.sage.py
|
|
123
|
+
|
|
124
|
+
# Environments
|
|
125
|
+
.env
|
|
126
|
+
.venv
|
|
127
|
+
env/
|
|
128
|
+
venv/
|
|
129
|
+
ENV/
|
|
130
|
+
env.bak/
|
|
131
|
+
venv.bak/
|
|
132
|
+
|
|
133
|
+
# Spyder project settings
|
|
134
|
+
.spyderproject
|
|
135
|
+
.spyproject
|
|
136
|
+
|
|
137
|
+
# Rope project settings
|
|
138
|
+
.ropeproject
|
|
139
|
+
|
|
140
|
+
# mkdocs documentation
|
|
141
|
+
/site
|
|
142
|
+
|
|
143
|
+
# mypy
|
|
144
|
+
.mypy_cache/
|
|
145
|
+
.dmypy.json
|
|
146
|
+
dmypy.json
|
|
147
|
+
|
|
148
|
+
# Pyre type checker
|
|
149
|
+
.pyre/
|
|
150
|
+
|
|
151
|
+
# pytype static type analyzer
|
|
152
|
+
.pytype/
|
|
153
|
+
|
|
154
|
+
# Cython debug symbols
|
|
155
|
+
cython_debug/
|
|
156
|
+
|
|
157
|
+
# PyCharm
|
|
158
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
159
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
160
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
161
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
162
|
+
.idea/
|
|
163
|
+
|
|
164
|
+
# Experia specific
|
|
165
|
+
*.db
|
experia-0.2.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Experia AI Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
experia-0.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: experia
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: The open-source experience learning layer for AI agents.
|
|
5
|
+
Author-email: Experia AI Contributors <hello@experia.ai>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: aiosqlite>=0.20.0
|
|
10
|
+
Requires-Dist: pydantic>=2.0.0
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
13
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
15
|
+
Provides-Extra: llm
|
|
16
|
+
Requires-Dist: litellm>=1.0.0; extra == 'llm'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# Experia AI
|
|
20
|
+
|
|
21
|
+
The open-source experience learning layer for AI agents.
|
|
22
|
+
|
|
23
|
+
Experia enables agents to learn from past actions, failures, and outcomes.
|
|
24
|
+
It provides experience capture, lesson extraction, behavioral improvement,
|
|
25
|
+
and long-term cognitive memory without replacing existing agent frameworks.
|
|
26
|
+
|
|
27
|
+
## Vision
|
|
28
|
+
|
|
29
|
+
Current AI agents start from zero on every interaction. Experia adds an **experience learning loop** around agents. It allows agents to remember what happened, understand why it worked or failed, and improve future decisions.
|
|
30
|
+
|
|
31
|
+
**Observation → Action → Result → Experience → Lesson → Memory → Better Future Action**
|
|
32
|
+
|
|
33
|
+
```mermaid
|
|
34
|
+
flowchart TD
|
|
35
|
+
subgraph Agent Application
|
|
36
|
+
Agent[AI Agent / LLM]
|
|
37
|
+
Task[Execute Task]
|
|
38
|
+
Agent -- Takes Action --> Task
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
subgraph Experia AI Cognitive Layer [Experia Async Cognitive Layer]
|
|
42
|
+
Store[(MemoryStore Protocol)]
|
|
43
|
+
Eval[Evaluator Protocol]
|
|
44
|
+
Ctx[Context Builder]
|
|
45
|
+
|
|
46
|
+
Task -- 1. await record() --> Store
|
|
47
|
+
Store -- 2. Analyze Experience --> Eval
|
|
48
|
+
Eval -- 3. Extract Lesson --> Store
|
|
49
|
+
Store -- 4. await retrieve_context() --> Ctx
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
Ctx -- 5. Inject Knowledge --> Agent
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Integrations
|
|
56
|
+
|
|
57
|
+
Experia acts as a cognitive plugin. It does not replace your agent frameworks (like LangChain, AutoGen, CrewAI), it enhances them by managing long-term memory, learned experiences, user knowledge, and behavioral patterns.
|
|
58
|
+
|
|
59
|
+
## Getting Started
|
|
60
|
+
|
|
61
|
+
Experia uses an **asynchronous** and **pluggable** architecture.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install experia
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import asyncio
|
|
69
|
+
from experia.core.learner import Learner
|
|
70
|
+
from experia.memory.store import SQLiteStore
|
|
71
|
+
from experia.experience.evaluator import SimpleHeuristicEvaluator
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
async def main():
|
|
75
|
+
# 1. Dependency Injection setup
|
|
76
|
+
store = SQLiteStore("my_agent.db")
|
|
77
|
+
await store.initialize()
|
|
78
|
+
|
|
79
|
+
evaluator = SimpleHeuristicEvaluator()
|
|
80
|
+
|
|
81
|
+
# 2. Initialize Learner
|
|
82
|
+
agent = Learner(store=store, evaluator=evaluator)
|
|
83
|
+
|
|
84
|
+
# 3. Use the async API to record actions
|
|
85
|
+
await agent.record(
|
|
86
|
+
task="Deploy web app",
|
|
87
|
+
action="Restart Nginx",
|
|
88
|
+
result="failed with config syntax error",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# 4. Retrieve memory context for your LLM
|
|
92
|
+
context = await agent.retrieve_context()
|
|
93
|
+
print(context)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == "__main__":
|
|
97
|
+
asyncio.run(main())
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
experia-0.2.1/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Experia AI
|
|
2
|
+
|
|
3
|
+
The open-source experience learning layer for AI agents.
|
|
4
|
+
|
|
5
|
+
Experia enables agents to learn from past actions, failures, and outcomes.
|
|
6
|
+
It provides experience capture, lesson extraction, behavioral improvement,
|
|
7
|
+
and long-term cognitive memory without replacing existing agent frameworks.
|
|
8
|
+
|
|
9
|
+
## Vision
|
|
10
|
+
|
|
11
|
+
Current AI agents start from zero on every interaction. Experia adds an **experience learning loop** around agents. It allows agents to remember what happened, understand why it worked or failed, and improve future decisions.
|
|
12
|
+
|
|
13
|
+
**Observation → Action → Result → Experience → Lesson → Memory → Better Future Action**
|
|
14
|
+
|
|
15
|
+
```mermaid
|
|
16
|
+
flowchart TD
|
|
17
|
+
subgraph Agent Application
|
|
18
|
+
Agent[AI Agent / LLM]
|
|
19
|
+
Task[Execute Task]
|
|
20
|
+
Agent -- Takes Action --> Task
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
subgraph Experia AI Cognitive Layer [Experia Async Cognitive Layer]
|
|
24
|
+
Store[(MemoryStore Protocol)]
|
|
25
|
+
Eval[Evaluator Protocol]
|
|
26
|
+
Ctx[Context Builder]
|
|
27
|
+
|
|
28
|
+
Task -- 1. await record() --> Store
|
|
29
|
+
Store -- 2. Analyze Experience --> Eval
|
|
30
|
+
Eval -- 3. Extract Lesson --> Store
|
|
31
|
+
Store -- 4. await retrieve_context() --> Ctx
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Ctx -- 5. Inject Knowledge --> Agent
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Integrations
|
|
38
|
+
|
|
39
|
+
Experia acts as a cognitive plugin. It does not replace your agent frameworks (like LangChain, AutoGen, CrewAI), it enhances them by managing long-term memory, learned experiences, user knowledge, and behavioral patterns.
|
|
40
|
+
|
|
41
|
+
## Getting Started
|
|
42
|
+
|
|
43
|
+
Experia uses an **asynchronous** and **pluggable** architecture.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install experia
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import asyncio
|
|
51
|
+
from experia.core.learner import Learner
|
|
52
|
+
from experia.memory.store import SQLiteStore
|
|
53
|
+
from experia.experience.evaluator import SimpleHeuristicEvaluator
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
async def main():
|
|
57
|
+
# 1. Dependency Injection setup
|
|
58
|
+
store = SQLiteStore("my_agent.db")
|
|
59
|
+
await store.initialize()
|
|
60
|
+
|
|
61
|
+
evaluator = SimpleHeuristicEvaluator()
|
|
62
|
+
|
|
63
|
+
# 2. Initialize Learner
|
|
64
|
+
agent = Learner(store=store, evaluator=evaluator)
|
|
65
|
+
|
|
66
|
+
# 3. Use the async API to record actions
|
|
67
|
+
await agent.record(
|
|
68
|
+
task="Deploy web app",
|
|
69
|
+
action="Restart Nginx",
|
|
70
|
+
result="failed with config syntax error",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# 4. Retrieve memory context for your LLM
|
|
74
|
+
context = await agent.retrieve_context()
|
|
75
|
+
print(context)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
asyncio.run(main())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from experia.memory.models import Memory
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ContextBuilder:
|
|
7
|
+
"""
|
|
8
|
+
Transforms raw memories into structured, usable intelligence for the agent.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
def format_for_prompt(self, memories: List[Memory]) -> str:
|
|
12
|
+
"""
|
|
13
|
+
Takes a list of memories and formats them into a text string
|
|
14
|
+
that can be injected into an LLM system prompt.
|
|
15
|
+
"""
|
|
16
|
+
if not memories:
|
|
17
|
+
return ""
|
|
18
|
+
|
|
19
|
+
context_lines = ["--- User Context & Learned Experience ---"]
|
|
20
|
+
|
|
21
|
+
# Group by type for better readability by the LLM
|
|
22
|
+
grouped_memories = {}
|
|
23
|
+
for mem in memories:
|
|
24
|
+
grouped_memories.setdefault(mem.type.value, []).append(mem)
|
|
25
|
+
|
|
26
|
+
for mem_type, type_memories in grouped_memories.items():
|
|
27
|
+
context_lines.append(f"\n[{mem_type.upper()}]")
|
|
28
|
+
for mem in type_memories:
|
|
29
|
+
context_lines.append(f"- {mem.content}")
|
|
30
|
+
|
|
31
|
+
context_lines.append("\n---------------------------------------")
|
|
32
|
+
return "\n".join(context_lines)
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class ExperiaError(Exception):
|
|
2
|
+
"""Base exception for all Experia errors."""
|
|
3
|
+
|
|
4
|
+
pass
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class StorageError(ExperiaError):
|
|
8
|
+
"""Raised when a storage operation fails."""
|
|
9
|
+
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class EvaluationError(ExperiaError):
|
|
14
|
+
"""Raised when an experience evaluation fails."""
|
|
15
|
+
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ConfigurationError(ExperiaError):
|
|
20
|
+
"""Raised when Experia is misconfigured."""
|
|
21
|
+
|
|
22
|
+
pass
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import List, Optional, Protocol
|
|
2
|
+
from uuid import UUID
|
|
3
|
+
|
|
4
|
+
from experia.experience.models import ExperienceRecord, Lesson
|
|
5
|
+
from experia.memory.models import Memory, MemoryType
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class MemoryStore(Protocol):
|
|
9
|
+
"""Protocol for memory and experience storage backends."""
|
|
10
|
+
|
|
11
|
+
async def save_experience(self, experience: ExperienceRecord) -> None: ...
|
|
12
|
+
|
|
13
|
+
async def get_experience(
|
|
14
|
+
self, experience_id: UUID
|
|
15
|
+
) -> Optional[ExperienceRecord]: ...
|
|
16
|
+
|
|
17
|
+
async def save_lesson(self, lesson: Lesson) -> None: ...
|
|
18
|
+
|
|
19
|
+
async def save_memory(self, memory: Memory) -> None: ...
|
|
20
|
+
|
|
21
|
+
async def search_memories(
|
|
22
|
+
self,
|
|
23
|
+
query: str = "",
|
|
24
|
+
memory_type: Optional[MemoryType] = None,
|
|
25
|
+
limit: int = 10,
|
|
26
|
+
) -> List[Memory]: ...
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Evaluator(Protocol):
|
|
30
|
+
"""Protocol for experience evaluators."""
|
|
31
|
+
|
|
32
|
+
async def evaluate(self, experience: ExperienceRecord) -> Optional[Lesson]: ...
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
|
|
3
|
+
from experia.context.builder import ContextBuilder
|
|
4
|
+
from experia.core.exceptions import ConfigurationError
|
|
5
|
+
from experia.core.interfaces import Evaluator, MemoryStore
|
|
6
|
+
from experia.core.logging import logger
|
|
7
|
+
from experia.experience.models import ExperienceRecord
|
|
8
|
+
from experia.improvement.rules import RuleGenerator
|
|
9
|
+
from experia.memory.models import Memory, MemoryType
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Learner:
|
|
13
|
+
"""
|
|
14
|
+
The main asynchronous entry point for the Experia AI Cognitive Layer.
|
|
15
|
+
Uses Dependency Injection to accept any MemoryStore and Evaluator implementations.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(
|
|
19
|
+
self,
|
|
20
|
+
store: MemoryStore,
|
|
21
|
+
evaluator: Evaluator,
|
|
22
|
+
rule_generator: Optional[RuleGenerator] = None,
|
|
23
|
+
):
|
|
24
|
+
if not store or not evaluator:
|
|
25
|
+
raise ConfigurationError("Learner requires both a store and an evaluator.")
|
|
26
|
+
|
|
27
|
+
self.store = store
|
|
28
|
+
self.evaluator = evaluator
|
|
29
|
+
self.rule_generator = rule_generator
|
|
30
|
+
self.context_builder = ContextBuilder()
|
|
31
|
+
logger.info("Experia Learner initialized successfully.")
|
|
32
|
+
|
|
33
|
+
async def record(
|
|
34
|
+
self,
|
|
35
|
+
task: str,
|
|
36
|
+
action: str,
|
|
37
|
+
result: str,
|
|
38
|
+
context: Optional[Dict[str, Any]] = None,
|
|
39
|
+
) -> ExperienceRecord:
|
|
40
|
+
"""Records an agent's action and its result asynchronously."""
|
|
41
|
+
experience = ExperienceRecord(
|
|
42
|
+
task=task, action=action, result=result, context=context or {}
|
|
43
|
+
)
|
|
44
|
+
await self.store.save_experience(experience)
|
|
45
|
+
logger.debug(f"Recorded experience {experience.id} for task '{task}'")
|
|
46
|
+
|
|
47
|
+
await self._evaluate_and_remember(experience)
|
|
48
|
+
return experience
|
|
49
|
+
|
|
50
|
+
async def _evaluate_and_remember(self, experience: ExperienceRecord) -> None:
|
|
51
|
+
"""Internal asynchronous method to evaluate an experience and store its lesson."""
|
|
52
|
+
lesson = await self.evaluator.evaluate(experience)
|
|
53
|
+
if lesson:
|
|
54
|
+
await self.store.save_lesson(lesson)
|
|
55
|
+
|
|
56
|
+
memory = Memory(
|
|
57
|
+
content=lesson.content,
|
|
58
|
+
type=MemoryType.LESSON,
|
|
59
|
+
confidence=lesson.confidence,
|
|
60
|
+
importance=0.7,
|
|
61
|
+
source=f"Experience:{experience.id}",
|
|
62
|
+
)
|
|
63
|
+
await self.store.save_memory(memory)
|
|
64
|
+
logger.info(
|
|
65
|
+
f"Learned and remembered lesson from experience {experience.id}"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Optionally generate a global rule
|
|
69
|
+
if self.rule_generator:
|
|
70
|
+
await self.rule_generator.consolidate_lesson(lesson)
|
|
71
|
+
|
|
72
|
+
async def retrieve_context(self, query: str = "", limit: int = 5) -> str:
|
|
73
|
+
"""Searches cognitive memory and builds a prompt string asynchronously."""
|
|
74
|
+
memories = await self.store.search_memories(query=query, limit=limit)
|
|
75
|
+
logger.debug(f"Retrieved {len(memories)} memories for context.")
|
|
76
|
+
return self.context_builder.format_for_prompt(memories)
|
|
77
|
+
|
|
78
|
+
async def remember(
|
|
79
|
+
self, content: str, memory_type: MemoryType = MemoryType.FACT
|
|
80
|
+
) -> Memory:
|
|
81
|
+
"""Manually add a piece of knowledge to the memory store asynchronously."""
|
|
82
|
+
memory = Memory(content=content, type=memory_type, importance=0.9)
|
|
83
|
+
await self.store.save_memory(memory)
|
|
84
|
+
logger.debug(f"Manually remembered explicit knowledge: {memory.id}")
|
|
85
|
+
return memory
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
# Configure the package-level logger
|
|
4
|
+
logger = logging.getLogger("experia")
|
|
5
|
+
|
|
6
|
+
# Prevent log propagation to the root logger by default to avoid duplicate logs
|
|
7
|
+
# if the user hasn't configured a handler.
|
|
8
|
+
logger.propagate = False
|
|
9
|
+
|
|
10
|
+
if not logger.handlers:
|
|
11
|
+
handler = logging.StreamHandler()
|
|
12
|
+
formatter = logging.Formatter(
|
|
13
|
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
14
|
+
)
|
|
15
|
+
handler.setFormatter(formatter)
|
|
16
|
+
logger.addHandler(handler)
|
|
17
|
+
logger.setLevel(logging.INFO)
|
|
File without changes
|
|
File without changes
|