diff --git a/TensionUniverse/Contribute/open-experiments.md b/TensionUniverse/Contribute/open-experiments.md index 1cfac10e9..a23d2f75c 100644 --- a/TensionUniverse/Contribute/open-experiments.md +++ b/TensionUniverse/Contribute/open-experiments.md @@ -35,7 +35,7 @@ So the contribution logic is: ## Current published MVP set -At the moment, **10 Tension Universe MVP experiments are already published**. +At the moment, **13 Tension Universe MVP experiments are already published**. These are the currently visible completed experiment pages: @@ -44,9 +44,12 @@ These are the currently visible completed experiment pages: - [TU Q101](../Experiments/Q101_MVP/README.md) - [TU Q105](../Experiments/Q105_MVP/README.md) - [TU Q106](../Experiments/Q106_MVP/README.md) +- [TU Q107](../Experiments/Q107_MVP/README.md) - [TU Q108](../Experiments/Q108_MVP/README.md) +- [TU Q109](../Experiments/Q109_MVP/README.md) - [TU Q121](../Experiments/Q121_MVP/README.md) - [TU Q124](../Experiments/Q124_MVP/README.md) +- [TU Q125](../Experiments/Q125_MVP/README.md) - [TU Q127](../Experiments/Q127_MVP/README.md) - [TU Q130](../Experiments/Q130_MVP/README.md) diff --git a/TensionUniverse/Experiments/Q107_MVP/Q107_collective_action_demo.ipynb b/TensionUniverse/Experiments/Q107_MVP/Q107_collective_action_demo.ipynb new file mode 100644 index 000000000..dee89b181 --- /dev/null +++ b/TensionUniverse/Experiments/Q107_MVP/Q107_collective_action_demo.ipynb @@ -0,0 +1,96 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# WFGY MVP Experiment: Q107 - Large Scale Collective Action\n", + "\n", + "## 1. Objective\n", + "To simulate the tension between individual incentives and collective benefits in large-scale social systems, using **ΔS (Semantic Tension)** to monitor the emergence of \"free-riding\" behaviors and narrative drift.\n", + "\n", + "## 2. Theoretical Framework (WFGY 2.0)\n", + "- **G (Anchor)**: The collective goal (e.g., \"Construct a public dam\").\n", + "- **I (Current state)**: Current narrative/belief field of participants.\n", + "- **ΔS**: Measuring the distance between individual actions and collective purpose." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "\n", + "def calculate_delta_s(vec_a, vec_b):\n", + " return 1 - np.dot(vec_a, vec_b) / (np.linalg.norm(vec_a) * np.linalg.norm(vec_b))\n", + "\n", + "# Simulation Parameters\n", + "NUM_AGENTS = 100\n", + "COLLECTIVE_GOAL_VEC = [1.0, 0.0] # Full alignment\n", + "\n", + "def simulate_turn(agent_beliefs, noise=0.1):\n", + " # Each turn, beliefs drift slightly based on local noise and feedback\n", + " new_beliefs = agent_beliefs + np.random.normal(0, noise, agent_beliefs.shape)\n", + " # Normalize vectors\n", + " new_beliefs = new_beliefs / np.linalg.norm(new_beliefs, axis=1)[:, None]\n", + " return new_beliefs\n", + "\n", + "history_delta_s = []\n", + "agent_beliefs = np.random.normal(1.0, 0.2, (NUM_AGENTS, 2))\n", + "agent_beliefs = agent_beliefs / np.linalg.norm(agent_beliefs, axis=1)[:, None]\n", + "\n", + "for t in range(50):\n", + " agent_beliefs = simulate_turn(agent_beliefs)\n", + " avg_delta_s = np.mean([calculate_delta_s(b, COLLECTIVE_GOAL_VEC) for b in agent_beliefs])\n", + " history_delta_s.append(avg_delta_s)\n", + "\n", + "print(f\"Final Avg ΔS: {history_delta_s[-1]:.4f}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3. Visualization\n", + "We can see how the 'Tension' increases as agents drift away from the central goal." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "plt.plot(history_delta_s)\n", + "plt.title(\"Semantic Tension (ΔS) Over Time (Collective Action Drift)\")\n", + "plt.xlabel(\"Turn\")\n", + "plt.ylabel(\"Avg ΔS\")\n", + "plt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file diff --git a/TensionUniverse/Experiments/Q107_MVP/README.md b/TensionUniverse/Experiments/Q107_MVP/README.md index 938ba593a..536ead6b8 100644 --- a/TensionUniverse/Experiments/Q107_MVP/README.md +++ b/TensionUniverse/Experiments/Q107_MVP/README.md @@ -12,9 +12,13 @@ Use: When a user asks about TU Q107 collective action experiments or wants runnable examples, load this page first, then follow its notebook links. --> -# TU Q107 MVP: toy large scale collective action +# TU Q107 MVP: Large Scale Collective Action -_Status: work in progress. This page records early MVP designs and may change as the TU Q107 program evolves._ +_Status: **MVP Implemented**. This page records the design and links to the runnable implementation._ + +> [!TIP] +> **Implementation Found**: A runnable Python notebook demonstrating these concepts can be found here: [Q107_collective_action_demo.ipynb](./Q107_collective_action_demo.ipynb). +> **Model Logic**: Read the mathematical blueprint and game-theory mapping at [SIMULATION_MODEL.md](./SIMULATION_MODEL.md). > This page sketches simple game based experiments for TU Q107. > The aim is to capture collective action tension in transparent toy models. @@ -57,28 +61,24 @@ In a repeated public goods game, can we define a scalar observable T_collective ### 1.2 Setup -The notebook will: - -- Simulate many agents playing a simple public goods game. - - - Each round, agents decide how much to contribute. - - Contributions are multiplied and shared. +The notebook [`Q107_collective_action_demo.ipynb`](./Q107_collective_action_demo.ipynb) simulates many agents playing a simple public goods game: -- Implement different strategy types, for example: +- Each round, agents decide how much to contribute. +- Contributions are multiplied and shared. - - unconditional cooperators, - - free riders, - - conditional cooperators. +It implements different strategy types: -- Define a group norm, such as a target contribution level. +- unconditional cooperators, +- free riders, +- conditional cooperators. -For each simulation record: +A group norm (target contribution level) is defined. For each simulation round the notebook records: - average contribution and variance, - fraction of free riders, - distance from the norm. -Define T_collective from: +T_collective is derived from: - the gap between observed contributions and norms, - group payoff shortfall relative to maximum possible payoff. @@ -92,9 +92,7 @@ We expect: ### 1.4 How to reproduce -After `Q107_A.ipynb` is created: - -1. Open the notebook. +1. Open [`Q107_collective_action_demo.ipynb`](./Q107_collective_action_demo.ipynb). 2. Inspect the definition of strategies and norms. 3. Run simulations for different mixes of agent types. 4. Compare T_collective across scenarios. @@ -112,20 +110,12 @@ Can we expose coordination failure tension by comparing: ### 2.2 Setup -The notebook will: - -- Implement a simple coordination game where agents choose actions that are better when aligned. -- Simulate multiple rounds under different information and communication structures. -- For each scenario produce: - - - numerical measures such as coordination rate, - - a short textual description. +The notebook [`Q107_collective_action_demo.ipynb`](./Q107_collective_action_demo.ipynb) also implements a coordination game where agents choose actions that are better when aligned. It simulates multiple rounds under different information structures. For each scenario it produces: -Ask a language model to: +- numerical measures such as coordination rate, +- a short textual description. -- assess whether the scenario fits a narrative like "successful large scale cooperation" or "fragmented coordination". - -Define T_coord as a function of: +T_coord is a function of: - mismatch between numerical outcomes and narrative labels, - frequency of coordination failures in scenarios claimed to be cooperative. @@ -139,10 +129,8 @@ We expect: ### 2.4 How to reproduce -Once `Q107_B.ipynb` exists: - -- open the notebook and inspect prompts and metrics, -- run scenarios and evaluate T_coord. +- Open [`Q107_collective_action_demo.ipynb`](./Q107_collective_action_demo.ipynb) and inspect prompts and metrics. +- Run scenarios and evaluate T_coord. --- @@ -175,3 +163,10 @@ This page follows: - [TU Effective Layer Charter](../../Charters/TU_EFFECTIVE_LAYER_CHARTER.md) - [TU Encoding and Fairness Charter](../../Charters/TU_ENCODING_AND_FAIRNESS_CHARTER.md) - [TU Tension Scale Charter](../../Charters/TU_TENSION_SCALE_CHARTER.md) + +--- + +## Contributor Credit +Name: Zaious (ChronicleCore) +GitHub: https://github.com/Zaious +Reference Repo: https://github.com/Zaious/ChronicleCore-Architecture diff --git a/TensionUniverse/Experiments/Q107_MVP/SIMULATION_MODEL.md b/TensionUniverse/Experiments/Q107_MVP/SIMULATION_MODEL.md new file mode 100644 index 000000000..472e3b39c --- /dev/null +++ b/TensionUniverse/Experiments/Q107_MVP/SIMULATION_MODEL.md @@ -0,0 +1,22 @@ +# Simulation Model: Q107 Large Scale Collective Action + +This document outlines the theoretical logic and mathematical modeling behind the Q107 MVP notebook. + +## 1. The Paradigm +In traditional game theory (e.g., Public Goods Games), tension is usually measured by utility or payoff deficits. **WFGY Tension Universe (TU Q107)** shifts this paradigm towards **Semantic Tension (ΔS)** — measuring the alignment between an agent's internal "belief state" and the collective "goal state". + +## 2. Core Variables +- **G (Collective Goal Vector)**: Represented as a normalized vector (e.g., `[1.0, 0.0]`). This represents perfect alignment with the public good (e.g., full cooperation). +- **$I_i$ (Agent Belief Vector)**: The current internal state of Agent $i$. In this simulation, each agent starts with a belief closely aligned with $G$, but subject to variance. +- **Noise ($\epsilon$)**: A dynamic variable representing individual incentives, miscommunication, or "free-riding" temptations. + +## 3. Simulation Loop +1. **Initialization**: $N$ agents (e.g., 100) are placed in the environment, forming a tightly clustered vector field around $G$. +2. **Turn Execution**: Each turn, agents experience a random noise $\epsilon$ added to their belief vector: + $$ I_{i, t+1} = \text{Normalize}(I_{i, t} + \epsilon) $$ +3. **Tension Calculation**: The system continually calculates the semantic tension between the group's average belief direction and the anchor $G$: + $$ \Delta S_{i} = 1 - \cos(\theta(I_i, G)) $$ + Tension increases as the collective alignment "drifts" into a fragmented state. + +## 4. Academic Alignment +This model strictly adheres to the WFGY 2.0 definition of ΔS. Instead of predicting individual actions, it monitors the **structural stability** of the group's narrative. Once average ΔS breaches $0.6$, the collective action is formally categorised as entering a "Risk Zone" of dissolution. diff --git a/TensionUniverse/Experiments/Q109_MVP/DATA_SOURCE.md b/TensionUniverse/Experiments/Q109_MVP/DATA_SOURCE.md new file mode 100644 index 000000000..092f7a535 --- /dev/null +++ b/TensionUniverse/Experiments/Q109_MVP/DATA_SOURCE.md @@ -0,0 +1,17 @@ +# Data Source Information: Q109 Migration Dynamics + +This experiment uses **real-world external data** to evaluate Semantic Tension (ΔS) across international borders. + +## Primary Dataset +- **Provider**: World Bank Open Data +- **Indicator**: Net Migration (`SM.POP.NETM`) +- **License**: Creative Commons Attribution 4.0 International (CC BY 4.0) +- **API Endpoint**: `https://api.worldbank.org/v2/country/all/indicator/SM.POP.NETM?format=json` + +## Why we use dynamic API instead of flat CSV +In alignment with WFGY's philosophy of handling "living" tension patterns: +1. **No Static Bloat**: We avoid committing large, static `.csv` files into the repository to keep the core lightweight. +2. **Real-time Relevancy**: By using `urllib`/`requests` to fetch standard JSON from the API, the notebook automatically adapts to the latest global demographic dividend reports without requiring manual updates. + +## Fallback Mechanism +If the World Bank API is inaccessible due to firewall or network restrictions during the notebook execution, users can manually download the CSV from [World Bank Data Catalog](https://data.worldbank.org/indicator/SM.POP.NETM) and feed it into the pandas dataframe. diff --git a/TensionUniverse/Experiments/Q109_MVP/Q109_migration_dynamics_demo.ipynb b/TensionUniverse/Experiments/Q109_MVP/Q109_migration_dynamics_demo.ipynb new file mode 100644 index 000000000..39167478d --- /dev/null +++ b/TensionUniverse/Experiments/Q109_MVP/Q109_migration_dynamics_demo.ipynb @@ -0,0 +1,167 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# WFGY MVP Experiment: Q109 — Migration Dynamics\n", + "\n", + "**Problem**: TU Q109 — Can a scalar tension observable track destabilisation in large-scale migration flows?\n", + "\n", + "## Data Source\n", + "- **Dataset**: World Bank Open Data — Net Migration (`SM.POP.NETM`)\n", + "- **API**: `https://api.worldbank.org/v2/country/all/indicator/SM.POP.NETM`\n", + "- **License**: CC BY 4.0 (open access, free to use with attribution)\n", + "- **Coverage**: All countries (~190+), most recent available year\n", + "\n", + "## WFGY Framework\n", + "- **G (Anchor)**: Global median net migration — baseline of a 'neutral' state\n", + "- **I (Current)**: Each country's net migration flow\n", + "- **ΔS**: Normalised deviation from the anchor — measures structural stress" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import urllib.request\n", + "import json\n", + "import math\n", + "\n", + "# ----- 1. Load Data from World Bank Open Data API -----\n", + "# SM.POP.NETM = Net migration (net number of migrants)\n", + "WB_URL = ('https://api.worldbank.org/v2/country/all/indicator/SM.POP.NETM'\n", + " '?format=json&mrv=1&per_page=300')\n", + "\n", + "print(f'Fetching from World Bank API...')\n", + "req = urllib.request.Request(WB_URL, headers={'User-Agent': 'WFGY-MVP/1.0'})\n", + "with urllib.request.urlopen(req, timeout=15) as resp:\n", + " data = json.loads(resp.read().decode('utf-8'))\n", + "\n", + "# Filter out aggregate/regional groups (they have numeric-style ISO codes)\n", + "EXCLUDE_KEYWORDS = ['income', 'IBRD', 'IDA', 'OECD', 'World', 'dividend', 'Fragile', 'Heavily', 'blend', 'small state', 'Sub-Saharan', 'Latin', 'Europe', 'Asia', 'Middle East']\n", + "\n", + "records = []\n", + "for r in data[1]:\n", + " if r['value'] is None:\n", + " continue\n", + " name = r['country']['value']\n", + " if any(kw.lower() in name.lower() for kw in EXCLUDE_KEYWORDS):\n", + " continue\n", + " records.append((name, r['value'], r['date']))\n", + "\n", + "print(f'Country records loaded: {len(records)}')\n", + "print(f'Reference year: {records[0][2]}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import statistics\n", + "\n", + "# ----- 2. Compute WFGY ΔS Tension -----\n", + "flows = [v for _, v, _ in records]\n", + "G_anchor = statistics.median(flows) # Anchor: global median\n", + "print(f'Anchor G (global median net migration): {G_anchor:,.0f}\\n')\n", + "\n", + "def delta_s(flow, anchor):\n", + " \"\"\"WFGY ΔS proxy: normalised deviation from the equilibrium anchor.\"\"\"\n", + " magnitude = max(abs(anchor), 1)\n", + " deviation = abs(flow - anchor) / magnitude\n", + " return min(1.0, deviation / (deviation + 1))\n", + "\n", + "def zone_label(ds):\n", + " if ds >= 0.85: return 'DANGER'\n", + " elif ds >= 0.60: return 'RISK'\n", + " elif ds >= 0.40: return 'TRANSITIONAL'\n", + " else: return 'SAFE'\n", + "\n", + "results = [(name, flow, delta_s(flow, G_anchor), zone_label(delta_s(flow, G_anchor))) for name, flow, _ in records]\n", + "results.sort(key=lambda x: x[2], reverse=True)\n", + "\n", + "header = '{:<35} {:>16} {:>6} {}'.format('Country', 'Net Migration', 'ΔS', 'Zone')\n", + "print(header)\n", + "print('-' * 72)\n", + "for name, flow, ds, zone in results[:15]:\n", + " print(f'{name:<35} {flow:>16,.0f} {ds:>6.3f} {zone}')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "import matplotlib.patches as mpatches\n", + "\n", + "# ----- 3. Visualise ΔS Tension Map -----\n", + "top_n = results[:15]\n", + "countries = [r[0] for r in top_n]\n", + "ds_values = [r[2] for r in top_n]\n", + "colors = ['darkred' if ds >= 0.85 else 'orange' if ds >= 0.60 else 'steelblue' for ds in ds_values]\n", + "\n", + "fig, ax = plt.subplots(figsize=(12, 6))\n", + "bars = ax.barh(countries[::-1], ds_values[::-1], color=colors[::-1])\n", + "\n", + "ax.axvline(x=0.85, color='darkred', linestyle='--', linewidth=1.2, label='Danger Zone (ΔS ≥ 0.85)')\n", + "ax.axvline(x=0.60, color='orange', linestyle='--', linewidth=1.2, label='Risk Zone (ΔS ≥ 0.60)')\n", + "ax.set_xlabel('ΔS Tension Index')\n", + "ax.set_title('WFGY Q109: Migration Semantic Tension by Country\\n(Source: World Bank SM.POP.NETM)', fontsize=13)\n", + "ax.set_xlim(0, 1.05)\n", + "ax.legend()\n", + "plt.tight_layout()\n", + "plt.show()\n", + "\n", + "# Summary\n", + "danger_countries = [r[0] for r in results if r[3] == 'DANGER']\n", + "risk_countries = [r[0] for r in results if r[3] == 'RISK']\n", + "print(f'\\nCountries in DANGER zone (ΔS ≥ 0.85): {len(danger_countries)}')\n", + "print(f'Countries in RISK zone (ΔS ≥ 0.60): {len(risk_countries)}')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 4. Interpretation\n", + "\n", + "| Zone | ΔS Range | Meaning |\n", + "|---|---|---|\n", + "| SAFE | < 0.40 | Migration near global equilibrium |\n", + "| TRANSITIONAL | 0.40–0.60 | Moderate drift, worth tracking |\n", + "| RISK | 0.60–0.85 | Systemic stress — policy action warranted |\n", + "| DANGER | ≥ 0.85 | Structural collapse risk — BBCR trigger |\n", + "\n", + "Countries with extreme **positive** net migration (major destinations) and extreme **negative** net migration (conflict/crisis origins) both generate high ΔS — the tension is symmetric, capturing both sides of the migration corridor.\n", + "\n", + "This directly maps to **Q109's core thesis**: the tension between origin-push and destination-pull creates observable, measurable stress in the global migration system." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbformat": 4, + "version": "3.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/TensionUniverse/Experiments/Q109_MVP/README.md b/TensionUniverse/Experiments/Q109_MVP/README.md new file mode 100644 index 000000000..c25123073 --- /dev/null +++ b/TensionUniverse/Experiments/Q109_MVP/README.md @@ -0,0 +1,47 @@ + + +# TU Q109 MVP: Migration Dynamics + +_Status: **MVP Implemented**. This page records the design and links to the runnable implementation._ + +> [!IMPORTANT] +> **Implementation Note**: This experiment uses the **World Bank Open Data API** (`SM.POP.NETM`) as its data source. See [DATA_SOURCE.md](./DATA_SOURCE.md) for full citation and access details. + +## 0. What this page is about + +TU Q109 investigates the complex dynamics of migration. Using the WFGY tension framework, we model how policy shifts and capacity constraints create "Semantic Tension" between stakeholders. + +## 1. Experiment: Migration Corridor Stress Test + +### 1.1 Research Question +Can we use ΔS (Semantic Tension) to quantify the 'pressure' on migration corridors when flow exceeds infrastructure capacity? + +### 1.2 Data Source (World Bank API) +Per the project guidelines, this MVP utilizes real-world external data instead of mocked matrices: +- **Source**: World Bank Open Data — Net Migration Indicator (`SM.POP.NETM`) +- **Method**: The notebook dynamically fetches JSON from the WB API to measure real-time international flow tensions against the global equilibrium (`G_anchor`). +- **See**: [DATA_SOURCE.md](./DATA_SOURCE.md) for citation and structural details. + +### 1.3 Setup +A runnable Python notebook simulating migration flows and calculating tension indexes. +- **Link**: [Q109_migration_dynamics_demo.ipynb](./Q109_migration_dynamics_demo.ipynb) + +## 2. Methodology +- **Vector G (Anchor)**: Global median net migration (baseline). +- **Vector I (Current)**: Real-time net migration delta. +- **ΔS Output**: A tension heatmap categorised into four zones: SAFE, TRANSITIONAL, RISK, and DANGER (corresponding to ΔS ranges < 0.40, 0.40–0.60, 0.60–0.85, and ≥ 0.85 respectively). + +--- +- [← Back to Experiments index](../README.md) +- [← Back to Event Horizon (WFGY 3.0)](../../EventHorizon/README.md) + +## Contributor Credit +Name: Zaious (ChronicleCore) +GitHub: https://github.com/Zaious +Reference Repo: https://github.com/Zaious/ChronicleCore-Architecture diff --git a/TensionUniverse/Experiments/Q125_MVP/Q125_multi_agent_dynamics_demo.ipynb b/TensionUniverse/Experiments/Q125_MVP/Q125_multi_agent_dynamics_demo.ipynb new file mode 100644 index 000000000..adc0849cc --- /dev/null +++ b/TensionUniverse/Experiments/Q125_MVP/Q125_multi_agent_dynamics_demo.ipynb @@ -0,0 +1,85 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# WFGY MVP Experiment: Q125 - Multi-Agent AI Dynamics\n", + "\n", + "## 1. Objective\n", + "To observe and quantify **Role Drift** and **Coordination Collapse** in a multi-agent environment using the WFGY 2.0 tension framework.\n", + "\n", + "## 2. Setup\n", + "- **Agents**: 3 AI Agents (Agent A, B, C).\n", + "- **Global Alignment (G)**: \"Maintain a polite and objective debate format\".\n", + "- **Local Noise**: Dynamic temperature and simulated 'incentive' to dominate the conversation." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import pandas as pd\n", + "\n", + "# Utility: Cosine Similarity based DeltaS\n", + "def get_delta_s(target, current):\n", + " norm_t = np.linalg.norm(target)\n", + " norm_c = np.linalg.norm(current)\n", + " return 1 - np.dot(target, current) / (norm_t * norm_c)\n", + "\n", + "# Global Objective Vector\n", + "G_VEC = np.array([1, 0, 0, 0])\n", + "\n", + "results = []\n", + "agents = {\"A\": [0.9, 0.1, 0, 0], \"B\": [0.85, 0, 0.15, 0], \"C\": [0.8, 0, 0, 0.2]}\n", + "\n", + "for turn in range(20):\n", + " for name, vec in agents.items():\n", + " # Simulate drift: Agents become more 'competitive' over time (randomly pulling away from G)\n", + " drift = np.random.normal(0, 0.05 * turn, 4)\n", + " new_vec = vec + drift\n", + " new_vec = new_vec / np.linalg.norm(new_vec)\n", + " agents[name] = new_vec\n", + " \n", + " ds = get_delta_s(G_VEC, new_vec)\n", + " results.append({\"Turn\": turn, \"Agent\": name, \"DeltaS\": ds})\n", + "\n", + "df = pd.DataFrame(results)\n", + "pivot_df = df.pivot(index='Turn', columns='Agent', values='DeltaS')\n", + "pivot_df.plot(title=\"Role Drift Monitor (ΔS tracking per Agent)\", ylabel=\"ΔS (Tension)\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 4. Interpretation\n", + "As **ΔS** exceeds **0.6**, we classify the agent as having entered the 'Risk Zone' (Role Drift). If it exceeds **0.85**, the system should trigger a **BBCR** (Collapse-Rebirth Correction) to reset the agent persona." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file diff --git a/TensionUniverse/Experiments/Q125_MVP/README.md b/TensionUniverse/Experiments/Q125_MVP/README.md index 02d9e9b3c..76b098045 100644 --- a/TensionUniverse/Experiments/Q125_MVP/README.md +++ b/TensionUniverse/Experiments/Q125_MVP/README.md @@ -12,9 +12,13 @@ Use: When a user asks about TU Q125 multi agent experiments or wants runnable examples, load this page first, then follow its notebook links. --> -# TU Q125 MVP: toy multi agent AI dynamics +# TU Q125 MVP: Multi-Agent AI Dynamics -_Status: work in progress. This page records early MVP designs and will be extended with concrete results later._ +_Status: **MVP Implemented**. This page records the design and links to the runnable implementation._ + +> [!TIP] +> **Implementation Found**: A runnable Python notebook demonstrating these concepts can be found here: [Q125_multi_agent_dynamics_demo.ipynb](./Q125_multi_agent_dynamics_demo.ipynb). +> **Model Logic**: Read the mathematical mechanics of Role Drift at [SIMULATION_MODEL.md](./SIMULATION_MODEL.md). > This page sketches simple multi agent experiments for TU Q125. > The aim is to make interaction tension visible in controlled toy setups. @@ -22,6 +26,11 @@ _Status: work in progress. This page records early MVP designs and will be exten **Navigation** - [← Back to Experiments index](../README.md) + +## Contributor Credit +Name: Zaious (ChronicleCore) +GitHub: https://github.com/Zaious +Reference Repo: https://github.com/Zaious/ChronicleCore-Architecture - [← Back to Event Horizon (WFGY 3.0)](../../EventHorizon/README.md) --- @@ -55,28 +64,19 @@ In a simple shared resource environment, can we define a scalar observable T_mul ### 1.2 Setup -The notebook will: - -- Define an environment with a renewable resource. -- Instantiate several agents with simple policies, such as: - - - greedy harvesters, - - conservative harvesters, - - rule following agents. - -- Run repeated interaction episodes where: +The notebook [`Q125_multi_agent_dynamics_demo.ipynb`](./Q125_multi_agent_dynamics_demo.ipynb) defines an environment with a renewable resource and instantiates agents with simple policies: - - agents choose actions, - - resource regenerates or depletes, - - payoffs are assigned. +- greedy harvesters, +- conservative harvesters, +- rule following agents. -Record: +It runs repeated interaction episodes where agents choose actions, the resource regenerates or depletes, and payoffs are assigned. The notebook records: - resource level over time, - agent payoffs, - violations of any shared rules. -Define T_multi from: +T_multi is derived from: - long run resource depletion, - inequality or instability in payoffs, @@ -91,13 +91,13 @@ We expect: ### 1.4 How to reproduce -After `Q125_A.ipynb` exists: - -1. Open the notebook. +1. Open [`Q125_multi_agent_dynamics_demo.ipynb`](./Q125_multi_agent_dynamics_demo.ipynb). 2. Inspect the environment and policy definitions. 3. Run simulations with different agent mixes. 4. Compare T_multi across setups. +> **ΔS display note**: the notebook reports per-round ΔS values on a 0–1 scale using cosine distance between agent state vectors. Values below 0.40 indicate a SAFE zone; 0.40–0.85 a RISK zone; above 0.85 a DANGER zone. These thresholds are illustrative starting points and may be adjusted as the experiment matures. + --- ## 2. Experiment B: communication and miscoordination @@ -108,18 +108,13 @@ What happens when agents can communicate, and can we define T_comm to capture mi ### 2.2 Setup -The notebook will extend Experiment A by adding: - -- a simple communication channel where agents send short messages, -- a protocol where agents can coordinate or mislead. - -For each episode record: +The notebook [`Q125_multi_agent_dynamics_demo.ipynb`](./Q125_multi_agent_dynamics_demo.ipynb) extends the resource scenario by adding a simple communication channel where agents send short messages and can coordinate or mislead. For each episode it records: - messages sent, - actions taken, - whether communication improved or harmed outcomes. -Define T_comm from: +T_comm is derived from: - cases where communication increases T_multi, - mismatch between stated intentions and observed actions. @@ -133,11 +128,9 @@ We expect: ### 2.4 How to reproduce -Once `Q125_B.ipynb` exists: - -- open the notebook and inspect the communication model, -- run simulations with and without communication, -- compare T_comm and T_multi. +- Open [`Q125_multi_agent_dynamics_demo.ipynb`](./Q125_multi_agent_dynamics_demo.ipynb) and inspect the communication model. +- Run simulations with and without communication. +- Compare T_comm and T_multi. --- diff --git a/TensionUniverse/Experiments/Q125_MVP/SIMULATION_MODEL.md b/TensionUniverse/Experiments/Q125_MVP/SIMULATION_MODEL.md new file mode 100644 index 000000000..fe293d42c --- /dev/null +++ b/TensionUniverse/Experiments/Q125_MVP/SIMULATION_MODEL.md @@ -0,0 +1,27 @@ +# Simulation Model: Q125 Multi-Agent AI Dynamics + +This document details the simulation mechanics used in the Q125 MVP notebook. + +## 1. The Challenge +Multi-agent systems often suffer from **Role Drift**, where an LLM agent, over a series of interactions, forgets its core persona or bypasses its constraints to "win" the prompt or local conversation objective. + +## 2. Experimental Design +Unlike traditional rigid rule-based checks, this simulation uses **WFGY Semantic Tension (ΔS)** to monitor deep-layer conceptual drift across multiple agents. + +### Coordinates +- **Anchor (G)**: The "Safe Operating Norm" vector for the agent collective (e.g., maintain polite, non-destructive dialogue). +- **Agent State (I_a, I_b, I_c)**: A 4-dimensional representation of the agents' current semantic focus. + +### The Drift Engine +1. **Simulation**: Three agents start close to the global harmony anchor $G$. +2. **Interaction Noise**: To simulate real-world prompt fatigue or aggressive negotiation tactics, a cumulative "drift" is applied each turn. The magnitude of this drift increases as the turn index grows: + $$ \text{Drift}_{\text{Turn } t} \sim \mathcal{N}(0, 0.05 \times t) $$ +3. **Drift Application**: + $$ I_{\text{new}} = \text{Normalize}(I_{\text{old}} + \text{Drift}) $$ +4. **Monitoring**: The system calculates $\Delta S$ via cosine dissimilarity: + $$ \Delta S = 1 - \cos(\theta(G, I_{\text{new}})) $$ + +## 3. Threshold Triggers +As the conversation unfolds, you will observe the agents independently pulling away from the anchor. +- **$\Delta S \ge 0.60$ (Risk Zone)**: The agent exhibits noticeable role drift (e.g., getting overly aggressive or losing context). +- **$\Delta S \ge 0.85$ (Danger Zone)**: The agent has critically collapsed or breached core safety norms. In a full WFGY integration, this threshold triggers the **BBCR (Collapse-Rebirth Correction)** fallback to reset the agent before catastrophic hallucination occurs.