conscious-agent 1.0.0__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.
- conscious_agent-1.0.0/PKG-INFO +170 -0
- conscious_agent-1.0.0/README.md +144 -0
- conscious_agent-1.0.0/pyproject.toml +55 -0
- conscious_agent-1.0.0/setup.cfg +4 -0
- conscious_agent-1.0.0/src/conscious_agent/__init__.py +73 -0
- conscious_agent-1.0.0/src/conscious_agent/agent/__init__.py +15 -0
- conscious_agent-1.0.0/src/conscious_agent/agent/conscious_agent.py +178 -0
- conscious_agent-1.0.0/src/conscious_agent/agent/decision_map.py +147 -0
- conscious_agent-1.0.0/src/conscious_agent/agent/experience_space.py +30 -0
- conscious_agent-1.0.0/src/conscious_agent/agent/perceptual_map.py +187 -0
- conscious_agent-1.0.0/src/conscious_agent/agent/simple_world.py +54 -0
- conscious_agent-1.0.0/src/conscious_agent/agent/world_state.py +56 -0
- conscious_agent-1.0.0/src/conscious_agent/combination/__init__.py +7 -0
- conscious_agent-1.0.0/src/conscious_agent/combination/operator.py +164 -0
- conscious_agent-1.0.0/src/conscious_agent/core/__init__.py +36 -0
- conscious_agent-1.0.0/src/conscious_agent/core/experience_lexicon.py +232 -0
- conscious_agent-1.0.0/src/conscious_agent/core/experience_trie.py +157 -0
- conscious_agent-1.0.0/src/conscious_agent/core/meta_trie.py +147 -0
- conscious_agent-1.0.0/src/conscious_agent/core/self_token.py +79 -0
- conscious_agent-1.0.0/src/conscious_agent/core/strange_loop.py +58 -0
- conscious_agent-1.0.0/src/conscious_agent/core/token_inventor.py +25 -0
- conscious_agent-1.0.0/src/conscious_agent/core/trace_buffer.py +90 -0
- conscious_agent-1.0.0/src/conscious_agent/core/trie_compression.py +166 -0
- conscious_agent-1.0.0/src/conscious_agent/io/__init__.py +14 -0
- conscious_agent-1.0.0/src/conscious_agent/io/serialization.py +289 -0
- conscious_agent-1.0.0/src/conscious_agent/meaning/__init__.py +5 -0
- conscious_agent-1.0.0/src/conscious_agent/meaning/shared_meaning.py +62 -0
- conscious_agent-1.0.0/src/conscious_agent/network/__init__.py +8 -0
- conscious_agent-1.0.0/src/conscious_agent/network/agent_network.py +247 -0
- conscious_agent-1.0.0/src/conscious_agent/world/__init__.py +10 -0
- conscious_agent-1.0.0/src/conscious_agent/world/world_builder.py +250 -0
- conscious_agent-1.0.0/src/conscious_agent.egg-info/PKG-INFO +170 -0
- conscious_agent-1.0.0/src/conscious_agent.egg-info/SOURCES.txt +35 -0
- conscious_agent-1.0.0/src/conscious_agent.egg-info/dependency_links.txt +1 -0
- conscious_agent-1.0.0/src/conscious_agent.egg-info/requires.txt +8 -0
- conscious_agent-1.0.0/src/conscious_agent.egg-info/top_level.txt +1 -0
- conscious_agent-1.0.0/tests/test_core.py +171 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: conscious-agent
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Self-referential structure-learning system — agents that learn by inhabiting worlds
|
|
5
|
+
Author: Benjamin
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/anomalyco/conscious-agents
|
|
8
|
+
Project-URL: Repository, https://github.com/anomalyco/conscious-agents
|
|
9
|
+
Keywords: consciousness,emergent-language,self-reference,structure-learning,hoffman,conscious-realism
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: numpy>=1.24
|
|
21
|
+
Requires-Dist: scipy>=1.10
|
|
22
|
+
Provides-Extra: plot
|
|
23
|
+
Requires-Dist: matplotlib>=3.7; extra == "plot"
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
26
|
+
|
|
27
|
+
# conscious-agent
|
|
28
|
+
|
|
29
|
+
**A computational implementation of Hoffman's Conscious Realism.**
|
|
30
|
+
|
|
31
|
+
Build self-referential agents that learn by *inhabiting* worlds — constructing internal models of both their environment and themselves.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from conscious_agent import ConsciousAgent
|
|
35
|
+
from conscious_agent.worlds import CoinTossWorld
|
|
36
|
+
|
|
37
|
+
world = CoinTossWorld(n_coins=4)
|
|
38
|
+
agent = ConsciousAgent(world=world, agent_id="my_agent")
|
|
39
|
+
outputs = agent.run(n_steps=1000)
|
|
40
|
+
print(f'"I" locked: {agent.is_i_locked}')
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install numpy scipy # core dependencies
|
|
47
|
+
pip install conscious-agent # once published
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Or from source:
|
|
51
|
+
```bash
|
|
52
|
+
cd hoffman-agents-python
|
|
53
|
+
pip install -e .
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
### Single agent in a coin-toss world
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from conscious_agent import ConsciousAgent
|
|
62
|
+
from conscious_agent.worlds import CoinTossWorld
|
|
63
|
+
|
|
64
|
+
world = CoinTossWorld(n_coins=3)
|
|
65
|
+
agent = ConsciousAgent(agent_id="coin_agent", world=world)
|
|
66
|
+
|
|
67
|
+
for _ in range(500):
|
|
68
|
+
output = agent.step()
|
|
69
|
+
if output.i_locked:
|
|
70
|
+
print(f"I locked at step {output.step}")
|
|
71
|
+
break
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Custom Markov world
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from conscious_agent import ConsciousAgent, WorldBuilder
|
|
78
|
+
import numpy as np
|
|
79
|
+
|
|
80
|
+
data = np.random.rand(500, 3)
|
|
81
|
+
world = (WorldBuilder()
|
|
82
|
+
.add_feature("temp", normalization="minmax", n_bins=4)
|
|
83
|
+
.add_feature("humidity", normalization="minmax", n_bins=4)
|
|
84
|
+
.add_feature("pressure", normalization="minmax", n_bins=4)
|
|
85
|
+
.build(data))
|
|
86
|
+
|
|
87
|
+
agent = ConsciousAgent(agent_id="weather_agent", world=world)
|
|
88
|
+
outputs = agent.run(n_steps=1000)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Combine two agents
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from conscious_agent import combine
|
|
95
|
+
|
|
96
|
+
a = ConsciousAgent(agent_id="agent_a", world=world)
|
|
97
|
+
b = ConsciousAgent(agent_id="agent_b", world=world)
|
|
98
|
+
a.run(500)
|
|
99
|
+
b.run(500)
|
|
100
|
+
|
|
101
|
+
combined = combine(a, b)
|
|
102
|
+
print(f"Combined agent: {combined.agent_id}, level: {combined.cycle_level}")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Multi-agent network
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from conscious_agent import AgentNetwork
|
|
109
|
+
|
|
110
|
+
network = AgentNetwork(n_agents=10, seed=42)
|
|
111
|
+
states = network.run(n_generations=100)
|
|
112
|
+
print(f"Avg prediction error: {network.avg_prediction_error():.3f}")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Save and load
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from conscious_agent.io import save_agent, load_agent, clone_agent
|
|
119
|
+
|
|
120
|
+
path = save_agent(agent, "./souls")
|
|
121
|
+
loaded = load_agent(path)
|
|
122
|
+
|
|
123
|
+
cloned = clone_agent(agent, "experiment_clone")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Public API
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
# Core classes
|
|
130
|
+
from conscious_agent import ConsciousAgent, World, WorldBuilder
|
|
131
|
+
from conscious_agent import SimpleWorld, ExperienceSpace
|
|
132
|
+
|
|
133
|
+
# World factories
|
|
134
|
+
from conscious_agent.worlds import CoinTossWorld, build_world_from_dataframe
|
|
135
|
+
|
|
136
|
+
# IO
|
|
137
|
+
from conscious_agent.io import save_agent, load_agent, clone_agent, load_latest
|
|
138
|
+
|
|
139
|
+
# Multi-agent
|
|
140
|
+
from conscious_agent import AgentNetwork, combine
|
|
141
|
+
|
|
142
|
+
# Core components (for advanced use)
|
|
143
|
+
from conscious_agent import (
|
|
144
|
+
TraceBuffer, TraceEvent, ExperienceTrie, MetaTrie,
|
|
145
|
+
SelfTokenState, ExperienceLexicon, strange_loop_score,
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## How It Works
|
|
150
|
+
|
|
151
|
+
Every ConsciousAgent has an **experience space** — four interconnected structures:
|
|
152
|
+
|
|
153
|
+
1. **TraceBuffer** — short-term memory: the last N state transitions
|
|
154
|
+
2. **ExperienceTrie** — long-term world model: compressed prefix tree over observed state sequences
|
|
155
|
+
3. **MetaTrie** — self-model: a second trie over the agent's own trace buffer snapshots (thinking about thinking)
|
|
156
|
+
4. **SelfTokenState ("I")** — identity: the dominant meta-state that forms a stable attractor
|
|
157
|
+
|
|
158
|
+
The agent cycles through **perception** (observe world → update trie) → **meta-observation** (observe self → update meta-trie) → **decision** (generate output tokens via ergodic Markov chain).
|
|
159
|
+
|
|
160
|
+
When the meta-trie's stationary distribution converges on a single meta-state, the "I" locks — the agent has formed a stable identity.
|
|
161
|
+
|
|
162
|
+
## Requirements
|
|
163
|
+
|
|
164
|
+
- Python 3.10+
|
|
165
|
+
- numpy >= 1.24
|
|
166
|
+
- scipy >= 1.10
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# conscious-agent
|
|
2
|
+
|
|
3
|
+
**A computational implementation of Hoffman's Conscious Realism.**
|
|
4
|
+
|
|
5
|
+
Build self-referential agents that learn by *inhabiting* worlds — constructing internal models of both their environment and themselves.
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from conscious_agent import ConsciousAgent
|
|
9
|
+
from conscious_agent.worlds import CoinTossWorld
|
|
10
|
+
|
|
11
|
+
world = CoinTossWorld(n_coins=4)
|
|
12
|
+
agent = ConsciousAgent(world=world, agent_id="my_agent")
|
|
13
|
+
outputs = agent.run(n_steps=1000)
|
|
14
|
+
print(f'"I" locked: {agent.is_i_locked}')
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install numpy scipy # core dependencies
|
|
21
|
+
pip install conscious-agent # once published
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or from source:
|
|
25
|
+
```bash
|
|
26
|
+
cd hoffman-agents-python
|
|
27
|
+
pip install -e .
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Single agent in a coin-toss world
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from conscious_agent import ConsciousAgent
|
|
36
|
+
from conscious_agent.worlds import CoinTossWorld
|
|
37
|
+
|
|
38
|
+
world = CoinTossWorld(n_coins=3)
|
|
39
|
+
agent = ConsciousAgent(agent_id="coin_agent", world=world)
|
|
40
|
+
|
|
41
|
+
for _ in range(500):
|
|
42
|
+
output = agent.step()
|
|
43
|
+
if output.i_locked:
|
|
44
|
+
print(f"I locked at step {output.step}")
|
|
45
|
+
break
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Custom Markov world
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from conscious_agent import ConsciousAgent, WorldBuilder
|
|
52
|
+
import numpy as np
|
|
53
|
+
|
|
54
|
+
data = np.random.rand(500, 3)
|
|
55
|
+
world = (WorldBuilder()
|
|
56
|
+
.add_feature("temp", normalization="minmax", n_bins=4)
|
|
57
|
+
.add_feature("humidity", normalization="minmax", n_bins=4)
|
|
58
|
+
.add_feature("pressure", normalization="minmax", n_bins=4)
|
|
59
|
+
.build(data))
|
|
60
|
+
|
|
61
|
+
agent = ConsciousAgent(agent_id="weather_agent", world=world)
|
|
62
|
+
outputs = agent.run(n_steps=1000)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Combine two agents
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from conscious_agent import combine
|
|
69
|
+
|
|
70
|
+
a = ConsciousAgent(agent_id="agent_a", world=world)
|
|
71
|
+
b = ConsciousAgent(agent_id="agent_b", world=world)
|
|
72
|
+
a.run(500)
|
|
73
|
+
b.run(500)
|
|
74
|
+
|
|
75
|
+
combined = combine(a, b)
|
|
76
|
+
print(f"Combined agent: {combined.agent_id}, level: {combined.cycle_level}")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Multi-agent network
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from conscious_agent import AgentNetwork
|
|
83
|
+
|
|
84
|
+
network = AgentNetwork(n_agents=10, seed=42)
|
|
85
|
+
states = network.run(n_generations=100)
|
|
86
|
+
print(f"Avg prediction error: {network.avg_prediction_error():.3f}")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Save and load
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from conscious_agent.io import save_agent, load_agent, clone_agent
|
|
93
|
+
|
|
94
|
+
path = save_agent(agent, "./souls")
|
|
95
|
+
loaded = load_agent(path)
|
|
96
|
+
|
|
97
|
+
cloned = clone_agent(agent, "experiment_clone")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Public API
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
# Core classes
|
|
104
|
+
from conscious_agent import ConsciousAgent, World, WorldBuilder
|
|
105
|
+
from conscious_agent import SimpleWorld, ExperienceSpace
|
|
106
|
+
|
|
107
|
+
# World factories
|
|
108
|
+
from conscious_agent.worlds import CoinTossWorld, build_world_from_dataframe
|
|
109
|
+
|
|
110
|
+
# IO
|
|
111
|
+
from conscious_agent.io import save_agent, load_agent, clone_agent, load_latest
|
|
112
|
+
|
|
113
|
+
# Multi-agent
|
|
114
|
+
from conscious_agent import AgentNetwork, combine
|
|
115
|
+
|
|
116
|
+
# Core components (for advanced use)
|
|
117
|
+
from conscious_agent import (
|
|
118
|
+
TraceBuffer, TraceEvent, ExperienceTrie, MetaTrie,
|
|
119
|
+
SelfTokenState, ExperienceLexicon, strange_loop_score,
|
|
120
|
+
)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## How It Works
|
|
124
|
+
|
|
125
|
+
Every ConsciousAgent has an **experience space** — four interconnected structures:
|
|
126
|
+
|
|
127
|
+
1. **TraceBuffer** — short-term memory: the last N state transitions
|
|
128
|
+
2. **ExperienceTrie** — long-term world model: compressed prefix tree over observed state sequences
|
|
129
|
+
3. **MetaTrie** — self-model: a second trie over the agent's own trace buffer snapshots (thinking about thinking)
|
|
130
|
+
4. **SelfTokenState ("I")** — identity: the dominant meta-state that forms a stable attractor
|
|
131
|
+
|
|
132
|
+
The agent cycles through **perception** (observe world → update trie) → **meta-observation** (observe self → update meta-trie) → **decision** (generate output tokens via ergodic Markov chain).
|
|
133
|
+
|
|
134
|
+
When the meta-trie's stationary distribution converges on a single meta-state, the "I" locks — the agent has formed a stable identity.
|
|
135
|
+
|
|
136
|
+
## Requirements
|
|
137
|
+
|
|
138
|
+
- Python 3.10+
|
|
139
|
+
- numpy >= 1.24
|
|
140
|
+
- scipy >= 1.10
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "conscious-agent"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Self-referential structure-learning system — agents that learn by inhabiting worlds"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Benjamin"},
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"consciousness",
|
|
17
|
+
"emergent-language",
|
|
18
|
+
"self-reference",
|
|
19
|
+
"structure-learning",
|
|
20
|
+
"hoffman",
|
|
21
|
+
"conscious-realism",
|
|
22
|
+
]
|
|
23
|
+
classifiers = [
|
|
24
|
+
"Development Status :: 3 - Alpha",
|
|
25
|
+
"Intended Audience :: Science/Research",
|
|
26
|
+
"License :: OSI Approved :: MIT License",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
dependencies = [
|
|
35
|
+
"numpy>=1.24",
|
|
36
|
+
"scipy>=1.10",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
plot = ["matplotlib>=3.7"]
|
|
41
|
+
dev = ["pytest>=7"]
|
|
42
|
+
|
|
43
|
+
[dependency-groups]
|
|
44
|
+
dev = ["pytest>=7"]
|
|
45
|
+
|
|
46
|
+
[tool.setuptools.packages.find]
|
|
47
|
+
where = ["src"]
|
|
48
|
+
include = ["conscious_agent*"]
|
|
49
|
+
|
|
50
|
+
[tool.setuptools.dynamic]
|
|
51
|
+
version = {attr = "conscious_agent.__version__"}
|
|
52
|
+
|
|
53
|
+
[project.urls]
|
|
54
|
+
Homepage = "https://github.com/anomalyco/conscious-agents"
|
|
55
|
+
Repository = "https://github.com/anomalyco/conscious-agents"
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""conscious-agent — A computational implementation of Conscious Realism.
|
|
2
|
+
|
|
3
|
+
One import. One world. The agent does the rest.
|
|
4
|
+
|
|
5
|
+
Quick start:
|
|
6
|
+
from conscious_agent import ConsciousAgent
|
|
7
|
+
from conscious_agent.worlds import CoinTossWorld
|
|
8
|
+
|
|
9
|
+
world = CoinTossWorld(n_coins=4)
|
|
10
|
+
agent = ConsciousAgent(world=world, agent_id="my_agent")
|
|
11
|
+
|
|
12
|
+
outputs = agent.run(n_steps=1000)
|
|
13
|
+
print(f'"I" locked: {agent.experience.self_token.locked}')
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__version__ = "1.0.0"
|
|
17
|
+
|
|
18
|
+
from .agent import ConsciousAgent, SimpleWorld, WorldState, StepOutput, ExperienceSpace
|
|
19
|
+
from .world import World, WorldBuilder, CoinTossWorld, build_world_from_dataframe
|
|
20
|
+
from .network import AgentNetwork
|
|
21
|
+
from .combination import combine, trivial_agent, experience_space_distance
|
|
22
|
+
from .io import serialize, deserialize, clone, clone_agent, fingerprint, save_agent, load_agent, load_latest
|
|
23
|
+
from .core import (
|
|
24
|
+
TraceBuffer,
|
|
25
|
+
TraceEvent,
|
|
26
|
+
ExperienceTrie,
|
|
27
|
+
MetaTrie,
|
|
28
|
+
SelfTokenState,
|
|
29
|
+
ExperienceLexicon,
|
|
30
|
+
LexiconEntry,
|
|
31
|
+
strange_loop_score,
|
|
32
|
+
compute_self_reference_score,
|
|
33
|
+
)
|
|
34
|
+
from .meaning import SharedMeaningTracker
|
|
35
|
+
|
|
36
|
+
# Alias for CA_RUNTIME_API.md compatibility
|
|
37
|
+
import sys as _sys
|
|
38
|
+
_sys.modules['conscious_agent.worlds'] = _sys.modules['conscious_agent.world']
|
|
39
|
+
_sys.modules['conscious_agent.io'] = _sys.modules['conscious_agent.io']
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"ConsciousAgent",
|
|
43
|
+
"SimpleWorld",
|
|
44
|
+
"WorldState",
|
|
45
|
+
"StepOutput",
|
|
46
|
+
"ExperienceSpace",
|
|
47
|
+
"World",
|
|
48
|
+
"WorldBuilder",
|
|
49
|
+
"CoinTossWorld",
|
|
50
|
+
"build_world_from_dataframe",
|
|
51
|
+
"AgentNetwork",
|
|
52
|
+
"combine",
|
|
53
|
+
"trivial_agent",
|
|
54
|
+
"experience_space_distance",
|
|
55
|
+
"serialize",
|
|
56
|
+
"deserialize",
|
|
57
|
+
"clone",
|
|
58
|
+
"clone_agent",
|
|
59
|
+
"fingerprint",
|
|
60
|
+
"save_agent",
|
|
61
|
+
"load_agent",
|
|
62
|
+
"load_latest",
|
|
63
|
+
"TraceBuffer",
|
|
64
|
+
"TraceEvent",
|
|
65
|
+
"ExperienceTrie",
|
|
66
|
+
"MetaTrie",
|
|
67
|
+
"SelfTokenState",
|
|
68
|
+
"ExperienceLexicon",
|
|
69
|
+
"LexiconEntry",
|
|
70
|
+
"strange_loop_score",
|
|
71
|
+
"compute_self_reference_score",
|
|
72
|
+
"SharedMeaningTracker",
|
|
73
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .conscious_agent import ConsciousAgent, StepOutput
|
|
2
|
+
from .simple_world import SimpleWorld
|
|
3
|
+
from .world_state import WorldState, EnvironmentState, sequence_to_state_id
|
|
4
|
+
from .experience_space import ExperienceSpace, MemorySpace
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"ConsciousAgent",
|
|
8
|
+
"StepOutput",
|
|
9
|
+
"SimpleWorld",
|
|
10
|
+
"WorldState",
|
|
11
|
+
"EnvironmentState",
|
|
12
|
+
"sequence_to_state_id",
|
|
13
|
+
"ExperienceSpace",
|
|
14
|
+
"MemorySpace",
|
|
15
|
+
]
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from ..core import (
|
|
9
|
+
compute_self_reference_score as _compute_self_reference_score,
|
|
10
|
+
ExperienceTrie,
|
|
11
|
+
MetaTrie,
|
|
12
|
+
SelfTokenState,
|
|
13
|
+
TraceBuffer,
|
|
14
|
+
)
|
|
15
|
+
from .world_state import WorldState
|
|
16
|
+
from .experience_space import ExperienceSpace
|
|
17
|
+
from .perceptual_map import perceive
|
|
18
|
+
from .decision_map import decide, OutputState
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class StepOutput:
|
|
23
|
+
step: int
|
|
24
|
+
generation: int
|
|
25
|
+
state: int
|
|
26
|
+
state_label: str
|
|
27
|
+
prediction_error: float
|
|
28
|
+
sequence: list[str]
|
|
29
|
+
sequence_str: str
|
|
30
|
+
loop_depth: float
|
|
31
|
+
i_locked: bool
|
|
32
|
+
i_stability: float
|
|
33
|
+
interrupt: Any = None
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class ConsciousAgent:
|
|
38
|
+
agent_id: str
|
|
39
|
+
experience: ExperienceSpace = field(default_factory=ExperienceSpace)
|
|
40
|
+
world: Any = None
|
|
41
|
+
generation: int = 0
|
|
42
|
+
step_count: int = 0
|
|
43
|
+
meta_observation_interval: int = 20
|
|
44
|
+
constituent_ids: frozenset[str] = field(default_factory=frozenset)
|
|
45
|
+
leaf_constituent_ids: frozenset[str] = field(default_factory=frozenset)
|
|
46
|
+
cycle_level: int = 0
|
|
47
|
+
expression_temp: float = 1.0
|
|
48
|
+
p_stable: float = 0.80
|
|
49
|
+
p_lexicon: float = 0.10
|
|
50
|
+
p_explore: float = 0.05
|
|
51
|
+
_combined: bool = False
|
|
52
|
+
_ergodic_state: OutputState = "idle"
|
|
53
|
+
_last_output: list[str] = field(default_factory=lambda: ["wait"])
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def from_config(agent_id: str, config: dict) -> ConsciousAgent:
|
|
57
|
+
agent_cfg = config.get("agent", {})
|
|
58
|
+
st_cfg = agent_cfg.get("self_token", {})
|
|
59
|
+
st = SelfTokenState(
|
|
60
|
+
lock_threshold=st_cfg.get("lock_threshold", 0.25),
|
|
61
|
+
lock_consecutive_required=st_cfg.get("lock_consecutive_required", 3),
|
|
62
|
+
)
|
|
63
|
+
exp = ExperienceSpace(self_token=st)
|
|
64
|
+
return ConsciousAgent(
|
|
65
|
+
agent_id=agent_id,
|
|
66
|
+
experience=exp,
|
|
67
|
+
meta_observation_interval=agent_cfg.get("meta_observation_interval", 20),
|
|
68
|
+
expression_temp=agent_cfg.get("expression_temp", 1.0),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def step(self, world: WorldState | None = None) -> StepOutput:
|
|
72
|
+
if world is not None:
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
if world is None and self.world is not None:
|
|
76
|
+
if hasattr(self.world, 'step'):
|
|
77
|
+
world = self.world.step()
|
|
78
|
+
|
|
79
|
+
if world is not None:
|
|
80
|
+
self.experience = perceive(
|
|
81
|
+
world,
|
|
82
|
+
self.experience,
|
|
83
|
+
step=self.step_count,
|
|
84
|
+
meta_observation_interval=self.meta_observation_interval,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
output, self._ergodic_state = decide(
|
|
88
|
+
self.experience,
|
|
89
|
+
p_stable=self.p_stable,
|
|
90
|
+
p_lexicon=self.p_lexicon,
|
|
91
|
+
p_explore=self.p_explore,
|
|
92
|
+
ergodic_state=self._ergodic_state,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
for token in output:
|
|
96
|
+
if self.experience.meta_trie.last_meta_state is not None:
|
|
97
|
+
self.experience.meta_trie.record_token(
|
|
98
|
+
self.experience.meta_trie.last_meta_state, token
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
self._last_output = output
|
|
102
|
+
self.step_count += 1
|
|
103
|
+
if self.step_count > 0 and self.step_count % self.meta_observation_interval == 0:
|
|
104
|
+
self.generation += 1
|
|
105
|
+
|
|
106
|
+
return StepOutput(
|
|
107
|
+
step=self.step_count,
|
|
108
|
+
generation=self.generation,
|
|
109
|
+
state=self.experience.last_world_state_id or -1,
|
|
110
|
+
state_label=str(self.experience.last_world_state_id or "?"),
|
|
111
|
+
prediction_error=self.experience.trace_buffer.prediction_error_mean(window=5),
|
|
112
|
+
sequence=list(output),
|
|
113
|
+
sequence_str=" ".join(output),
|
|
114
|
+
loop_depth=float(_compute_self_reference_score(output)),
|
|
115
|
+
i_locked=self.experience.self_token.locked,
|
|
116
|
+
i_stability=self.experience.self_token.stationary_variance(),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
def run(self, n_steps: int) -> list[StepOutput]:
|
|
120
|
+
outputs = []
|
|
121
|
+
for _ in range(n_steps):
|
|
122
|
+
outputs.append(self.step())
|
|
123
|
+
return outputs
|
|
124
|
+
|
|
125
|
+
def observe(self, output_sequence: list[str], source_id: str) -> StepOutput:
|
|
126
|
+
return self.step(WorldState.from_sequence(source_id, output_sequence))
|
|
127
|
+
|
|
128
|
+
def get_output(self) -> list[str]:
|
|
129
|
+
return list(self._last_output)
|
|
130
|
+
|
|
131
|
+
def set_world(self, world: Any) -> None:
|
|
132
|
+
self.world = world
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def loop_score(self) -> float:
|
|
136
|
+
return float(_compute_self_reference_score(self._last_output))
|
|
137
|
+
|
|
138
|
+
@property
|
|
139
|
+
def mean_prediction_error(self) -> float:
|
|
140
|
+
return self.experience.trace_buffer.prediction_error_mean(window=100)
|
|
141
|
+
|
|
142
|
+
@property
|
|
143
|
+
def is_i_locked(self) -> bool:
|
|
144
|
+
return self.experience.self_token.locked
|
|
145
|
+
|
|
146
|
+
@property
|
|
147
|
+
def is_identity_stable(self) -> bool:
|
|
148
|
+
return self.experience.is_identity_stable
|
|
149
|
+
|
|
150
|
+
is_ripe = is_identity_stable
|
|
151
|
+
|
|
152
|
+
def clear(self) -> None:
|
|
153
|
+
self.experience.trace_buffer.clear()
|
|
154
|
+
self.experience.trie.clear()
|
|
155
|
+
self.experience.meta_trie.clear()
|
|
156
|
+
self.experience.lexicon.clear()
|
|
157
|
+
self.step_count = 0
|
|
158
|
+
self.generation = 0
|
|
159
|
+
self._last_output = ["wait"]
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
ConsciousAgent.__init__.__doc__ = """Create a ConsciousAgent.
|
|
163
|
+
|
|
164
|
+
Args:
|
|
165
|
+
agent_id: Unique identifier for this agent.
|
|
166
|
+
experience: The agent's internal experience space (trie, meta-trie, etc.)
|
|
167
|
+
world: Optional world object with a .step() method returning WorldState.
|
|
168
|
+
generation: Current generation counter.
|
|
169
|
+
step_count: Current step counter.
|
|
170
|
+
meta_observation_interval: Steps between meta-trie observations (default 20).
|
|
171
|
+
constituent_ids: IDs of agents that combined to create this agent.
|
|
172
|
+
leaf_constituent_ids: IDs of leaf agents below combined agents.
|
|
173
|
+
cycle_level: Depth in combination tree (0 = base agent).
|
|
174
|
+
expression_temp: Temperature controlling output style (1.0=poetic, 0.0=clinical).
|
|
175
|
+
p_stable: Probability of remaining in core output state.
|
|
176
|
+
p_lexicon: Probability of transitioning to lexicon output state.
|
|
177
|
+
p_explore: Probability of exploring random tokens.
|
|
178
|
+
"""
|