File size: 5,501 Bytes
7fcf80a
 
 
6e9c156
 
7fcf80a
b908281
7fcf80a
 
 
 
 
6899cf3
b85cf68
6899cf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b85cf68
 
 
6899cf3
b85cf68
6899cf3
 
 
 
 
 
b85cf68
 
 
6899cf3
b85cf68
6899cf3
 
b85cf68
 
 
 
 
 
 
6899cf3
b85cf68
 
6899cf3
b85cf68
6899cf3
b85cf68
 
6899cf3
b85cf68
 
 
 
 
 
6899cf3
 
b85cf68
6899cf3
b85cf68
 
6899cf3
 
b85cf68
6899cf3
b85cf68
6899cf3
b85cf68
 
 
6899cf3
 
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
---
title: XCOM 2 Tactical Wingman
emoji: 🎯
colorFrom: blue
colorTo: indigo
sdk: streamlit
sdk_version: 1.38.0
app_file: app.py
pinned: false
license: mit
---

# 🎯 XCOM 2 Tactical Wingman

A local intelligent assistant (AI Agent) and strategic console designed to help XCOM 2 commanders make optimal base-building decisions, combat tactical choices, and soldier builds based on official guides and real game files. 

Built as a submission for the **AI Agents: Intensive Vibe Coding Capstone Project** (Kaggle & Google).

---

## πŸ‘½ Overview & Problem Statement
XCOM 2 is a complex, high-stakes tactical game where a single miscalculation can lead to permanent character death ("permadeath") or campaign failure.
- **The Problem:** Game mechanics (like hidden "Aim Assist" multipliers, encounter tables, and facility construction costs) are buried inside massive, cryptic game configuration files (e.g., `DefaultGameData.ini` with 14,000+ lines) or spread across long-form wiki pages. Players are forced to alt-tab, search through forums, or make blind guesses.
- **The Solution:** *XCOM 2 Tactical Wingman* introduces a localized AI Agent acting as **Central Officer Bradford**. Bradford is context-aware of the current campaign state and uses a **Model Context Protocol (MCP) server** to query real-time configuration parameters, difficulty compendiums, and strategy guides.

---

## πŸ› οΈ Architecture

```mermaid
graph TD
    User([Commander / User]) <--> |Streamlit Console UI| App[app.py]
    App <--> |Campaign State + User Query| Gemini[Gemini 2.5 Flash]
    Gemini <--> |Function Calling / Tools| MCPServer[mcp_server.py]
    MCPServer --> |Path Traversal Security Check| SandboxCheck{verify_sandbox_path}
    SandboxCheck --> |Authorized Read| LocalFiles[(Local Data folder)]
    LocalFiles -.-> |1. Clean Guides| XcomClear[data/XcomClear/*.txt]
    LocalFiles -.-> |2. Raw Configs| GameData[data/DefaultGameData_COMBINADO.txt]
    LocalFiles -.-> |3. Wiki Compendium| Compendium[difficulty_compendium.json]
```

---

## πŸ† Hackathon Key Concepts Applied

This project demonstrates three of the core concepts covered in the Kaggle/Google Intensive Vibe Coding course:

1. **Agent / System (ADK & Gemini API):** 
   - Uses the `google-genai` SDK to run `gemini-2.5-flash` in a chat session.
   - Dynamically injects the current **Campaign State** (difficulty, month, Avatar project progress, weapon/armor tiers, resources, active research) into the prompt header.
   - Configures the agent with custom system instructions, shaping its persona into the determined, military tone of *Central Officer Bradford* and directing it to output a structured **Tactical Recommendation Report** with success probabilities for campaign choices.

2. **Model Context Protocol (MCP) Server:**
   - Implements a self-contained python FastMCP server in [mcp_server.py](file:///C:/Users/carlo/Documents/XCOMGUIDE/tactical_wingman/mcp_server.py).
   - Exposes three custom tools to the Gemini agent:
     - `search_strategy_guide`: Scans paragraph chunks of tactical wikis using custom tf-idf-like relevance scoring.
     - `search_game_config`: Runs filters over the 14,000+ line INI game config file.
     - `get_difficulty_mechanics`: Pulls hidden stats (e.g. aim assist bonuses, spawn timelines) from a local JSON compendium.

3. **Security Features (Sandbox Validation):**
   - Implement path traversal verification in [mcp_server.py](file:///C:/Users/carlo/Documents/XCOMGUIDE/tactical_wingman/mcp_server.py#L26-30) using the `verify_sandbox_path` function.
   - Ensures that tools cannot be forced via prompt injection to read files outside the project's directory (`C:\Users\carlo\Documents\XCOMGUIDE\tactical_wingman\data`).

---

## πŸ“‚ Project Structure

- [app.py](file:///C:/Users/carlo/Documents/XCOMGUIDE/tactical_wingman/app.py): Streamlit dashboard and chat interface with Gemini 2.5 Flash.
- [mcp_server.py](file:///C:/Users/carlo/Documents/XCOMGUIDE/tactical_wingman/mcp_server.py): FastMCP server declaring read-only lookup tools.
- [difficulty_compendium.json](file:///C:/Users/carlo/Documents/XCOMGUIDE/tactical_wingman/difficulty_compendium.json): JSON database with aim assist factors and calendar tables.
- `data/`: Self-contained database of raw configs and strategy guides.
- [test_tools.py](file:///C:/Users/carlo/Documents/XCOMGUIDE/tactical_wingman/test_tools.py): Unit test script to verify database queries.
- [requirements.txt](file:///C:/Users/carlo/Documents/XCOMGUIDE/tactical_wingman/requirements.txt): Python dependencies.

---

## πŸš€ Requirements and Setup

### 1. Configure Gemini API Key
Obtain an API key from [Google AI Studio](https://aistudio.google.com/) and export it:
```bash
# Windows (PowerShell)
$env:GEMINI_API_KEY="your_api_key_here"

# Windows (CMD)
set GEMINI_API_KEY="your_api_key_here"
```
*Alternatively, you can paste the API Key directly in the UI sidebar.*

### 2. Install Dependencies
Create a virtual environment and install requirements:
```bash
# Create environment
python -m venv .venv

# Activate environment
.venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt
```

### 3. Run Verification Tests
Verify that the search tools read local files correctly:
```bash
python test_tools.py
```

### 4. Launch the Console
Start the Streamlit web console:
```bash
streamlit run app.py
```
This opens `http://localhost:8501` in your browser.

---

## πŸ›‘οΈ License
This project is licensed under the MIT License.