Skip to main content

Self-referential structure-learning system — agents that learn by inhabiting worlds

Project description

conscious-agent

A computational implementation of Hoffman's Conscious Realism.

Build self-referential agents that learn by inhabiting worlds — constructing internal models of both their environment and themselves.

from conscious_agent import ConsciousAgent
from conscious_agent.worlds import CoinTossWorld

world = CoinTossWorld(n_coins=4)
agent = ConsciousAgent(world=world, agent_id="my_agent")
outputs = agent.run(n_steps=1000)
print(f'"I" locked: {agent.is_i_locked}')

Installation

pip install numpy scipy       # core dependencies
pip install conscious-agent   # once published

Or from source:

cd hoffman-agents-python
pip install -e .

Quick Start

Single agent in a coin-toss world

from conscious_agent import ConsciousAgent
from conscious_agent.worlds import CoinTossWorld

world = CoinTossWorld(n_coins=3)
agent = ConsciousAgent(agent_id="coin_agent", world=world)

for _ in range(500):
    output = agent.step()
    if output.i_locked:
        print(f"I locked at step {output.step}")
        break

Custom Markov world

from conscious_agent import ConsciousAgent, WorldBuilder
import numpy as np

data = np.random.rand(500, 3)
world = (WorldBuilder()
    .add_feature("temp", normalization="minmax", n_bins=4)
    .add_feature("humidity", normalization="minmax", n_bins=4)
    .add_feature("pressure", normalization="minmax", n_bins=4)
    .build(data))

agent = ConsciousAgent(agent_id="weather_agent", world=world)
outputs = agent.run(n_steps=1000)

Combine two agents

from conscious_agent import combine

a = ConsciousAgent(agent_id="agent_a", world=world)
b = ConsciousAgent(agent_id="agent_b", world=world)
a.run(500)
b.run(500)

combined = combine(a, b)
print(f"Combined agent: {combined.agent_id}, level: {combined.cycle_level}")

Multi-agent network

from conscious_agent import AgentNetwork

network = AgentNetwork(n_agents=10, seed=42)
states = network.run(n_generations=100)
print(f"Avg prediction error: {network.avg_prediction_error():.3f}")

Save and load

from conscious_agent.io import save_agent, load_agent, clone_agent

path = save_agent(agent, "./souls")
loaded = load_agent(path)

cloned = clone_agent(agent, "experiment_clone")

Public API

# Core classes
from conscious_agent import ConsciousAgent, World, WorldBuilder
from conscious_agent import SimpleWorld, ExperienceSpace

# World factories
from conscious_agent.worlds import CoinTossWorld, build_world_from_dataframe

# IO
from conscious_agent.io import save_agent, load_agent, clone_agent, load_latest

# Multi-agent
from conscious_agent import AgentNetwork, combine

# Core components (for advanced use)
from conscious_agent import (
    TraceBuffer, TraceEvent, ExperienceTrie, MetaTrie,
    SelfTokenState, ExperienceLexicon, strange_loop_score,
)

How It Works

Every ConsciousAgent has an experience space — four interconnected structures:

  1. TraceBuffer — short-term memory: the last N state transitions
  2. ExperienceTrie — long-term world model: compressed prefix tree over observed state sequences
  3. MetaTrie — self-model: a second trie over the agent's own trace buffer snapshots (thinking about thinking)
  4. SelfTokenState ("I") — identity: the dominant meta-state that forms a stable attractor

The agent cycles through perception (observe world → update trie) → meta-observation (observe self → update meta-trie) → decision (generate output tokens via ergodic Markov chain).

When the meta-trie's stationary distribution converges on a single meta-state, the "I" locks — the agent has formed a stable identity.

Requirements

  • Python 3.10+
  • numpy >= 1.24
  • scipy >= 1.10

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

conscious_agent-1.0.0.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

conscious_agent-1.0.0-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file conscious_agent-1.0.0.tar.gz.

File metadata

  • Download URL: conscious_agent-1.0.0.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for conscious_agent-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5ce812821074c797d489dd2ff09cff2bf0382f8e1c74e76419fba97417801dcc
MD5 855caa128cff79118e7d22c4662fbead
BLAKE2b-256 f1bb1695e0a6d2fba110357dd78a68401268eb49803af40f7f747f2ccb18ad48

See more details on using hashes here.

File details

Details for the file conscious_agent-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for conscious_agent-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d311c5d3fc5cd55ff27a1d1a9fad3c1d6d6c27f86c8c95874b3568123effbe50
MD5 e845cbe09a1fea177c8da109d3d153c3
BLAKE2b-256 d2ec1fbaff2feb85614a727b7c92933925464dae51978f21468a142af585271c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page