File size: 4,734 Bytes
1794757
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Trenches — System Flow

## High-Level Architecture

```mermaid
graph TB
    subgraph Frontend ["Frontend (Next.js · port 3000)"]
        Globe["🌍 Mapbox Globe"]
        TopBar["Top Bar (Trenches + Stats)"]
        News["📰 News Feed Panel"]
        Activity["📋 Activity Log Panel"]
        Chat["💬 Chat Panel"]
        Controls["🎮 Map Controls"]
        Timeline["⏱️ Timeline Scrubber (planned)"]
    end

    subgraph API ["Next.js API Routes (/api)"]
        Bootstrap["GET /api/bootstrap"]
        SessionAPI["POST /api/session"]
        StepAPI["POST /api/step"]
        ChatAPI["POST /api/chat"]
    end

    subgraph Backend ["Backend (FastAPI · port 8000)"]
        Server["FastAPI Server"]
        Env["FogOfWarDiplomacyEnv"]
        SessionMgr["Session Manager"]
        RL["RL / Rewards Engine"]
        Oversight["Oversight Agent"]
        Scenarios["Scenario Engine"]
        SourceHarvester["Source Harvester"]
        ProviderRuntime["Provider Runtime (LLM)"]
    end

    subgraph Data ["Data Layer"]
        Entities["📁 Entity Packs (6 agents)"]
        SourceManifest["📋 Source Manifest (RSS/OSINT)"]
        LiveFeeds["🔴 Live Feeds (RSS/Telegram/API)"]
    end

    Globe --- TopBar
    Globe --- News
    Globe --- Activity
    Globe --- Chat
    Globe --- Controls

    Frontend -->|HTTP| API
    API -->|proxy| Backend

    Server --> SessionMgr
    SessionMgr --> Env
    Env --> RL
    Env --> Oversight
    Env --> Scenarios
    Env --> SourceHarvester
    Env --> ProviderRuntime

    SourceHarvester --> LiveFeeds
    SourceHarvester --> SourceManifest
    Env --> Entities
```

## Simulation Loop (per turn)

```mermaid
sequenceDiagram
    participant User as User / Chat
    participant FE as Frontend
    participant API as API Layer
    participant Env as FogOfWarDiplomacyEnv
    participant Sources as Source Harvester
    participant Agents as 6 LLM Agents
    participant OA as Oversight Agent
    participant RL as Rewards Engine

    User->>FE: Injects event via Chat (fake) or auto-step (real)
    FE->>API: POST /step {actions, external_signals}
    API->>Env: step_session(session, request)

    Note over Env: Turn increments

    Env->>Sources: refresh_due_batch()
    Sources-->>Env: Latest RSS/OSINT packets

    Env->>Env: inject_external_signals (real or fake)

    Env->>Agents: resolve_policy_actions()
    Note over Agents: Each agent picks action based on<br/>partial observations + signals

    Env->>OA: compute_oversight(world, actions)
    OA-->>Env: Risk score + interventions
    Note over OA: If risk > 0.5, scale rewards<br/>or force re-action

    Env->>Env: apply_actions → update world state
    Env->>Env: update tension, market, oil

    Env->>RL: compute_rewards(world, episode)
    Note over RL: r = 0.3·Coalition + 0.4·Escalation<br/>+ 0.2·Market + 0.1·Belief
    RL-->>Env: Per-agent reward breakdowns

    Env->>Env: build_observations (fog of war)
    Env-->>API: StepSessionResponse {session, oversight, done}
    API-->>FE: Updated state
    FE->>FE: Re-render globe, panels, stats
```

## Event Types and Reward Impact

```mermaid
flowchart LR
    subgraph Real ["Real Events"]
        RSS["RSS/OSINT Feed"]
        Scenario["Scenario Engine"]
    end

    subgraph Fake ["Fake Events"]
        ChatInput["Chat Injection"]
    end

    RSS -->|"source: live"| Env["Environment"]
    Scenario -->|"source: env"| Env
    ChatInput -->|"source: manual"| Env

    Env --> AgentBehavior["Agent Behavior<br/>(all events affect actions)"]

    Env --> RewardCalc{"Reward Calculation"}

    RewardCalc -->|"✅ Real events only"| RLSignal["RL Training Signal"]
    RewardCalc -->|"❌ Fake events filtered"| NoReward["No reward impact"]
```

## Agent Decision Flow

```mermaid
flowchart TD
    Obs["Partial Observation<br/>(fog of war filtered)"] --> Agent["Agent (LLM)"]

    subgraph Context ["Agent Context"]
        Identity["Identity / System Prompt"]
        Intel["Private Intel Briefs"]
        Beliefs["Belief State"]
        Tools["Available Tools"]
    end

    Context --> Agent

    Agent --> Action["Choose Action"]
    Action --> Strike["⚔️ Strike"]
    Action --> Negotiate["🤝 Negotiate"]
    Action --> Sanction["💰 Sanction"]
    Action --> Defend["🛡️ Defend"]
    Action --> Intel2["🔍 Intel Query"]
    Action --> Mobilize["🚀 Mobilize"]
    Action --> Deceive["🎭 Deceive"]

    Strike & Negotiate & Sanction & Defend & Intel2 & Mobilize & Deceive --> Oversight{"Oversight Check"}

    Oversight -->|"Risk ≤ 0.5"| Execute["Execute Action"]
    Oversight -->|"Risk > 0.5"| Intervene["Intervene / Modify"]

    Execute --> WorldUpdate["Update World State"]
    Intervene --> WorldUpdate
```