anima-world 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.
Files changed (49) hide show
  1. anima_world-1.0.0/LICENSE +202 -0
  2. anima_world-1.0.0/NOTICE +16 -0
  3. anima_world-1.0.0/PKG-INFO +245 -0
  4. anima_world-1.0.0/README.md +213 -0
  5. anima_world-1.0.0/anima_world/__init__.py +3 -0
  6. anima_world-1.0.0/anima_world/__main__.py +1565 -0
  7. anima_world-1.0.0/anima_world/actions.py +105 -0
  8. anima_world-1.0.0/anima_world/agent.py +31 -0
  9. anima_world-1.0.0/anima_world/api.py +947 -0
  10. anima_world-1.0.0/anima_world/beats.py +528 -0
  11. anima_world-1.0.0/anima_world/brain.py +97 -0
  12. anima_world-1.0.0/anima_world/bt_nodes.py +280 -0
  13. anima_world-1.0.0/anima_world/chat_service.py +355 -0
  14. anima_world-1.0.0/anima_world/chat_session.py +141 -0
  15. anima_world-1.0.0/anima_world/chat_store.py +219 -0
  16. anima_world-1.0.0/anima_world/cliques.py +63 -0
  17. anima_world-1.0.0/anima_world/config_store.py +311 -0
  18. anima_world-1.0.0/anima_world/db.py +433 -0
  19. anima_world-1.0.0/anima_world/economy.py +108 -0
  20. anima_world-1.0.0/anima_world/events.py +44 -0
  21. anima_world-1.0.0/anima_world/gossip.py +58 -0
  22. anima_world-1.0.0/anima_world/graph.py +72 -0
  23. anima_world-1.0.0/anima_world/llm_client.py +216 -0
  24. anima_world-1.0.0/anima_world/locations.py +30 -0
  25. anima_world-1.0.0/anima_world/memory_retrieval.py +54 -0
  26. anima_world-1.0.0/anima_world/memory_store.py +259 -0
  27. anima_world-1.0.0/anima_world/memory_triggers.py +174 -0
  28. anima_world-1.0.0/anima_world/narrative.py +368 -0
  29. anima_world-1.0.0/anima_world/needs.py +68 -0
  30. anima_world-1.0.0/anima_world/onboarding.py +287 -0
  31. anima_world-1.0.0/anima_world/planner.py +375 -0
  32. anima_world-1.0.0/anima_world/projection.py +349 -0
  33. anima_world-1.0.0/anima_world/prompt_store.py +227 -0
  34. anima_world-1.0.0/anima_world/relationship_judge.py +276 -0
  35. anima_world-1.0.0/anima_world/scheduler.py +1774 -0
  36. anima_world-1.0.0/anima_world/types.py +81 -0
  37. anima_world-1.0.0/anima_world/world_package.py +501 -0
  38. anima_world-1.0.0/anima_world/world_seed.json +188 -0
  39. anima_world-1.0.0/anima_world/world_seed.py +58 -0
  40. anima_world-1.0.0/anima_world/world_store.py +477 -0
  41. anima_world-1.0.0/anima_world/world_time.py +51 -0
  42. anima_world-1.0.0/anima_world.egg-info/PKG-INFO +245 -0
  43. anima_world-1.0.0/anima_world.egg-info/SOURCES.txt +47 -0
  44. anima_world-1.0.0/anima_world.egg-info/dependency_links.txt +1 -0
  45. anima_world-1.0.0/anima_world.egg-info/entry_points.txt +2 -0
  46. anima_world-1.0.0/anima_world.egg-info/requires.txt +8 -0
  47. anima_world-1.0.0/anima_world.egg-info/top_level.txt +1 -0
  48. anima_world-1.0.0/pyproject.toml +65 -0
  49. anima_world-1.0.0/setup.cfg +4 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,16 @@
1
+ anima-world —— ANIMA 世界引擎
2
+ Copyright 2026 ANIMA
3
+
4
+ This product includes software developed at ANIMA (https://animametaverse.com).
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
@@ -0,0 +1,245 @@
1
+ Metadata-Version: 2.4
2
+ Name: anima-world
3
+ Version: 1.0.0
4
+ Summary: A world-simulation engine for LLM-driven agents: event-sourced core, behavior-tree scheduling, memory and relationships, packaged as portable .cyberworld files
5
+ Author-email: ANIMA <aubrey@animametaverse.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://animametaverse.com
8
+ Project-URL: Source, https://github.com/aubrey-anima/core
9
+ Project-URL: Issues, https://github.com/aubrey-anima/core/issues
10
+ Project-URL: Changelog, https://github.com/aubrey-anima/core/blob/main/CHANGELOG.md
11
+ Keywords: simulation,agents,llm,event-sourcing,behavior-tree,worldbuilding
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Games/Entertainment :: Simulation
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ License-File: NOTICE
24
+ Requires-Dist: cryptography>=42.0
25
+ Requires-Dist: openai>=1.30
26
+ Requires-Dist: httpx>=0.27
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8.0; extra == "dev"
29
+ Requires-Dist: build>=1.2; extra == "dev"
30
+ Requires-Dist: twine>=5.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # anima-world
34
+
35
+ **A world-simulation engine for LLM-driven agents.** Characters wake up, get hungry,
36
+ go to work, gossip about each other, form cliques, spend money, remember what happened
37
+ last week, and change how they feel about you. One SQLite file is one world.
38
+
39
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/aubrey-anima/core/blob/main/LICENSE)
40
+ [![Python](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-blue.svg)](https://github.com/aubrey-anima/core/blob/main/pyproject.toml)
41
+ [![PyPI](https://img.shields.io/pypi/v/anima-world.svg)](https://pypi.org/project/anima-world/)
42
+
43
+ English | [中文](https://github.com/aubrey-anima/core/blob/main/README.zh-CN.md)
44
+
45
+ ---
46
+
47
+ ## What this is
48
+
49
+ Most "AI agent" frameworks give you a chatbot with tools. This gives you a **place** —
50
+ one that keeps running whether or not anyone is watching, and remembers what happened
51
+ while they were away.
52
+
53
+ A world is a tick-driven simulation. On every tick each character runs a behavior tree
54
+ against its own needs and the state of the world, and acts. Those acts become events in
55
+ an append-only log, which is the world's only source of truth — balances, relationships,
56
+ and locations are all *projections* of that log, never separately stored rows that could
57
+ drift out of sync.
58
+
59
+ The LLM sits beside the simulation, not inside it. It writes the narration, plans what a
60
+ character does with free time, and judges how a conversation changed a relationship —
61
+ all on background threads. **The clock never blocks on a network call.** Take the LLM
62
+ away entirely and the world still runs; it just narrates in templates.
63
+
64
+ The engine is **a library, not a service.** There is no HTTP server and no port. Your
65
+ application imports it, and the world lives inside your process:
66
+
67
+ ```
68
+ your app ──import anima_world.api──▶ world.db
69
+ ```
70
+
71
+ ## See it run
72
+
73
+ ```console
74
+ $ pip install anima-world
75
+ $ anima-world start
76
+
77
+ ANIMA 世界引擎
78
+ ────────────────────────────────────────────
79
+
80
+ ① LLM
81
+ ! LLM 未配置 —— 叙事、空闲计划、关系判定都会降级成模板文本
82
+ 修复:anima-world config set llm.api_key sk-…
83
+
84
+ ② 世界
85
+ ✓ 新建 saves/world.db
86
+ 时钟:1 tick/秒 —— 约 5 分钟走完一个世界日(现实时间的 300 倍速)
87
+ ✓ 3 个角色就位: 苏晚夏、陆知遥、沈亦柔
88
+
89
+ ③ 运行
90
+ 世界在本进程里运行,叙事会打印在下面;停止:Ctrl-C
91
+
92
+ [第0天 00:10] 遥:遥 wandered around
93
+ [第0天 00:10] 夏:夏 went to sleep
94
+ [第0天 00:35] 遥:遥 went to sleep
95
+ ^C
96
+ 世界已停下,快照已保存。下次接着跑:anima-world start
97
+ ```
98
+
99
+ `start` configures the LLM, creates the world, and runs it — in that order, with no
100
+ documentation required first. Without an API key everything still works; narration is
101
+ templated and characters have no plans. That degradation is deliberate, and it is never
102
+ silent (`anima-world doctor` will tell you, and `World.state()` carries the reason).
103
+
104
+ > **Heads up on language:** the engine speaks Chinese. CLI output, narration prompts, the
105
+ > built-in seed world, and the reference docs are all in Chinese. The API itself is
106
+ > English (`World.open`, `world.tick`, `world.chat`), so embedding it in an
107
+ > English-language application works fine — you supply your own seed and prompts.
108
+
109
+ ## Install
110
+
111
+ ```bash
112
+ pip install anima-world # Python 3.11+
113
+ ```
114
+
115
+ Three runtime dependencies, chosen to stay out of your way since they land in every host
116
+ that embeds a world: `cryptography` (encrypts the API key at rest), `openai` (any
117
+ OpenAI-compatible endpoint), `httpx`.
118
+
119
+ From source:
120
+
121
+ ```bash
122
+ git clone https://github.com/aubrey-anima/core.git anima-world
123
+ cd anima-world && pip install -e ".[dev]" && python -m pytest
124
+ ```
125
+
126
+ ## Use it in your app
127
+
128
+ This is the main interface. `World` is a plain object with a lifetime — open it, drive
129
+ it, close it.
130
+
131
+ ```python
132
+ from anima_world.api import World
133
+
134
+ with World.open("saves/world.db") as world:
135
+ world.start_clock() # background clock; or drive it yourself
136
+ print(world.state()["world_time"]) # {'day': 0, 'hour': 6, 'minute': 25, ...}
137
+
138
+ # Talk to a character on a player's behalf. Streams; your app owns the transcript.
139
+ for chunk in world.chat("夏", [{"role": "user", "content": "你好"}],
140
+ player_id="p1", display_name="阿宇"):
141
+ print(chunk, end="")
142
+
143
+ # Commit a finished exchange: summary + one world event + a relationship verdict
144
+ world.record_chat_turn("夏", "p1", [
145
+ {"role": "user", "content": "你好"},
146
+ {"role": "assistant", "content": "你好呀"},
147
+ ])
148
+
149
+ world.player_move("p1", "cafe")
150
+ world.config_set("scheduler.tick_rate", 1.0)
151
+ ```
152
+
153
+ For batch work, drive the clock yourself — `world.tick(n)` is synchronous and
154
+ deterministic, which is what makes fast-forwarding and testing possible:
155
+
156
+ ```python
157
+ with World.open("w.db") as world:
158
+ world.tick(288) # one world day
159
+ print(world.memories("夏")) # what she remembers, ranked
160
+ print(world.needs("夏")) # {'energy': 0.59, 'hunger': 0.16, ...}
161
+ print(world.cliques()) # who has clustered together
162
+ ```
163
+
164
+ ## What a world contains
165
+
166
+ Four subsystems, each an opt-in flag except memory. They are off by default because a
167
+ world that only walks around and talks is a legitimate world, and every mechanism you
168
+ enable is more LLM spend and more surface to reason about.
169
+
170
+ | Subsystem | Flag | What it adds |
171
+ |---|---|---|
172
+ | **Memory** | always on | Retrieval scored on relevance × recency × importance, periodic reflection that writes higher-order memories, and a forgetting curve |
173
+ | **Needs** | `needs.enabled` | `energy` / `hunger` / `social` decay per tick and drive an urgency band in the behavior tree — a tired character stops what it is doing and goes to sleep |
174
+ | **Economy** | `economy.enabled` | Items, money, shops, wages, and price drift. The ledger is a projection of `payment` events, so balances cannot be forged |
175
+ | **Social** | `social.enabled` | Three-axis relationships (always on) plus gossip that propagates second-hand with confidence decay, and emergent cliques |
176
+
177
+ ```bash
178
+ anima-world config set needs.enabled true --db-path saves/world.db
179
+ ```
180
+
181
+ ## How it is built
182
+
183
+ **One file is one world.** `world.db` holds events, chats, memories, and config.
184
+ `world.db.key` sits next to it and encrypts the API key — **it must travel with the
185
+ database**, or the key becomes unreadable and the world silently drops to Mock. (Not
186
+ actually silently: the engine says so at boot and keeps saying so in `state()`.)
187
+
188
+ **The event log is the only truth.** There is no `balances` table, because two sources
189
+ of truth eventually disagree and you cannot tell which one is right. `world.db` does not
190
+ store "夏 has 50 coins" — it stores *why* she has 50 coins. Reconciliation is replay.
191
+
192
+ **One running world owns its file.** Half the truth lives in memory (clock, projection,
193
+ locks, thread pools), so a second process writing the same `world.db` forks it
194
+ immediately. Offline work — packaging, fast-forwarding — happens after the world closes.
195
+
196
+ **Version is contract.** One release freezes (engine code, db format, package format)
197
+ together. The major version *is* the db format version, and `db.py` enforces it at
198
+ runtime: mount a database from an incompatible format and it refuses on the spot rather
199
+ than quietly writing garbage.
200
+
201
+ ## Ship a world to someone else
202
+
203
+ Worlds package into a single `.cyberworld` file — either a template (just the seed, the
204
+ world builds itself on first boot) or a snapshot (a database that has already lived).
205
+
206
+ ```bash
207
+ anima-world world export --seed seed.json --output my.cyberworld \
208
+ --world-id my-world --name "我的世界" --mode template
209
+
210
+ anima-world world import my.cyberworld --destination ./instances
211
+ ```
212
+
213
+ ## Commands
214
+
215
+ ```bash
216
+ anima-world start # create + run, with guided setup — start here
217
+ anima-world doctor # health check: files, keys, a real LLM call, clock speed
218
+ anima-world config # read/write settings, secrets encrypted and masked
219
+ anima-world run # foreground host, no onboarding (for deployment)
220
+ anima-world simulate # headless fast-forward
221
+ anima-world world # export / import .cyberworld packages
222
+ ```
223
+
224
+ ## Documentation
225
+
226
+ | | |
227
+ |---|---|
228
+ | [docs/REFERENCE.md](https://github.com/aubrey-anima/core/blob/main/docs/REFERENCE.md) | Every command, every `World` method, every config key, the beat-script format 🇨🇳 |
229
+ | [docs/ARCHITECTURE.md](https://github.com/aubrey-anima/core/blob/main/docs/ARCHITECTURE.md) | Why it is shaped this way: the truth model, the tick frame, threads and locks, invariants, known debt 🇨🇳 |
230
+ | [CONTRIBUTING.md](https://github.com/aubrey-anima/core/blob/main/CONTRIBUTING.md) | Development setup, the invariants a patch must not break, how to propose changes |
231
+ | [CHANGELOG.md](https://github.com/aubrey-anima/core/blob/main/CHANGELOG.md) | Release history |
232
+
233
+ ## Contributing
234
+
235
+ Issues and pull requests are welcome. Start with [CONTRIBUTING.md](https://github.com/aubrey-anima/core/blob/main/CONTRIBUTING.md) —
236
+ it lists the handful of invariants that a change must not break (there is exactly one
237
+ lock in the system, the LLM is never called on the tick thread, and a few file formats
238
+ are mirrored by other repositories).
239
+
240
+ ## License
241
+
242
+ [Apache License 2.0](https://github.com/aubrey-anima/core/blob/main/LICENSE). Use it, modify it, ship it inside closed-source products;
243
+ keep the copyright notice and state what you changed. Apache rather than MIT for the
244
+ patent grant, and permissive rather than copyleft because an engine that hosts embed
245
+ cannot be copyleft without infecting every host that embeds it.
@@ -0,0 +1,213 @@
1
+ # anima-world
2
+
3
+ **A world-simulation engine for LLM-driven agents.** Characters wake up, get hungry,
4
+ go to work, gossip about each other, form cliques, spend money, remember what happened
5
+ last week, and change how they feel about you. One SQLite file is one world.
6
+
7
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/aubrey-anima/core/blob/main/LICENSE)
8
+ [![Python](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13-blue.svg)](https://github.com/aubrey-anima/core/blob/main/pyproject.toml)
9
+ [![PyPI](https://img.shields.io/pypi/v/anima-world.svg)](https://pypi.org/project/anima-world/)
10
+
11
+ English | [中文](https://github.com/aubrey-anima/core/blob/main/README.zh-CN.md)
12
+
13
+ ---
14
+
15
+ ## What this is
16
+
17
+ Most "AI agent" frameworks give you a chatbot with tools. This gives you a **place** —
18
+ one that keeps running whether or not anyone is watching, and remembers what happened
19
+ while they were away.
20
+
21
+ A world is a tick-driven simulation. On every tick each character runs a behavior tree
22
+ against its own needs and the state of the world, and acts. Those acts become events in
23
+ an append-only log, which is the world's only source of truth — balances, relationships,
24
+ and locations are all *projections* of that log, never separately stored rows that could
25
+ drift out of sync.
26
+
27
+ The LLM sits beside the simulation, not inside it. It writes the narration, plans what a
28
+ character does with free time, and judges how a conversation changed a relationship —
29
+ all on background threads. **The clock never blocks on a network call.** Take the LLM
30
+ away entirely and the world still runs; it just narrates in templates.
31
+
32
+ The engine is **a library, not a service.** There is no HTTP server and no port. Your
33
+ application imports it, and the world lives inside your process:
34
+
35
+ ```
36
+ your app ──import anima_world.api──▶ world.db
37
+ ```
38
+
39
+ ## See it run
40
+
41
+ ```console
42
+ $ pip install anima-world
43
+ $ anima-world start
44
+
45
+ ANIMA 世界引擎
46
+ ────────────────────────────────────────────
47
+
48
+ ① LLM
49
+ ! LLM 未配置 —— 叙事、空闲计划、关系判定都会降级成模板文本
50
+ 修复:anima-world config set llm.api_key sk-…
51
+
52
+ ② 世界
53
+ ✓ 新建 saves/world.db
54
+ 时钟:1 tick/秒 —— 约 5 分钟走完一个世界日(现实时间的 300 倍速)
55
+ ✓ 3 个角色就位: 苏晚夏、陆知遥、沈亦柔
56
+
57
+ ③ 运行
58
+ 世界在本进程里运行,叙事会打印在下面;停止:Ctrl-C
59
+
60
+ [第0天 00:10] 遥:遥 wandered around
61
+ [第0天 00:10] 夏:夏 went to sleep
62
+ [第0天 00:35] 遥:遥 went to sleep
63
+ ^C
64
+ 世界已停下,快照已保存。下次接着跑:anima-world start
65
+ ```
66
+
67
+ `start` configures the LLM, creates the world, and runs it — in that order, with no
68
+ documentation required first. Without an API key everything still works; narration is
69
+ templated and characters have no plans. That degradation is deliberate, and it is never
70
+ silent (`anima-world doctor` will tell you, and `World.state()` carries the reason).
71
+
72
+ > **Heads up on language:** the engine speaks Chinese. CLI output, narration prompts, the
73
+ > built-in seed world, and the reference docs are all in Chinese. The API itself is
74
+ > English (`World.open`, `world.tick`, `world.chat`), so embedding it in an
75
+ > English-language application works fine — you supply your own seed and prompts.
76
+
77
+ ## Install
78
+
79
+ ```bash
80
+ pip install anima-world # Python 3.11+
81
+ ```
82
+
83
+ Three runtime dependencies, chosen to stay out of your way since they land in every host
84
+ that embeds a world: `cryptography` (encrypts the API key at rest), `openai` (any
85
+ OpenAI-compatible endpoint), `httpx`.
86
+
87
+ From source:
88
+
89
+ ```bash
90
+ git clone https://github.com/aubrey-anima/core.git anima-world
91
+ cd anima-world && pip install -e ".[dev]" && python -m pytest
92
+ ```
93
+
94
+ ## Use it in your app
95
+
96
+ This is the main interface. `World` is a plain object with a lifetime — open it, drive
97
+ it, close it.
98
+
99
+ ```python
100
+ from anima_world.api import World
101
+
102
+ with World.open("saves/world.db") as world:
103
+ world.start_clock() # background clock; or drive it yourself
104
+ print(world.state()["world_time"]) # {'day': 0, 'hour': 6, 'minute': 25, ...}
105
+
106
+ # Talk to a character on a player's behalf. Streams; your app owns the transcript.
107
+ for chunk in world.chat("夏", [{"role": "user", "content": "你好"}],
108
+ player_id="p1", display_name="阿宇"):
109
+ print(chunk, end="")
110
+
111
+ # Commit a finished exchange: summary + one world event + a relationship verdict
112
+ world.record_chat_turn("夏", "p1", [
113
+ {"role": "user", "content": "你好"},
114
+ {"role": "assistant", "content": "你好呀"},
115
+ ])
116
+
117
+ world.player_move("p1", "cafe")
118
+ world.config_set("scheduler.tick_rate", 1.0)
119
+ ```
120
+
121
+ For batch work, drive the clock yourself — `world.tick(n)` is synchronous and
122
+ deterministic, which is what makes fast-forwarding and testing possible:
123
+
124
+ ```python
125
+ with World.open("w.db") as world:
126
+ world.tick(288) # one world day
127
+ print(world.memories("夏")) # what she remembers, ranked
128
+ print(world.needs("夏")) # {'energy': 0.59, 'hunger': 0.16, ...}
129
+ print(world.cliques()) # who has clustered together
130
+ ```
131
+
132
+ ## What a world contains
133
+
134
+ Four subsystems, each an opt-in flag except memory. They are off by default because a
135
+ world that only walks around and talks is a legitimate world, and every mechanism you
136
+ enable is more LLM spend and more surface to reason about.
137
+
138
+ | Subsystem | Flag | What it adds |
139
+ |---|---|---|
140
+ | **Memory** | always on | Retrieval scored on relevance × recency × importance, periodic reflection that writes higher-order memories, and a forgetting curve |
141
+ | **Needs** | `needs.enabled` | `energy` / `hunger` / `social` decay per tick and drive an urgency band in the behavior tree — a tired character stops what it is doing and goes to sleep |
142
+ | **Economy** | `economy.enabled` | Items, money, shops, wages, and price drift. The ledger is a projection of `payment` events, so balances cannot be forged |
143
+ | **Social** | `social.enabled` | Three-axis relationships (always on) plus gossip that propagates second-hand with confidence decay, and emergent cliques |
144
+
145
+ ```bash
146
+ anima-world config set needs.enabled true --db-path saves/world.db
147
+ ```
148
+
149
+ ## How it is built
150
+
151
+ **One file is one world.** `world.db` holds events, chats, memories, and config.
152
+ `world.db.key` sits next to it and encrypts the API key — **it must travel with the
153
+ database**, or the key becomes unreadable and the world silently drops to Mock. (Not
154
+ actually silently: the engine says so at boot and keeps saying so in `state()`.)
155
+
156
+ **The event log is the only truth.** There is no `balances` table, because two sources
157
+ of truth eventually disagree and you cannot tell which one is right. `world.db` does not
158
+ store "夏 has 50 coins" — it stores *why* she has 50 coins. Reconciliation is replay.
159
+
160
+ **One running world owns its file.** Half the truth lives in memory (clock, projection,
161
+ locks, thread pools), so a second process writing the same `world.db` forks it
162
+ immediately. Offline work — packaging, fast-forwarding — happens after the world closes.
163
+
164
+ **Version is contract.** One release freezes (engine code, db format, package format)
165
+ together. The major version *is* the db format version, and `db.py` enforces it at
166
+ runtime: mount a database from an incompatible format and it refuses on the spot rather
167
+ than quietly writing garbage.
168
+
169
+ ## Ship a world to someone else
170
+
171
+ Worlds package into a single `.cyberworld` file — either a template (just the seed, the
172
+ world builds itself on first boot) or a snapshot (a database that has already lived).
173
+
174
+ ```bash
175
+ anima-world world export --seed seed.json --output my.cyberworld \
176
+ --world-id my-world --name "我的世界" --mode template
177
+
178
+ anima-world world import my.cyberworld --destination ./instances
179
+ ```
180
+
181
+ ## Commands
182
+
183
+ ```bash
184
+ anima-world start # create + run, with guided setup — start here
185
+ anima-world doctor # health check: files, keys, a real LLM call, clock speed
186
+ anima-world config # read/write settings, secrets encrypted and masked
187
+ anima-world run # foreground host, no onboarding (for deployment)
188
+ anima-world simulate # headless fast-forward
189
+ anima-world world # export / import .cyberworld packages
190
+ ```
191
+
192
+ ## Documentation
193
+
194
+ | | |
195
+ |---|---|
196
+ | [docs/REFERENCE.md](https://github.com/aubrey-anima/core/blob/main/docs/REFERENCE.md) | Every command, every `World` method, every config key, the beat-script format 🇨🇳 |
197
+ | [docs/ARCHITECTURE.md](https://github.com/aubrey-anima/core/blob/main/docs/ARCHITECTURE.md) | Why it is shaped this way: the truth model, the tick frame, threads and locks, invariants, known debt 🇨🇳 |
198
+ | [CONTRIBUTING.md](https://github.com/aubrey-anima/core/blob/main/CONTRIBUTING.md) | Development setup, the invariants a patch must not break, how to propose changes |
199
+ | [CHANGELOG.md](https://github.com/aubrey-anima/core/blob/main/CHANGELOG.md) | Release history |
200
+
201
+ ## Contributing
202
+
203
+ Issues and pull requests are welcome. Start with [CONTRIBUTING.md](https://github.com/aubrey-anima/core/blob/main/CONTRIBUTING.md) —
204
+ it lists the handful of invariants that a change must not break (there is exactly one
205
+ lock in the system, the LLM is never called on the tick thread, and a few file formats
206
+ are mirrored by other repositories).
207
+
208
+ ## License
209
+
210
+ [Apache License 2.0](https://github.com/aubrey-anima/core/blob/main/LICENSE). Use it, modify it, ship it inside closed-source products;
211
+ keep the copyright notice and state what you changed. Apache rather than MIT for the
212
+ patent grant, and permissive rather than copyleft because an engine that hosts embed
213
+ cannot be copyleft without infecting every host that embeds it.