Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +148 -91
src/streamlit_app.py
CHANGED
|
@@ -2,12 +2,12 @@ import streamlit as st
|
|
| 2 |
import time
|
| 3 |
|
| 4 |
# --- CONFIGURATION & CONTENT ---
|
| 5 |
-
st.set_page_config(page_title="Elf-OS Agent Simulator", page_icon="🤖")
|
| 6 |
|
| 7 |
CONTENT = {
|
| 8 |
"Deutsch": {
|
| 9 |
"title": "🤖 Elf-OS: Agenten Simulation",
|
| 10 |
-
"intro": "
|
| 11 |
"sidebar_title": "Wähle eine Mission",
|
| 12 |
"tools_header": "🧰 Verfügbare Werkzeuge",
|
| 13 |
"chain_header": "🔗 Deine Gedanken-Kette",
|
|
@@ -15,90 +15,128 @@ CONTENT = {
|
|
| 15 |
"btn_add": "➕",
|
| 16 |
"btn_clear": "🗑️ Kette löschen",
|
| 17 |
"btn_run": "🚀 Agent starten",
|
| 18 |
-
"
|
| 19 |
-
"feedback_spotify": "❌ <strong>Fehler:</strong>
|
| 20 |
-
"
|
| 21 |
-
"
|
| 22 |
-
"
|
|
|
|
|
|
|
|
|
|
| 23 |
"missions": {
|
| 24 |
"L1": {
|
| 25 |
"name": "Level 1: Das vergessene Geschenk",
|
| 26 |
-
"briefing": "Santa
|
| 27 |
"solution_ids": ["db", "inv"],
|
| 28 |
-
"
|
|
|
|
| 29 |
},
|
| 30 |
"L2": {
|
| 31 |
"name": "Level 2: Die Routen-Planung",
|
| 32 |
-
"briefing": "
|
| 33 |
"solution_ids": ["weather", "fuel", "nav"],
|
| 34 |
-
"
|
|
|
|
| 35 |
},
|
| 36 |
"L3": {
|
| 37 |
"name": "Level 3: Der Notfall (Advanced)",
|
| 38 |
-
"briefing": "Rudolph
|
| 39 |
"solution_ids": ["gps", "maps", "cal", "book"],
|
| 40 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
},
|
| 43 |
"tools": {
|
| 44 |
-
"weather": "Wetter_Radar",
|
| 45 |
-
"db": "
|
| 46 |
-
"inv": "
|
| 47 |
-
"nav": "
|
| 48 |
-
"fuel": "
|
| 49 |
-
"gps": "GPS_Ortung",
|
| 50 |
-
"maps": "
|
| 51 |
-
"cal": "Kalender_Bot",
|
| 52 |
-
"book": "Buchungs_Tool",
|
| 53 |
-
"spotify": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 55 |
},
|
| 56 |
"English": {
|
| 57 |
"title": "🤖 Elf-OS: Agent Simulator",
|
| 58 |
-
"intro": "
|
| 59 |
-
"sidebar_title": "Choose
|
| 60 |
"tools_header": "🧰 Available Tools",
|
| 61 |
"chain_header": "🔗 Your Thought Chain",
|
| 62 |
-
"empty_chain": "*No tools selected
|
| 63 |
"btn_add": "➕",
|
| 64 |
"btn_clear": "🗑️ Clear Chain",
|
| 65 |
"btn_run": "🚀 Run Agent",
|
| 66 |
-
"
|
| 67 |
-
"feedback_spotify": "❌ <strong>Error:</strong>
|
| 68 |
-
"
|
| 69 |
-
"
|
| 70 |
-
"
|
|
|
|
|
|
|
|
|
|
| 71 |
"missions": {
|
| 72 |
"L1": {
|
| 73 |
"name": "Level 1: The Forgotten Gift",
|
| 74 |
-
"briefing": "Santa forgot what
|
| 75 |
"solution_ids": ["db", "inv"],
|
| 76 |
-
"
|
|
|
|
| 77 |
},
|
| 78 |
"L2": {
|
| 79 |
"name": "Level 2: Route Planning",
|
| 80 |
-
"briefing": "
|
| 81 |
"solution_ids": ["weather", "fuel", "nav"],
|
| 82 |
-
"
|
|
|
|
| 83 |
},
|
| 84 |
"L3": {
|
| 85 |
"name": "Level 3: The Emergency (Advanced)",
|
| 86 |
-
"briefing": "Rudolph
|
| 87 |
"solution_ids": ["gps", "maps", "cal", "book"],
|
| 88 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
},
|
| 91 |
"tools": {
|
| 92 |
-
"weather": "Weather_Radar",
|
| 93 |
-
"db": "
|
| 94 |
-
"inv": "
|
| 95 |
-
"nav": "
|
| 96 |
-
"fuel": "
|
| 97 |
-
"gps": "GPS_Location",
|
| 98 |
-
"maps": "
|
| 99 |
-
"cal": "Calendar_Bot",
|
| 100 |
-
"book": "Booking_Tool",
|
| 101 |
-
"spotify": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
}
|
| 103 |
}
|
| 104 |
}
|
|
@@ -108,35 +146,24 @@ st.markdown("""
|
|
| 108 |
<style>
|
| 109 |
.stButton>button {
|
| 110 |
width: 100%;
|
| 111 |
-
border-radius:
|
| 112 |
-
height:
|
| 113 |
font-weight: 500;
|
|
|
|
| 114 |
}
|
| 115 |
-
.success-box {
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
color: #155724;
|
| 119 |
-
border-radius: 10px;
|
| 120 |
-
margin-bottom: 10px;
|
| 121 |
-
border: 1px solid #c3e6cb;
|
| 122 |
-
}
|
| 123 |
-
.fail-box {
|
| 124 |
-
padding: 20px;
|
| 125 |
-
background-color: #f8d7da;
|
| 126 |
-
color: #721c24;
|
| 127 |
-
border-radius: 10px;
|
| 128 |
-
margin-bottom: 10px;
|
| 129 |
-
border: 1px solid #f5c6cb;
|
| 130 |
-
}
|
| 131 |
-
div[data-testid="stExpander"] {
|
| 132 |
-
background-color: #f0f2f6;
|
| 133 |
-
border-radius: 10px;
|
| 134 |
-
}
|
| 135 |
</style>
|
| 136 |
""", unsafe_allow_html=True)
|
| 137 |
|
| 138 |
# --- APP LOGIC ---
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
text = CONTENT[lang_key]
|
| 141 |
|
| 142 |
st.title(text["title"])
|
|
@@ -148,24 +175,41 @@ selected_mission_name = st.sidebar.selectbox(text["sidebar_title"], list(mission
|
|
| 148 |
selected_mission_key = mission_options[selected_mission_name]
|
| 149 |
mission_data = text["missions"][selected_mission_key]
|
| 150 |
|
| 151 |
-
# 3. Session State Management
|
| 152 |
-
if 'chain' not in st.session_state:
|
| 153 |
-
st.session_state.chain = [] # Stores Tool IDs (e.g., 'db', 'inv')
|
| 154 |
-
|
| 155 |
# Reset chain if mission changes
|
| 156 |
if 'current_mission' not in st.session_state or st.session_state.current_mission != selected_mission_key:
|
| 157 |
st.session_state.chain = []
|
| 158 |
st.session_state.current_mission = selected_mission_key
|
| 159 |
|
| 160 |
-
# 4. Display Mission
|
| 161 |
st.info(f"📋 **MISSION:** {mission_data['briefing']}")
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
col1, col2 = st.columns([1, 1])
|
| 164 |
|
| 165 |
with col1:
|
| 166 |
st.subheader(text["tools_header"])
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
st.session_state.chain.append(tool_id)
|
| 170 |
|
| 171 |
with col2:
|
|
@@ -174,35 +218,48 @@ with col2:
|
|
| 174 |
st.markdown(text["empty_chain"])
|
| 175 |
else:
|
| 176 |
for i, tool_id in enumerate(st.session_state.chain):
|
| 177 |
-
|
| 178 |
-
st.markdown(f"**{i+1}.** `{
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
|
|
|
| 182 |
|
| 183 |
st.write("---")
|
| 184 |
|
| 185 |
# 5. Execution Logic
|
| 186 |
if st.button(text["btn_run"], type="primary"):
|
| 187 |
-
with st.spinner(
|
| 188 |
-
time.sleep(1.
|
| 189 |
|
| 190 |
user_chain_ids = st.session_state.chain
|
| 191 |
correct_ids = mission_data['solution_ids']
|
| 192 |
|
| 193 |
-
#
|
| 194 |
-
if "
|
| 195 |
-
|
| 196 |
|
| 197 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
elif user_chain_ids == correct_ids:
|
| 199 |
st.balloons()
|
| 200 |
st.markdown(f'<div class="success-box">{text["feedback_success"]}<br><br><em>💡 {mission_data["explanation"]}</em></div>', unsafe_allow_html=True)
|
| 201 |
-
|
| 202 |
-
#
|
| 203 |
elif set(user_chain_ids) == set(correct_ids) and len(user_chain_ids) == len(correct_ids):
|
| 204 |
st.markdown(f'<div class="fail-box">{text["feedback_order"]}</div>', unsafe_allow_html=True)
|
| 205 |
|
| 206 |
-
#
|
| 207 |
else:
|
| 208 |
st.markdown(f'<div class="fail-box">{text["feedback_fail"]}</div>', unsafe_allow_html=True)
|
|
|
|
| 2 |
import time
|
| 3 |
|
| 4 |
# --- CONFIGURATION & CONTENT ---
|
| 5 |
+
st.set_page_config(page_title="Elf-OS Agent Simulator v2.0", page_icon="🤖", layout="wide")
|
| 6 |
|
| 7 |
CONTENT = {
|
| 8 |
"Deutsch": {
|
| 9 |
"title": "🤖 Elf-OS: Agenten Simulation",
|
| 10 |
+
"intro": "Willkommen im erweiterten Modus! KI-Agenten haben nicht unendlich Energie. Achte auf deinen **Magie-Staub (Tokens)**. Jedes Werkzeug kostet Staub. Wenn er leer ist, bricht der Agent ab!",
|
| 11 |
"sidebar_title": "Wähle eine Mission",
|
| 12 |
"tools_header": "🧰 Verfügbare Werkzeuge",
|
| 13 |
"chain_header": "🔗 Deine Gedanken-Kette",
|
|
|
|
| 15 |
"btn_add": "➕",
|
| 16 |
"btn_clear": "🗑️ Kette löschen",
|
| 17 |
"btn_run": "🚀 Agent starten",
|
| 18 |
+
"cost_label": "✨ Magie-Staub Verbrauch:",
|
| 19 |
+
"feedback_spotify": "❌ <strong>Fehler:</strong> Musik lenkt nur ab! (Halluzination)",
|
| 20 |
+
"feedback_trap": "🚨 <strong>SICHERHEITSALARM:</strong> Du hast ein unsicheres Werkzeug benutzt! Der 'Hack' hat den Alarm ausgelöst. Agenten müssen sicher arbeiten.",
|
| 21 |
+
"feedback_cost": "🪫 <strong>Zu wenig Magie!</strong> Du hast zu viele unnötige Werkzeuge benutzt. Effizienz ist wichtig bei LLMs.",
|
| 22 |
+
"feedback_think": "🧠 <strong>Agent verwirrt:</strong> Bei so einer schweren Aufgabe muss der Agent erst NACHDENKEN (CoT), bevor er handelt.",
|
| 23 |
+
"feedback_order": "⚠️ <strong>Reihenfolge falsch!</strong> Die Logik stimmt nicht.",
|
| 24 |
+
"feedback_fail": "❌ <strong>Das reicht nicht.</strong> Der Agent konnte das Ziel nicht erreichen.",
|
| 25 |
+
"feedback_success": "✅ <strong>Erfolg!</strong> Mission erfüllt!",
|
| 26 |
"missions": {
|
| 27 |
"L1": {
|
| 28 |
"name": "Level 1: Das vergessene Geschenk",
|
| 29 |
+
"briefing": "Santa weiß nicht mehr, was Mia will. Finde es heraus und prüfe den Sack.",
|
| 30 |
"solution_ids": ["db", "inv"],
|
| 31 |
+
"budget": 30,
|
| 32 |
+
"explanation": "Datenbank -> Inventar. Simpel und effizient."
|
| 33 |
},
|
| 34 |
"L2": {
|
| 35 |
"name": "Level 2: Die Routen-Planung",
|
| 36 |
+
"briefing": "Flug nach Berlin. Nur bei gutem Wetter UND genug Moos im Tank starten.",
|
| 37 |
"solution_ids": ["weather", "fuel", "nav"],
|
| 38 |
+
"budget": 45,
|
| 39 |
+
"explanation": "Erst die Bedingungen (Wetter/Tank) prüfen, dann handeln."
|
| 40 |
},
|
| 41 |
"L3": {
|
| 42 |
"name": "Level 3: Der Notfall (Advanced)",
|
| 43 |
+
"briefing": "Rudolph ist krank. Finde einen offenen Tierarzt und buche sofort.",
|
| 44 |
"solution_ids": ["gps", "maps", "cal", "book"],
|
| 45 |
+
"budget": 60,
|
| 46 |
+
"explanation": "Kontext (GPS) -> Suche (Maps) -> Verfügbarkeit (Kalender) -> Aktion (Buchen)."
|
| 47 |
+
},
|
| 48 |
+
"L4": {
|
| 49 |
+
"name": "Level 4: Der Smart-Chimney (EXPERT)",
|
| 50 |
+
"briefing": "🔥 <strong>HÄRTEFALL:</strong> Ein Smart-Home Schornstein ist versperrt. Du musst ihn öffnen, ohne den Alarm auszulösen. Errate nicht das Passwort!",
|
| 51 |
+
"solution_ids": ["scan", "think", "manual", "auth"],
|
| 52 |
+
"budget": 55,
|
| 53 |
+
"explanation": "<strong>Chain of Thought:</strong> Erst Scannen. Dann NACHDENKEN (Think), um zu verstehen, welches Modell es ist. Dann Handbuch lesen (Manual) und korrekt authentifizieren. 'Hacken' löst Alarm aus!"
|
| 54 |
}
|
| 55 |
},
|
| 56 |
"tools": {
|
| 57 |
+
"weather": {"name": "Wetter_Radar", "cost": 10},
|
| 58 |
+
"db": {"name": "Wunschzettel_DB", "cost": 10},
|
| 59 |
+
"inv": {"name": "Sack_Inventar", "cost": 10},
|
| 60 |
+
"nav": {"name": "Navi_System", "cost": 15},
|
| 61 |
+
"fuel": {"name": "Tankanzeige", "cost": 5},
|
| 62 |
+
"gps": {"name": "GPS_Ortung", "cost": 5},
|
| 63 |
+
"maps": {"name": "Google_Maps", "cost": 15},
|
| 64 |
+
"cal": {"name": "Kalender_Bot", "cost": 10},
|
| 65 |
+
"book": {"name": "Buchungs_Tool", "cost": 20},
|
| 66 |
+
"spotify": {"name": "Spotify_Playlist", "cost": 5},
|
| 67 |
+
"scan": {"name": "Struktur_Scanner", "cost": 10},
|
| 68 |
+
"hack": {"name": "Brute_Force_Hack", "cost": 20},
|
| 69 |
+
"manual": {"name": "Technische_Handbücher", "cost": 15},
|
| 70 |
+
"think": {"name": "🧠 Chain_of_Thought", "cost": 5},
|
| 71 |
+
"guess": {"name": "Passwort_Raten", "cost": 5},
|
| 72 |
+
"auth": {"name": "Security_Protokoll", "cost": 20}
|
| 73 |
}
|
| 74 |
},
|
| 75 |
"English": {
|
| 76 |
"title": "🤖 Elf-OS: Agent Simulator",
|
| 77 |
+
"intro": "Welcome to Advanced Mode! AI Agents consume energy. Watch your **Magic Dust (Tokens)**. Each tool costs dust. If you run out, the agent crashes!",
|
| 78 |
+
"sidebar_title": "Choose Mission",
|
| 79 |
"tools_header": "🧰 Available Tools",
|
| 80 |
"chain_header": "🔗 Your Thought Chain",
|
| 81 |
+
"empty_chain": "*No tools selected...*",
|
| 82 |
"btn_add": "➕",
|
| 83 |
"btn_clear": "🗑️ Clear Chain",
|
| 84 |
"btn_run": "🚀 Run Agent",
|
| 85 |
+
"cost_label": "✨ Magic Dust Usage:",
|
| 86 |
+
"feedback_spotify": "❌ <strong>Error:</strong> Music is a distraction! (Hallucination)",
|
| 87 |
+
"feedback_trap": "🚨 <strong>SECURITY ALERT:</strong> You used an unsafe tool! The 'Hack' triggered the alarm. Agents must follow protocol.",
|
| 88 |
+
"feedback_cost": "🪫 <strong>Out of Magic!</strong> You used too many unnecessary tools. Efficiency matters for LLMs.",
|
| 89 |
+
"feedback_think": "🧠 <strong>Agent Confused:</strong> For this complex task, the Agent must THINK (CoT) before acting.",
|
| 90 |
+
"feedback_order": "⚠️ <strong>Wrong Order!</strong> The logic flow is incorrect.",
|
| 91 |
+
"feedback_fail": "❌ <strong>Not enough.</strong> The Agent failed to reach the goal.",
|
| 92 |
+
"feedback_success": "✅ <strong>Success!</strong> Mission accomplished!",
|
| 93 |
"missions": {
|
| 94 |
"L1": {
|
| 95 |
"name": "Level 1: The Forgotten Gift",
|
| 96 |
+
"briefing": "Santa forgot what Mia wants. Find out and check the sack.",
|
| 97 |
"solution_ids": ["db", "inv"],
|
| 98 |
+
"budget": 30,
|
| 99 |
+
"explanation": "Database -> Inventory. Simple and efficient."
|
| 100 |
},
|
| 101 |
"L2": {
|
| 102 |
"name": "Level 2: Route Planning",
|
| 103 |
+
"briefing": "Fly to Berlin. Only take off if weather is good AND fuel is sufficient.",
|
| 104 |
"solution_ids": ["weather", "fuel", "nav"],
|
| 105 |
+
"budget": 45,
|
| 106 |
+
"explanation": "Check conditions (Weather/Fuel) before Action (Nav)."
|
| 107 |
},
|
| 108 |
"L3": {
|
| 109 |
"name": "Level 3: The Emergency (Advanced)",
|
| 110 |
+
"briefing": "Rudolph is sick. Find an open vet nearby and book now.",
|
| 111 |
"solution_ids": ["gps", "maps", "cal", "book"],
|
| 112 |
+
"budget": 60,
|
| 113 |
+
"explanation": "Context (GPS) -> Search (Maps) -> Availability (Cal) -> Action (Book)."
|
| 114 |
+
},
|
| 115 |
+
"L4": {
|
| 116 |
+
"name": "Level 4: The Smart Chimney (EXPERT)",
|
| 117 |
+
"briefing": "🔥 <strong>HARD MODE:</strong> A Smart-Home chimney is locked. You need to open it without triggering the alarm. Do NOT guess the password!",
|
| 118 |
+
"solution_ids": ["scan", "think", "manual", "auth"],
|
| 119 |
+
"budget": 55,
|
| 120 |
+
"explanation": "<strong>Chain of Thought:</strong> Scan first. Then THINK to process the data. Then read the Manual. Finally, use the Security Protocol. 'Hacking' triggers the alarm!"
|
| 121 |
}
|
| 122 |
},
|
| 123 |
"tools": {
|
| 124 |
+
"weather": {"name": "Weather_Radar", "cost": 10},
|
| 125 |
+
"db": {"name": "Wishlist_DB", "cost": 10},
|
| 126 |
+
"inv": {"name": "Sack_Inventory", "cost": 10},
|
| 127 |
+
"nav": {"name": "Nav_System", "cost": 15},
|
| 128 |
+
"fuel": {"name": "Fuel_Gauge", "cost": 5},
|
| 129 |
+
"gps": {"name": "GPS_Location", "cost": 5},
|
| 130 |
+
"maps": {"name": "Google_Maps", "cost": 15},
|
| 131 |
+
"cal": {"name": "Calendar_Bot", "cost": 10},
|
| 132 |
+
"book": {"name": "Booking_Tool", "cost": 20},
|
| 133 |
+
"spotify": {"name": "Spotify_Playlist", "cost": 5},
|
| 134 |
+
"scan": {"name": "Structure_Scanner", "cost": 10},
|
| 135 |
+
"hack": {"name": "Brute_Force_Hack", "cost": 20},
|
| 136 |
+
"manual": {"name": "Tech_Manuals", "cost": 15},
|
| 137 |
+
"think": {"name": "🧠 Chain_of_Thought", "cost": 5},
|
| 138 |
+
"guess": {"name": "Password_Guesser", "cost": 5},
|
| 139 |
+
"auth": {"name": "Security_Protocol", "cost": 20}
|
| 140 |
}
|
| 141 |
}
|
| 142 |
}
|
|
|
|
| 146 |
<style>
|
| 147 |
.stButton>button {
|
| 148 |
width: 100%;
|
| 149 |
+
border-radius: 8px;
|
| 150 |
+
height: 45px;
|
| 151 |
font-weight: 500;
|
| 152 |
+
border: 1px solid #ddd;
|
| 153 |
}
|
| 154 |
+
.success-box { padding: 15px; background-color: #d4edda; color: #155724; border-radius: 10px; border: 1px solid #c3e6cb; }
|
| 155 |
+
.fail-box { padding: 15px; background-color: #f8d7da; color: #721c24; border-radius: 10px; border: 1px solid #f5c6cb; }
|
| 156 |
+
.metric-box { text-align: center; font-size: 1.2rem; font-weight: bold; padding: 10px; background: #f0f2f6; border-radius: 8px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
</style>
|
| 158 |
""", unsafe_allow_html=True)
|
| 159 |
|
| 160 |
# --- APP LOGIC ---
|
| 161 |
+
|
| 162 |
+
# 1. Setup
|
| 163 |
+
if 'chain' not in st.session_state:
|
| 164 |
+
st.session_state.chain = []
|
| 165 |
+
|
| 166 |
+
lang_key = st.sidebar.radio("Language / Sprache", ["English", "Deutsch"])
|
| 167 |
text = CONTENT[lang_key]
|
| 168 |
|
| 169 |
st.title(text["title"])
|
|
|
|
| 175 |
selected_mission_key = mission_options[selected_mission_name]
|
| 176 |
mission_data = text["missions"][selected_mission_key]
|
| 177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
# Reset chain if mission changes
|
| 179 |
if 'current_mission' not in st.session_state or st.session_state.current_mission != selected_mission_key:
|
| 180 |
st.session_state.chain = []
|
| 181 |
st.session_state.current_mission = selected_mission_key
|
| 182 |
|
|
|
|
| 183 |
st.info(f"📋 **MISSION:** {mission_data['briefing']}")
|
| 184 |
|
| 185 |
+
# 3. Calculate Cost
|
| 186 |
+
current_cost = sum([text["tools"][t_id]["cost"] for t_id in st.session_state.chain])
|
| 187 |
+
max_budget = mission_data["budget"]
|
| 188 |
+
budget_percent = min(current_cost / max_budget, 1.0)
|
| 189 |
+
|
| 190 |
+
# Display Progress/Cost Bar
|
| 191 |
+
col_m1, col_m2 = st.columns([3, 1])
|
| 192 |
+
with col_m1:
|
| 193 |
+
st.write(text["cost_label"])
|
| 194 |
+
bar_color = "green" if current_cost <= max_budget else "red"
|
| 195 |
+
st.progress(budget_percent)
|
| 196 |
+
with col_m2:
|
| 197 |
+
st.markdown(f"<div class='metric-box' style='color:{bar_color}'>{current_cost} / {max_budget}</div>", unsafe_allow_html=True)
|
| 198 |
+
|
| 199 |
+
st.write("---")
|
| 200 |
+
|
| 201 |
+
# 4. Interface
|
| 202 |
col1, col2 = st.columns([1, 1])
|
| 203 |
|
| 204 |
with col1:
|
| 205 |
st.subheader(text["tools_header"])
|
| 206 |
+
|
| 207 |
+
# Group tools for better layout
|
| 208 |
+
tools_list = list(text["tools"].items())
|
| 209 |
+
|
| 210 |
+
for tool_id, tool_data in tools_list:
|
| 211 |
+
cost_display = f" ({tool_data['cost']})"
|
| 212 |
+
if st.button(f"{text['btn_add']} {tool_data['name']} {cost_display}", key=f"btn_{tool_id}"):
|
| 213 |
st.session_state.chain.append(tool_id)
|
| 214 |
|
| 215 |
with col2:
|
|
|
|
| 218 |
st.markdown(text["empty_chain"])
|
| 219 |
else:
|
| 220 |
for i, tool_id in enumerate(st.session_state.chain):
|
| 221 |
+
tool_data = text["tools"][tool_id]
|
| 222 |
+
st.markdown(f"**{i+1}.** `{tool_data['name']}` <small>({tool_data['cost']})</small>", unsafe_allow_html=True)
|
| 223 |
+
|
| 224 |
+
st.write("")
|
| 225 |
+
if st.button(text["btn_clear"], type="secondary"):
|
| 226 |
+
st.session_state.chain = []
|
| 227 |
|
| 228 |
st.write("---")
|
| 229 |
|
| 230 |
# 5. Execution Logic
|
| 231 |
if st.button(text["btn_run"], type="primary"):
|
| 232 |
+
with st.spinner("Agent running..."):
|
| 233 |
+
time.sleep(1.2)
|
| 234 |
|
| 235 |
user_chain_ids = st.session_state.chain
|
| 236 |
correct_ids = mission_data['solution_ids']
|
| 237 |
|
| 238 |
+
# FAIL CONDITION 1: TRAP TOOLS (Security/Hallucination)
|
| 239 |
+
if "hack" in user_chain_ids or "guess" in user_chain_ids:
|
| 240 |
+
st.markdown(f'<div class="fail-box">{text["feedback_trap"]}</div>', unsafe_allow_html=True)
|
| 241 |
|
| 242 |
+
# FAIL CONDITION 2: SPOTIFY (Distraction)
|
| 243 |
+
elif "spotify" in user_chain_ids:
|
| 244 |
+
st.markdown(f'<div class="fail-box">{text["feedback_spotify"]}</div>', unsafe_allow_html=True)
|
| 245 |
+
|
| 246 |
+
# FAIL CONDITION 3: BUDGET EXCEEDED
|
| 247 |
+
elif current_cost > max_budget:
|
| 248 |
+
st.markdown(f'<div class="fail-box">{text["feedback_cost"]}</div>', unsafe_allow_html=True)
|
| 249 |
+
|
| 250 |
+
# FAIL CONDITION 4: LEVEL 4 MISSING "THINK" (Chain of Thought requirement)
|
| 251 |
+
elif selected_mission_key == "L4" and "think" not in user_chain_ids:
|
| 252 |
+
st.markdown(f'<div class="fail-box">{text["feedback_think"]}</div>', unsafe_allow_html=True)
|
| 253 |
+
|
| 254 |
+
# SUCCESS
|
| 255 |
elif user_chain_ids == correct_ids:
|
| 256 |
st.balloons()
|
| 257 |
st.markdown(f'<div class="success-box">{text["feedback_success"]}<br><br><em>💡 {mission_data["explanation"]}</em></div>', unsafe_allow_html=True)
|
| 258 |
+
|
| 259 |
+
# PARTIAL/WRONG ORDER
|
| 260 |
elif set(user_chain_ids) == set(correct_ids) and len(user_chain_ids) == len(correct_ids):
|
| 261 |
st.markdown(f'<div class="fail-box">{text["feedback_order"]}</div>', unsafe_allow_html=True)
|
| 262 |
|
| 263 |
+
# GENERIC FAIL
|
| 264 |
else:
|
| 265 |
st.markdown(f'<div class="fail-box">{text["feedback_fail"]}</div>', unsafe_allow_html=True)
|