|
|
| import os |
| import sys |
| import time |
| import random |
| from tqdm import tqdm |
|
|
| |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) |
|
|
| from core.life_state import LifeMetrics, ResourceBudget |
| from core.lifestack_env import LifeStackEnv, LifeStackAction |
| from agent.agent import LifeStackAgent |
| from agent.memory import LifeStackMemory |
| from agent.conflict_generator import generate_conflict, TEMPLATES |
| from intake.simperson import PERSONS |
|
|
| def inject_wisdom(count=200): |
| print(f"🚀 Starting Wisdom Injection: Generating {count} expert precedents...") |
| |
| |
| agent = LifeStackAgent(api_only=True) |
| memory = LifeStackMemory(silent=True) |
| |
| |
| stored_count = 0 |
| start_time = time.time() |
| |
| |
| person_list = list(PERSONS.values()) |
| |
| for i in tqdm(range(count)): |
| try: |
| |
| env = LifeStackEnv() |
| |
| |
| difficulty = random.randint(2, 5) |
| person = random.choice(person_list) |
| conflict = generate_conflict(difficulty=difficulty) |
| |
| |
| env.reset(conflict=conflict.primary_disruption, budget=conflict.resource_budget) |
| |
| before_metrics = env.state.current_metrics |
| before_budget = env.state.budget |
| |
| |
| |
| action = agent.get_action(before_metrics, before_budget, conflict, person) |
| |
| |
| |
| uptake = person.respond_to_action(action.primary.action_type, action.primary.resource_cost, |
| before_metrics.mental_wellbeing.stress_level) |
| |
| env_action = LifeStackAction.from_agent_action(action) |
| |
| env_action.metric_changes = {k: v * uptake for k, v in action.primary.metric_changes.items()} |
| |
| obs = env.step(env_action) |
| |
| |
| if obs.reward > 0.4: |
| memory.store_decision( |
| conflict_title=conflict.title, |
| action_type=action.primary.action_type, |
| target_domain=action.primary.target_domain, |
| reward=obs.reward, |
| metrics_snapshot=before_metrics.flatten(), |
| reasoning=action.reasoning |
| ) |
| stored_count += 1 |
| |
| |
| |
| time.sleep(1.5) |
| |
| except Exception as e: |
| if "429" in str(e): |
| print(f"\n⚠️ Rate limit hit at step {i}. Waiting 30s...") |
| time.sleep(30) |
| else: |
| print(f"\n❌ Error at step {i}: {e}") |
| continue |
|
|
| end_time = time.time() |
| duration = end_time - start_time |
| print(f"\n✅ Wisdom Injection Complete!") |
| print(f" - Total Attempted: {count}") |
| print(f" - Expert Precedents Stored: {stored_count}") |
| print(f" - Time taken: {duration:.1f}s") |
| print(f"Memory now contains {memory.collection.count()} high-quality traces.") |
|
|
| if __name__ == "__main__": |
| |
| |
| inject_wisdom(count=200) |
|
|