Commit Β·
67a025a
1
Parent(s): 49586ec
Memory strategies: rename to upstream (condenser/discard_all/hide_tool_result), describe per inference code; quest-name letter-spacing matches paper microsite
Browse files
app.py
CHANGED
|
@@ -343,12 +343,13 @@ gradio-app > div {
|
|
| 343 |
text-transform: none !important;
|
| 344 |
color: var(--q-text) !important;
|
| 345 |
}
|
|
|
|
| 346 |
.quest-name {
|
| 347 |
font-family: "Source Serif 4", "Source Serif Pro", ui-serif, Georgia, serif !important;
|
| 348 |
font-style: italic !important;
|
| 349 |
font-weight: 700 !important;
|
| 350 |
color: inherit !important;
|
| 351 |
-
letter-spacing: 0.005em;
|
| 352 |
margin: 4px 0 14px 0 !important;
|
| 353 |
}
|
| 354 |
.hero-subtitle {
|
|
@@ -1361,26 +1362,34 @@ def _trace_to_json(state: "AgentState", used_model: str) -> str:
|
|
| 1361 |
)
|
| 1362 |
|
| 1363 |
|
| 1364 |
-
MEMORY_STRATEGIES = ("vanilla", "condenser", "
|
| 1365 |
|
| 1366 |
|
| 1367 |
def _normalize_memory_strategy(strategy: str) -> str:
|
| 1368 |
-
s = (strategy or "condenser").strip().lower().replace("
|
|
|
|
|
|
|
| 1369 |
return s if s in MEMORY_STRATEGIES else "condenser"
|
| 1370 |
|
| 1371 |
|
| 1372 |
def _apply_memory_strategy(messages: List[Dict[str, str]], strategy: str, turn: int) -> None:
|
| 1373 |
-
"""
|
| 1374 |
-
|
| 1375 |
-
|
| 1376 |
-
|
| 1377 |
-
|
| 1378 |
-
|
| 1379 |
-
|
| 1380 |
-
|
| 1381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1382 |
"""
|
| 1383 |
-
if strategy == "
|
| 1384 |
if turn > 1 and turn % 8 == 0 and len(messages) > 2:
|
| 1385 |
system_msg = messages[0]
|
| 1386 |
question_msg = messages[1]
|
|
@@ -1394,8 +1403,8 @@ def _apply_memory_strategy(messages: List[Dict[str, str]], strategy: str, turn:
|
|
| 1394 |
f"{turn} β continue the research from the original question]",
|
| 1395 |
}
|
| 1396 |
)
|
| 1397 |
-
elif strategy == "
|
| 1398 |
-
keep_tail =
|
| 1399 |
tool_indices = [
|
| 1400 |
i for i, m in enumerate(messages)
|
| 1401 |
if m.get("role") == "user" and str(m.get("content", "")).startswith("<tool_response>")
|
|
@@ -1805,10 +1814,10 @@ with gr.Blocks(
|
|
| 1805 |
)
|
| 1806 |
gr.HTML(
|
| 1807 |
'<div class="memory-help">'
|
| 1808 |
-
'<b>vanilla</b> β
|
| 1809 |
-
'<b>condenser</b> β
|
| 1810 |
-
'<b>
|
| 1811 |
-
'<b>
|
| 1812 |
'</div>'
|
| 1813 |
)
|
| 1814 |
max_turns = gr.Slider(
|
|
|
|
| 343 |
text-transform: none !important;
|
| 344 |
color: var(--q-text) !important;
|
| 345 |
}
|
| 346 |
+
/* Match the .brand mark from the Quest microsite (github-page branch). */
|
| 347 |
.quest-name {
|
| 348 |
font-family: "Source Serif 4", "Source Serif Pro", ui-serif, Georgia, serif !important;
|
| 349 |
font-style: italic !important;
|
| 350 |
font-weight: 700 !important;
|
| 351 |
color: inherit !important;
|
| 352 |
+
letter-spacing: -0.005em;
|
| 353 |
margin: 4px 0 14px 0 !important;
|
| 354 |
}
|
| 355 |
.hero-subtitle {
|
|
|
|
| 1362 |
)
|
| 1363 |
|
| 1364 |
|
| 1365 |
+
MEMORY_STRATEGIES = ("vanilla", "condenser", "discard_all", "hide_tool_result")
|
| 1366 |
|
| 1367 |
|
| 1368 |
def _normalize_memory_strategy(strategy: str) -> str:
|
| 1369 |
+
s = (strategy or "condenser").strip().lower().replace("-", "_")
|
| 1370 |
+
if s == "hide_tool_results":
|
| 1371 |
+
s = "hide_tool_result"
|
| 1372 |
return s if s in MEMORY_STRATEGIES else "condenser"
|
| 1373 |
|
| 1374 |
|
| 1375 |
def _apply_memory_strategy(messages: List[Dict[str, str]], strategy: str, turn: int) -> None:
|
| 1376 |
+
"""Lightweight port of the strategies defined in the Quest inference
|
| 1377 |
+
code (`inference/react_agent.py`). Upstream is token-threshold-driven;
|
| 1378 |
+
this Space approximates each strategy on a turn-count basis for demo
|
| 1379 |
+
purposes.
|
| 1380 |
+
|
| 1381 |
+
- vanilla: no-op (matches MEMORY_ENABLED=false upstream).
|
| 1382 |
+
- condenser: no-op here; the main loop injects a compact research-state
|
| 1383 |
+
summary every few turns (a poor-man's stand-in for the upstream
|
| 1384 |
+
State Summarizer LLM that emits a structured trusted/untrusted/
|
| 1385 |
+
uncertain JSON when the token threshold is hit).
|
| 1386 |
+
- discard_all: every 8 turns, reset history to [system, user question]
|
| 1387 |
+
(upstream resets when token_count crosses the threshold).
|
| 1388 |
+
- hide_tool_result: keep only the most recent tool-response user
|
| 1389 |
+
message; older ones get their content replaced with a stub
|
| 1390 |
+
(mirrors upstream behavior).
|
| 1391 |
"""
|
| 1392 |
+
if strategy == "discard_all":
|
| 1393 |
if turn > 1 and turn % 8 == 0 and len(messages) > 2:
|
| 1394 |
system_msg = messages[0]
|
| 1395 |
question_msg = messages[1]
|
|
|
|
| 1403 |
f"{turn} β continue the research from the original question]",
|
| 1404 |
}
|
| 1405 |
)
|
| 1406 |
+
elif strategy == "hide_tool_result":
|
| 1407 |
+
keep_tail = 1
|
| 1408 |
tool_indices = [
|
| 1409 |
i for i, m in enumerate(messages)
|
| 1410 |
if m.get("role") == "user" and str(m.get("content", "")).startswith("<tool_response>")
|
|
|
|
| 1814 |
)
|
| 1815 |
gr.HTML(
|
| 1816 |
'<div class="memory-help">'
|
| 1817 |
+
'<b>vanilla</b> β memory management disabled; the full conversation history is kept.<br>'
|
| 1818 |
+
'<b>condenser</b> (default) β when context grows large, a State Summarizer LLM compresses earlier turns into a structured JSON of trusted/untrusted/uncertain claims, visited sources, and prior search queries; the agent continues with that compact state.<br>'
|
| 1819 |
+
'<b>discard_all</b> β when context grows large, the entire message history is reset, restarting the agent from the original question with no accumulated context.<br>'
|
| 1820 |
+
'<b>hide_tool_result</b> β when context grows large, older tool responses are pruned; only the most recent tool result is kept.'
|
| 1821 |
'</div>'
|
| 1822 |
)
|
| 1823 |
max_turns = gr.Slider(
|