rct-platform 1.0.2a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. core/__init__.py +5 -0
  2. core/delta_engine/__init__.py +0 -0
  3. core/delta_engine/memory_delta.py +342 -0
  4. core/fdia/__init__.py +0 -0
  5. core/fdia/fdia.py +441 -0
  6. core/intent_loop/__init__.py +29 -0
  7. core/py.typed +0 -0
  8. core/regional_adapter/__init__.py +0 -0
  9. core/regional_adapter/regional_adapter.py +670 -0
  10. microservices/analysearch-intent/app/__init__.py +0 -0
  11. microservices/analysearch-intent/app/api/__init__.py +0 -0
  12. microservices/analysearch-intent/app/api/routes.py +234 -0
  13. microservices/analysearch-intent/app/core/__init__.py +0 -0
  14. microservices/analysearch-intent/app/core/analysearch_engine.py +848 -0
  15. microservices/analysearch-intent/app/core/blueprint_generator.py +156 -0
  16. microservices/analysearch-intent/app/core/semantic_matcher.py +142 -0
  17. microservices/analysearch-intent/app/main.py +92 -0
  18. microservices/analysearch-intent/app/models/__init__.py +0 -0
  19. microservices/analysearch-intent/app/services/__init__.py +0 -0
  20. microservices/analysearch-intent/conftest.py +5 -0
  21. microservices/crystallizer/__init__.py +3 -0
  22. microservices/crystallizer/crystallizer.py +450 -0
  23. microservices/crystallizer/example_usage.py +172 -0
  24. microservices/gateway-api/gateway_main.py +321 -0
  25. microservices/gateway-api/genome_api.py +113 -0
  26. microservices/intent-loop/__init__.py +43 -0
  27. microservices/intent-loop/conftest.py +3 -0
  28. microservices/intent-loop/loop_engine.py +604 -0
  29. microservices/vector-search/app/__init__.py +2 -0
  30. microservices/vector-search/app/api/__init__.py +1 -0
  31. microservices/vector-search/app/api/routes.py +307 -0
  32. microservices/vector-search/app/backends/__init__.py +1 -0
  33. microservices/vector-search/app/backends/faiss_backend.py +342 -0
  34. microservices/vector-search/app/backends/qdrant_backend.py +340 -0
  35. microservices/vector-search/app/core/__init__.py +1 -0
  36. microservices/vector-search/app/core/vector_engine.py +421 -0
  37. microservices/vector-search/app/main.py +149 -0
  38. microservices/vector-search/app/models/__init__.py +1 -0
  39. microservices/vector-search/app/models/schemas.py +365 -0
  40. microservices/vector-search/conftest.py +90 -0
  41. rct_control_plane/__init__.py +67 -0
  42. rct_control_plane/api.py +821 -0
  43. rct_control_plane/cli.py +1222 -0
  44. rct_control_plane/control_plane_state.py +356 -0
  45. rct_control_plane/default_policies.py +329 -0
  46. rct_control_plane/dsl_parser.py +557 -0
  47. rct_control_plane/execution_graph_ir.py +542 -0
  48. rct_control_plane/intent_compiler.py +572 -0
  49. rct_control_plane/intent_schema.py +384 -0
  50. rct_control_plane/intent_templates/__init__.py +14 -0
  51. rct_control_plane/intent_templates/build_app_template.py +392 -0
  52. rct_control_plane/intent_templates/refactor_template.py +295 -0
  53. rct_control_plane/jitna_protocol.py +368 -0
  54. rct_control_plane/middleware.py +459 -0
  55. rct_control_plane/observability.py +415 -0
  56. rct_control_plane/policy_language.py +484 -0
  57. rct_control_plane/py.typed +0 -0
  58. rct_control_plane/replay_engine.py +309 -0
  59. rct_control_plane/rich_formatter.py +442 -0
  60. rct_control_plane/signed_execution.py +216 -0
  61. rct_platform-1.0.2a0.dist-info/METADATA +684 -0
  62. rct_platform-1.0.2a0.dist-info/RECORD +72 -0
  63. rct_platform-1.0.2a0.dist-info/WHEEL +5 -0
  64. rct_platform-1.0.2a0.dist-info/entry_points.txt +2 -0
  65. rct_platform-1.0.2a0.dist-info/licenses/LICENSE +201 -0
  66. rct_platform-1.0.2a0.dist-info/top_level.txt +4 -0
  67. signedai/__init__.py +5 -0
  68. signedai/core/__init__.py +55 -0
  69. signedai/core/models.py +252 -0
  70. signedai/core/registry.py +415 -0
  71. signedai/core/router.py +145 -0
  72. signedai/py.typed +0 -0
core/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Core public package metadata for RCT Platform."""
2
+
3
+ __version__ = "1.0.2a0"
4
+
5
+ __all__ = ["__version__"]
File without changes
@@ -0,0 +1,342 @@
1
+ """
2
+ RCT NPC Kernel — Memory Delta Engine (Plan 21)
3
+
4
+ Design principle:
5
+ Instead of storing full agent state at every tick (expensive),
6
+ only store what CHANGED (delta). This achieves the 74% compression
7
+ target documented in RCT-NPC-System-Analysis-1.md.
8
+
9
+ Memory layout per agent:
10
+ baseline_state → full state at tick 0 (or last checkpoint)
11
+ deltas[] → ordered list of (tick, what_changed) records
12
+
13
+ Queries:
14
+ get_state_at_tick(agent_id, tick) → reconstruct by replaying deltas
15
+ replay_to_tick(agent_id, tick) → synonym; returns reconstructed state
16
+ rollback(agent_id, n_ticks) → drop last n delta records
17
+ compute_compression_ratio() → vs naïve full-state storage
18
+
19
+ Layer: Memory subsystem (no imports from other NPC kernel modules except fdia.NPCIntentType)
20
+ """
21
+
22
+ from __future__ import annotations
23
+ from dataclasses import dataclass, field
24
+ from typing import Dict, List, Optional, Any
25
+ import copy
26
+
27
+ from core.fdia.fdia import NPCIntentType
28
+
29
+
30
+ # ---------------------------------------------------------------------------
31
+ # Delta Record
32
+ # ---------------------------------------------------------------------------
33
+
34
+ @dataclass
35
+ class MemoryDelta:
36
+ """
37
+ A single state-change record for one agent at one tick.
38
+
39
+ Stores only the DIFF versus the previous state —
40
+ fields that did not change are absent from `changes`.
41
+ """
42
+ agent_id: str
43
+ tick: int
44
+ intent_type: NPCIntentType
45
+ action_type: str
46
+ outcome: str # "success", "blocked", "partial"
47
+ changes: Dict[str, Any] = field(default_factory=dict)
48
+ # relationship_change: {other_agent_id: delta_alignment_float}
49
+ relationship_change: Dict[str, float] = field(default_factory=dict)
50
+ governance_violation: bool = False
51
+ resources_delta: Dict[str, float] = field(default_factory=dict) # gained/lost
52
+
53
+ def to_dict(self) -> Dict[str, Any]:
54
+ return {
55
+ "agent_id": self.agent_id,
56
+ "tick": self.tick,
57
+ "intent_type": self.intent_type.value,
58
+ "action_type": self.action_type,
59
+ "outcome": self.outcome,
60
+ "changes": self.changes,
61
+ "relationship_change": {
62
+ k: round(v, 6) for k, v in sorted(self.relationship_change.items())
63
+ },
64
+ "governance_violation": self.governance_violation,
65
+ "resources_delta": {
66
+ k: round(v, 6) for k, v in sorted(self.resources_delta.items())
67
+ },
68
+ }
69
+
70
+
71
+ # ---------------------------------------------------------------------------
72
+ # Agent Memory State (reconstructed at query time)
73
+ # ---------------------------------------------------------------------------
74
+
75
+ @dataclass
76
+ class AgentMemoryState:
77
+ """Full reconstructed state of an agent at a specific tick."""
78
+ agent_id: str
79
+ tick: int
80
+ intent_type: NPCIntentType
81
+ resources: Dict[str, float] = field(default_factory=dict)
82
+ reputation: float = 1.0
83
+ relationships: Dict[str, float] = field(default_factory=dict) # other_id → alignment
84
+ action_history: List[str] = field(default_factory=list) # ordered action types
85
+ violation_count: int = 0
86
+
87
+ def to_dict(self) -> Dict[str, Any]:
88
+ return {
89
+ "agent_id": self.agent_id,
90
+ "tick": self.tick,
91
+ "intent_type": self.intent_type.value,
92
+ "resources": {k: round(v, 6) for k, v in sorted(self.resources.items())},
93
+ "reputation": round(self.reputation, 6),
94
+ "relationships": {k: round(v, 6) for k, v in sorted(self.relationships.items())},
95
+ "action_history_len": len(self.action_history),
96
+ "violation_count": self.violation_count,
97
+ }
98
+
99
+
100
+ # ---------------------------------------------------------------------------
101
+ # Memory Delta Engine
102
+ # ---------------------------------------------------------------------------
103
+
104
+ @dataclass
105
+ class MemoryDeltaEngine:
106
+ """
107
+ Stores per-agent memory as compressed delta sequences.
108
+
109
+ Compression approach:
110
+ - Baseline: full state snapshot at initialization (or last checkpoint)
111
+ - Delta: only changed fields per tick
112
+ - Naive: would store full state every tick → O(agents × ticks × state_size)
113
+ - Delta: O(agents × changed_fields_per_tick) ≈ 26% of naive
114
+
115
+ Thread safety: NOT thread-safe — call only from the simulation loop.
116
+ """
117
+
118
+ # baseline_states[agent_id] → initial full state dict
119
+ baseline_states: Dict[str, AgentMemoryState] = field(default_factory=dict)
120
+ # deltas[agent_id] → ordered list of MemoryDelta (sorted by tick ascending)
121
+ deltas: Dict[str, List[MemoryDelta]] = field(default_factory=dict)
122
+ # naive_byte_count: estimated bytes if we stored full state each tick
123
+ _naive_byte_count: int = field(default=0, repr=False)
124
+ # delta_byte_count: estimated bytes with delta storage
125
+ _delta_byte_count: int = field(default=0, repr=False)
126
+ # checkpoint_interval: create full snapshot every N ticks for fast replay
127
+ checkpoint_interval: int = 50
128
+ _checkpoints: Dict[str, Dict[int, AgentMemoryState]] = field(
129
+ default_factory=dict, repr=False
130
+ )
131
+
132
+ # --- registration -------------------------------------------------------
133
+
134
+ def register_agent(
135
+ self,
136
+ agent_id: str,
137
+ initial_intent: "NPCIntentType | AgentMemoryState",
138
+ initial_resources: Optional[Dict[str, float]] = None,
139
+ initial_reputation: float = 1.0,
140
+ ) -> None:
141
+ """Register a new agent with its initial state.
142
+
143
+ Two call styles are supported:
144
+
145
+ Style A — positional (preferred):
146
+ engine.register_agent("hero", NPCIntentType.DISCOVER,
147
+ {"energy": 100.0}, reputation=0.8)
148
+
149
+ Style B — AgentMemoryState object (convenience):
150
+ engine.register_agent("hero", AgentMemoryState(
151
+ agent_id="hero", tick=0,
152
+ intent_type=NPCIntentType.DISCOVER,
153
+ resources={"energy": 100.0}, reputation=0.8))
154
+ """
155
+ # Style B: caller passed a pre-built AgentMemoryState as second arg
156
+ if isinstance(initial_intent, AgentMemoryState):
157
+ snapshot = initial_intent
158
+ baseline = AgentMemoryState(
159
+ agent_id=agent_id,
160
+ tick=0,
161
+ intent_type=snapshot.intent_type,
162
+ resources=dict(snapshot.resources),
163
+ reputation=snapshot.reputation,
164
+ relationships=dict(snapshot.relationships),
165
+ action_history=list(snapshot.action_history),
166
+ violation_count=snapshot.violation_count,
167
+ )
168
+ else:
169
+ # Style A: positional NPCIntentType
170
+ baseline = AgentMemoryState(
171
+ agent_id=agent_id,
172
+ tick=0,
173
+ intent_type=initial_intent,
174
+ resources=dict(initial_resources or {}),
175
+ reputation=initial_reputation,
176
+ )
177
+ self.baseline_states[agent_id] = baseline
178
+ self.deltas[agent_id] = []
179
+ self._checkpoints[agent_id] = {0: copy.deepcopy(baseline)}
180
+
181
+ # --- recording ----------------------------------------------------------
182
+
183
+ def record_delta(
184
+ self,
185
+ agent_id: str,
186
+ tick: int,
187
+ intent_type: NPCIntentType,
188
+ action_type: str,
189
+ outcome: str,
190
+ resource_changes: Optional[Dict[str, float]] = None,
191
+ relationship_changes: Optional[Dict[str, float]] = None,
192
+ governance_violation: bool = False,
193
+ extra_changes: Optional[Dict[str, Any]] = None,
194
+ ) -> None:
195
+ """
196
+ Append a delta record for *agent_id* at *tick*.
197
+
198
+ Only the supplied fields are stored — absent fields mean "unchanged".
199
+ """
200
+ if agent_id not in self.deltas:
201
+ raise KeyError(f"Agent '{agent_id}' not registered. Call register_agent() first.")
202
+
203
+ delta = MemoryDelta(
204
+ agent_id=agent_id,
205
+ tick=tick,
206
+ intent_type=intent_type,
207
+ action_type=action_type,
208
+ outcome=outcome,
209
+ resources_delta=dict(resource_changes or {}),
210
+ relationship_change=dict(relationship_changes or {}),
211
+ governance_violation=governance_violation,
212
+ changes=dict(extra_changes or {}),
213
+ )
214
+ self.deltas[agent_id].append(delta)
215
+
216
+ # Estimate sizes for compression ratio
217
+ # Naive: one full AgentMemoryState dict ≈ 200 bytes
218
+ # Delta: one MemoryDelta dict ≈ len(changes)*30 bytes
219
+ self._naive_byte_count += 200
220
+ self._delta_byte_count += max(30, len(str(delta.to_dict())))
221
+
222
+ # Create checkpoint if interval reached
223
+ all_deltas = self.deltas[agent_id]
224
+ if len(all_deltas) % self.checkpoint_interval == 0 and all_deltas:
225
+ state = self._reconstruct(agent_id, tick)
226
+ self._checkpoints[agent_id][tick] = copy.deepcopy(state)
227
+
228
+ # --- querying -----------------------------------------------------------
229
+
230
+ def get_state_at_tick(self, agent_id: str, tick: int) -> Optional[AgentMemoryState]:
231
+ """
232
+ Reconstruct full agent state at *tick* by replaying deltas from
233
+ the nearest prior checkpoint.
234
+ """
235
+ if agent_id not in self.baseline_states:
236
+ return None
237
+ return self._reconstruct(agent_id, tick)
238
+
239
+ def replay_to_tick(self, agent_id: str, target_tick: int) -> Optional[AgentMemoryState]:
240
+ """Alias for get_state_at_tick for semantics clarity."""
241
+ return self.get_state_at_tick(agent_id, target_tick)
242
+
243
+ def rollback(self, agent_id: str, n_ticks: int) -> int:
244
+ """
245
+ Remove the last *n_ticks* delta records for *agent_id*.
246
+ Returns number of records actually removed.
247
+ """
248
+ if agent_id not in self.deltas:
249
+ return 0
250
+ agent_deltas = self.deltas[agent_id]
251
+ remove = min(n_ticks, len(agent_deltas))
252
+ self.deltas[agent_id] = agent_deltas[: len(agent_deltas) - remove]
253
+ # Invalidate checkpoints that are now ahead of the rolled-back tick
254
+ if agent_deltas and remove < len(agent_deltas):
255
+ new_last_tick = agent_deltas[-1].tick if self.deltas[agent_id] else 0
256
+ stale = [t for t in self._checkpoints.get(agent_id, {}) if t > new_last_tick]
257
+ for t in stale:
258
+ del self._checkpoints[agent_id][t]
259
+ return remove
260
+
261
+ def get_recent_actions(self, agent_id: str, n: int = 5) -> List[str]:
262
+ """Return the last *n* action types for *agent_id*."""
263
+ agent_deltas = self.deltas.get(agent_id, [])
264
+ return [d.action_type for d in agent_deltas[-n:]]
265
+
266
+ def get_relationship_history(
267
+ self, agent_id: str, other_id: str
268
+ ) -> List[tuple]:
269
+ """Return (tick, delta_alignment) for all recorded interactions."""
270
+ result = []
271
+ for d in self.deltas.get(agent_id, []):
272
+ if other_id in d.relationship_change:
273
+ result.append((d.tick, d.relationship_change[other_id]))
274
+ return result
275
+
276
+ def get_violation_count(self, agent_id: str) -> int:
277
+ return sum(
278
+ 1 for d in self.deltas.get(agent_id, []) if d.governance_violation
279
+ )
280
+
281
+ # --- compression metric -------------------------------------------------
282
+
283
+ def compute_compression_ratio(self) -> float:
284
+ """
285
+ Ratio: 1 - (delta_bytes / naive_bytes)
286
+ 0.74 means delta storage uses 26% of naïve storage → 74% compression.
287
+ Returns 0.0 if no data recorded yet.
288
+ """
289
+ if self._naive_byte_count == 0:
290
+ return 0.0
291
+ ratio = 1.0 - (self._delta_byte_count / self._naive_byte_count)
292
+ return max(0.0, min(1.0, ratio))
293
+
294
+ def total_delta_count(self) -> int:
295
+ return sum(len(v) for v in self.deltas.values())
296
+
297
+ def registered_agent_count(self) -> int:
298
+ return len(self.baseline_states)
299
+
300
+ # --- private helpers ----------------------------------------------------
301
+
302
+ def _reconstruct(self, agent_id: str, target_tick: int) -> AgentMemoryState:
303
+ """
304
+ Internal: reconstruct state at target_tick from nearest checkpoint.
305
+ """
306
+ # Find the nearest checkpoint at or before target_tick
307
+ checkpoints = self._checkpoints.get(agent_id, {})
308
+ valid_cps = {t: s for t, s in checkpoints.items() if t <= target_tick}
309
+
310
+ if valid_cps:
311
+ nearest_tick = max(valid_cps.keys())
312
+ state = copy.deepcopy(valid_cps[nearest_tick])
313
+ else:
314
+ state = copy.deepcopy(self.baseline_states[agent_id])
315
+ nearest_tick = 0
316
+
317
+ # Replay deltas from nearest_tick+1 to target_tick
318
+ for delta in self.deltas.get(agent_id, []):
319
+ if delta.tick <= nearest_tick:
320
+ continue
321
+ if delta.tick > target_tick:
322
+ break
323
+ # Apply resource changes
324
+ for res, change in delta.resources_delta.items():
325
+ state.resources[res] = state.resources.get(res, 0.0) + change
326
+ # Apply relationship changes
327
+ for other_id, change in delta.relationship_change.items():
328
+ state.relationships[other_id] = (
329
+ state.relationships.get(other_id, 0.0) + change
330
+ )
331
+ # Apply outcome effects
332
+ if delta.outcome == "success":
333
+ state.reputation = min(1.0, state.reputation + 0.01)
334
+ elif delta.outcome == "blocked" and delta.governance_violation:
335
+ state.reputation = max(0.0, state.reputation - 0.05)
336
+ state.violation_count += 1
337
+ # Append action
338
+ state.action_history.append(delta.action_type)
339
+ state.tick = delta.tick
340
+
341
+ state.tick = target_tick
342
+ return state
core/fdia/__init__.py ADDED
File without changes