Skip to content

Commit 82ef2bb

Browse files
committed
feat: Think mode two-pass refinement & multi-select search providers
- Think mode (@Think: Yes / 🧠 toggle) now uses two-pass refinement: generate with thinking → refine with added details - Removed complex ReAct pattern (Reason → Act loop) in favor of simple refinement - Multi-select search provider dropdown on AI Generate and Agent Flow cards - Checkbox pill UI for selecting multiple search engines simultaneously - Search results from all active providers fetched in parallel and merged - Console logs for Think refinement flow ([DocGen Think], [Agent Think])
1 parent 71400c2 commit 82ef2bb

7 files changed

Lines changed: 375 additions & 56 deletions

File tree

CHANGELOG-think-refinement.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Think Mode Refinement & Multi-Select Search Providers
2+
3+
- Multi-select search provider dropdown for AI Generate and Agent Flow cards (checkbox pills instead of single-select)
4+
- Per-card multi-search support: AI and Agent cards can activate multiple search engines simultaneously
5+
- Think mode (`@think: Yes`) now uses two-pass refinement: generate with thinking → refine with added details
6+
- Agent Flow Think toggle also applies two-pass refinement per step
7+
- Removed ReAct pattern (Reason → Act loop) in favor of simpler refinement approach
8+
- Fixed: double-escaped `\\n` newlines in prompt strings
9+
- Fixed: search dropdown positioning and z-index issues for AI/Agent cards
10+
- Console logs added for Think refinement flow (`[DocGen Think]`, `[Agent Think]`)
11+
12+
---
13+
14+
## Summary
15+
16+
Replaced the complex multi-iteration ReAct pattern with a simple two-pass Think refinement: when Think mode is enabled (`@think: Yes` on AI cards or 🧠 toggle on Agent cards), the system generates content with `enableThinking: true`, then passes the result back to the model asking it to add important details, examples, and missing information. Also added multi-select search provider support for DocGen cards.
17+
18+
---
19+
20+
## 1. Multi-Select Search Providers for DocGen Cards
21+
**Files:** `js/ai-docgen.js`, `css/ai-docgen.css`
22+
**What:** Replaced single-select search dropdown with multi-select checkbox pill UI on both AI Generate and Agent Flow cards. Each card can now activate multiple search providers simultaneously. Results from all selected providers are fetched in parallel and merged.
23+
**Impact:** Users can combine search sources (e.g., DuckDuckGo + Wikipedia + Tavily) for richer context in AI-generated content.
24+
25+
## 2. Think Mode Two-Pass Refinement
26+
**Files:** `js/ai-docgen-generate.js`
27+
**What:** When Think mode is ON (`@think: Yes` or 🧠 toggle), generates content with `enableThinking: true`, then passes the draft back to the model asking it to improve by adding important details, examples, or missing information. The second call uses `enableThinking: false` for faster output.
28+
**Impact:** Think mode now produces richer, more detailed content without the complexity and slowness of the previous multi-iteration ReAct approach.
29+
30+
## 3. ReAct Pattern Removal
31+
**Files:** `js/ai-docgen-generate.js`
32+
**What:** Removed the iterative Reason → Act loop (which made 2-6 model calls per generation) and replaced it with the simple two-pass refinement described above.
33+
**Impact:** Think mode is now much faster (2 calls instead of 4-6), stays on-topic, and avoids output drift that occurred with the multi-iteration loop.
34+
35+
## 4. Search Dropdown CSS & Positioning
36+
**Files:** `css/ai-docgen.css`
37+
**What:** Added CSS for multi-select search dropdown with checkbox pills, proper z-index stacking, and positioning fixes to ensure the dropdown is visible above all card elements.
38+
**Impact:** Search dropdowns open correctly and are fully visible on all card types.
39+
40+
## 5. Search Provider Fix
41+
**Files:** `js/ai-web-search.js`
42+
**What:** Minor fix to search provider handling for compatibility with multi-select arrays.
43+
**Impact:** Search works correctly when multiple providers are selected.
44+
45+
---
46+
47+
## Files Changed (4 total)
48+
49+
| File | Lines Changed | Type |
50+
|------|:---:|------|
51+
| `css/ai-docgen.css` | +96 | Multi-select search dropdown styles |
52+
| `js/ai-docgen-generate.js` | +56 −25 | Think refinement, ReAct removal |
53+
| `js/ai-docgen.js` | +110 −31 | Multi-select search provider UI |
54+
| `js/ai-web-search.js` | +2 −2 | Multi-provider compatibility |

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ TextAgent has undergone significant evolution since its inception. What started
459459

460460
| Date | Commits | Feature / Update |
461461
|------|---------|-----------------|
462+
| **2026-03-14** | | 🧠 **Think Mode Refinement & Multi-Select Search** — Think mode (`@think: Yes` / 🧠 toggle) now uses two-pass generation: first generates with thinking enabled, then passes the draft back to the model to add important details, examples, and missing information; removed complex ReAct pattern in favor of simple refinement; multi-select search provider dropdown on AI Generate and Agent Flow cards (checkbox pills, activate multiple engines simultaneously); search results fetched in parallel and merged |
462463
| **2026-03-14** | | 🔑 **API Key Re-entry & Git UX** — fixed bug where incorrect cloud API keys couldn't be re-entered (dropdown re-click now re-shows key modal); "Change API Key" link in error status bar for auth failures; 🔑 key icon button on cloud model cards in DocGen setup panel with "Key Set"/"Key Required" badges; 🐙 Git toolbar button now shows centered confirmation dialog warning that local models have small context windows and cloud models (Groq, Gemini, OpenRouter) are recommended for repo analysis; Git analysis auto-opens API key modal on key/model-not-ready errors |
463464
| **2026-03-13** | | 🔍 **Two-Phase Search UX** — search thinking block now shows a distinct "✨ Rewriting query…" phase with `bi-stars` icon before transitioning to "🌐 Searching the web…"; `createSearchThinkingBlock()` accepts `isRewriting` flag; `updateThinkingBlockQuery()` smoothly transitions inner status text; smart detection skips rewrite phase when model is unavailable or busy |
464465
| **2026-03-13** | | 🔀 **Multi-Provider Parallel Search** — activate multiple search engines simultaneously; results from all active providers fetched in parallel via `Promise.all()`, deduplicated by URL, tagged with source, and grouped by provider for LLM context; new checkbox pill UI replaces single-select dropdown; per-pill 🔑 API key buttons; at least one provider always active; backward-compatible localStorage migration |
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Think Mode Refinement & Multi-Select Search Providers
2+
3+
- Multi-select search provider dropdown for AI Generate and Agent Flow cards (checkbox pills instead of single-select)
4+
- Per-card multi-search support: AI and Agent cards can activate multiple search engines simultaneously
5+
- Think mode (`@think: Yes`) now uses two-pass refinement: generate with thinking → refine with added details
6+
- Agent Flow Think toggle also applies two-pass refinement per step
7+
- Removed ReAct pattern (Reason → Act loop) in favor of simpler refinement approach
8+
- Fixed: double-escaped `\\n` newlines in prompt strings
9+
- Fixed: search dropdown positioning and z-index issues for AI/Agent cards
10+
- Console logs added for Think refinement flow (`[DocGen Think]`, `[Agent Think]`)
11+
12+
---
13+
14+
## Summary
15+
16+
Replaced the complex multi-iteration ReAct pattern with a simple two-pass Think refinement: when Think mode is enabled (`@think: Yes` on AI cards or 🧠 toggle on Agent cards), the system generates content with `enableThinking: true`, then passes the result back to the model asking it to add important details, examples, and missing information. Also added multi-select search provider support for DocGen cards.
17+
18+
---
19+
20+
## 1. Multi-Select Search Providers for DocGen Cards
21+
**Files:** `js/ai-docgen.js`, `css/ai-docgen.css`
22+
**What:** Replaced single-select search dropdown with multi-select checkbox pill UI on both AI Generate and Agent Flow cards. Each card can now activate multiple search providers simultaneously. Results from all selected providers are fetched in parallel and merged.
23+
**Impact:** Users can combine search sources (e.g., DuckDuckGo + Wikipedia + Tavily) for richer context in AI-generated content.
24+
25+
## 2. Think Mode Two-Pass Refinement
26+
**Files:** `js/ai-docgen-generate.js`
27+
**What:** When Think mode is ON (`@think: Yes` or 🧠 toggle), generates content with `enableThinking: true`, then passes the draft back to the model asking it to improve by adding important details, examples, or missing information. The second call uses `enableThinking: false` for faster output.
28+
**Impact:** Think mode now produces richer, more detailed content without the complexity and slowness of the previous multi-iteration ReAct approach.
29+
30+
## 3. ReAct Pattern Removal
31+
**Files:** `js/ai-docgen-generate.js`
32+
**What:** Removed the iterative Reason → Act loop (which made 2-6 model calls per generation) and replaced it with the simple two-pass refinement described above.
33+
**Impact:** Think mode is now much faster (2 calls instead of 4-6), stays on-topic, and avoids output drift that occurred with the multi-iteration loop.
34+
35+
## 4. Search Dropdown CSS & Positioning
36+
**Files:** `css/ai-docgen.css`
37+
**What:** Added CSS for multi-select search dropdown with checkbox pills, proper z-index stacking, and positioning fixes to ensure the dropdown is visible above all card elements.
38+
**Impact:** Search dropdowns open correctly and are fully visible on all card types.
39+
40+
## 5. Search Provider Fix
41+
**Files:** `js/ai-web-search.js`
42+
**What:** Minor fix to search provider handling for compatibility with multi-select arrays.
43+
**Impact:** Search works correctly when multiple providers are selected.
44+
45+
---
46+
47+
## Files Changed (4 total)
48+
49+
| File | Lines Changed | Type |
50+
|------|:---:|------|
51+
| `css/ai-docgen.css` | +96 | Multi-select search dropdown styles |
52+
| `js/ai-docgen-generate.js` | +56 −25 | Think refinement, ReAct removal |
53+
| `js/ai-docgen.js` | +110 −31 | Multi-select search provider UI |
54+
| `js/ai-web-search.js` | +2 −2 | Multi-provider compatibility |

css/ai-docgen.css

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,6 +2100,102 @@
21002100
color: #1e293b;
21012101
}
21022102

2103+
/* Multi-select search pill panel on AI/Agent cards */
2104+
.ai-search-pills-panel {
2105+
padding: 6px 12px;
2106+
border-top: 1px solid rgba(16, 185, 129, 0.15);
2107+
background: rgba(16, 185, 129, 0.04);
2108+
animation: ai-pills-slide 0.2s ease;
2109+
}
2110+
2111+
@keyframes ai-pills-slide {
2112+
from { opacity: 0; max-height: 0; }
2113+
to { opacity: 1; max-height: 48px; }
2114+
}
2115+
2116+
.ai-search-pills-row {
2117+
display: flex;
2118+
flex-wrap: wrap;
2119+
gap: 4px;
2120+
align-items: center;
2121+
}
2122+
2123+
.ai-card-search-pill {
2124+
display: inline-flex;
2125+
align-items: center;
2126+
gap: 0;
2127+
padding: 2px 8px;
2128+
border-radius: 12px;
2129+
border: 1px solid var(--border-color, rgba(255,255,255,0.12));
2130+
background: rgba(255,255,255,0.05);
2131+
color: var(--text-color, #e6edf3);
2132+
font-size: 0.72em;
2133+
cursor: pointer;
2134+
transition: all 0.2s;
2135+
user-select: none;
2136+
opacity: 0.55;
2137+
}
2138+
2139+
.ai-card-search-pill:hover {
2140+
opacity: 0.85;
2141+
border-color: #10b981;
2142+
}
2143+
2144+
.ai-card-search-pill.active {
2145+
opacity: 1;
2146+
border-color: #10b981;
2147+
background: rgba(16, 185, 129, 0.12);
2148+
color: #10b981;
2149+
font-weight: 500;
2150+
}
2151+
2152+
[data-theme="dark"] .ai-card-search-pill.active {
2153+
color: #34d399;
2154+
background: rgba(52, 211, 153, 0.12);
2155+
border-color: rgba(52, 211, 153, 0.4);
2156+
}
2157+
2158+
.ai-card-search-pill input[type="checkbox"] {
2159+
display: none;
2160+
}
2161+
2162+
.ai-card-search-pill-label {
2163+
display: inline-flex;
2164+
align-items: center;
2165+
gap: 3px;
2166+
pointer-events: none;
2167+
white-space: nowrap;
2168+
}
2169+
2170+
/* Search toggle button active state */
2171+
.ai-search-multi-btn.active {
2172+
background: rgba(16, 185, 129, 0.15) !important;
2173+
color: #10b981 !important;
2174+
border-color: rgba(16, 185, 129, 0.4) !important;
2175+
}
2176+
2177+
[data-theme="light"] .ai-search-pills-panel {
2178+
background: rgba(16, 185, 129, 0.03);
2179+
border-top-color: rgba(16, 185, 129, 0.12);
2180+
}
2181+
2182+
[data-theme="light"] .ai-card-search-pill {
2183+
background: rgba(0,0,0,0.03);
2184+
border-color: rgba(0,0,0,0.1);
2185+
color: #334155;
2186+
}
2187+
2188+
[data-theme="light"] .ai-card-search-pill.active {
2189+
color: #059669;
2190+
background: rgba(16, 185, 129, 0.1);
2191+
border-color: rgba(16, 185, 129, 0.35);
2192+
}
2193+
2194+
[data-theme="light"] .ai-search-multi-btn.active {
2195+
color: #059669 !important;
2196+
background: rgba(16, 185, 129, 0.1) !important;
2197+
}
2198+
21032199
/* Ensure agent card actions wrap on narrow widths */
21042200
.ai-agent-card .ai-placeholder-actions {
21052201
flex-wrap: wrap;

js/ai-docgen-generate.js

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
var _dg = M._docgen;
99

10+
// Helper: read multi-select search providers from card pills
11+
function getCardSearchProviders(blockIndex) {
12+
var panel = document.querySelector('.ai-search-pills-panel[data-ai-index="' + blockIndex + '"]');
13+
if (!panel) return [];
14+
var providers = [];
15+
panel.querySelectorAll('.ai-card-search-check:checked').forEach(function (cb) {
16+
providers.push(cb.value);
17+
});
18+
return providers;
19+
}
20+
1021
// ==============================================
1122
// MODEL READINESS — ensure model is loaded before generation
1223
// ==============================================
@@ -766,15 +777,49 @@
766777
}
767778
}
768779

780+
// Read per-card multi-select search providers and perform web search if enabled
781+
var cardSearchProviders = getCardSearchProviders(blockIndex);
782+
var searchContext = '';
783+
if (cardSearchProviders.length > 0 && M.webSearch) {
784+
try {
785+
var searchResults = await M.webSearch.performMultiSearch(block.prompt, 5, cardSearchProviders);
786+
searchContext = M.webSearch.formatResultsForLLM(searchResults);
787+
} catch (_) { /* search failed, proceed without */ }
788+
}
789+
769790
var hasImages = workerAttachments.length > 0;
791+
var userPrompt = buildPrompt(block, prevContent, memoryContext, hasImages, varsContext);
792+
if (searchContext) {
793+
userPrompt = 'Web research results:\n' + searchContext + '\n\nUse the above search results to inform your response. Cite sources when relevant.\n\n' + userPrompt;
794+
}
795+
796+
var useThinking = block.type === 'Think' || block.think;
770797
result = await M.requestAiTask({
771798
taskType: 'generate',
772799
context: prevContent.substring(Math.max(0, prevContent.length - 3000)),
773-
userPrompt: buildPrompt(block, prevContent, memoryContext, hasImages, varsContext),
774-
enableThinking: block.type === 'Think',
800+
userPrompt: userPrompt,
801+
enableThinking: useThinking,
775802
silent: true,
776803
attachments: workerAttachments
777804
});
805+
806+
// When Think is ON, refine: pass the result back and ask the model to enrich it
807+
if (useThinking) {
808+
var draft = cleanGeneratedOutput(result);
809+
console.log('[DocGen Think] 🧠 Refining output (' + draft.length + ' chars)...');
810+
var refinePrompt = 'Here is a draft response:\n\n' + draft + '\n\n'
811+
+ 'Improve this content by adding important details, examples, or missing information. '
812+
+ 'Keep the same structure and tone. Output the complete improved version.';
813+
result = await M.requestAiTask({
814+
taskType: 'generate',
815+
context: draft.substring(0, 2000),
816+
userPrompt: refinePrompt,
817+
enableThinking: false,
818+
silent: true,
819+
attachments: []
820+
});
821+
console.log('[DocGen Think] 🧠 Refinement done (' + cleanGeneratedOutput(result).length + ' chars)');
822+
}
778823
}
779824

780825
_dg.activeBlockOps.delete(blockIndex);
@@ -900,8 +945,7 @@
900945
return;
901946
}
902947

903-
var searchSelect = document.querySelector('.ai-agent-search-select[data-ai-index="' + blockIndex + '"]');
904-
var searchProvider = searchSelect ? searchSelect.value : 'off';
948+
var cardSearchProviders = getCardSearchProviders(blockIndex);
905949

906950
_dg.activeBlockOps.add(blockIndex);
907951
var agentCard = document.querySelector('.ai-placeholder-card[data-ai-index="' + blockIndex + '"]');
@@ -913,6 +957,7 @@
913957
var statusEl = stepEls[stepIdx].querySelector('.ai-agent-step-status');
914958
if (statusEl) {
915959
if (status === 'running') statusEl.textContent = '⏳';
960+
else if (status === 'reasoning') statusEl.textContent = '🤔';
916961
else if (status === 'done') statusEl.textContent = '✅';
917962
else if (status === 'error') statusEl.textContent = '❌';
918963
else statusEl.textContent = '⏸';
@@ -927,15 +972,19 @@
927972
var allResults = [];
928973
var docContext = text.substring(0, block.start);
929974

975+
// Check if Think mode is enabled for this Agent card
976+
var thinkToggle = agentCard ? agentCard.querySelector('.ai-think-toggle') : null;
977+
var useThinking = thinkToggle && thinkToggle.classList.contains('active');
978+
930979
for (var i = 0; i < steps.length; i++) {
931980
updateStepStatus(i, 'running');
932981

933982
var stepPrompt = 'You are an expert writer. This is step ' + steps[i].number
934983
+ ' of ' + steps.length + ' in a multi-step writing flow.\n\n';
935984

936-
if (searchProvider !== 'off' && M.webSearch) {
985+
if (cardSearchProviders.length > 0 && M.webSearch) {
937986
try {
938-
var searchResults = await M.webSearch.performSearch(steps[i].description);
987+
var searchResults = await M.webSearch.performMultiSearch(steps[i].description, 5, cardSearchProviders);
939988
var searchContext = M.webSearch.formatResultsForLLM(searchResults);
940989
stepPrompt += 'Web research results:\n' + searchContext + '\n\n';
941990
} catch (_) { /* search failed, proceed without */ }
@@ -995,11 +1044,29 @@
9951044
taskType: 'generate',
9961045
context: accumulatedContext || docContext.substring(Math.max(0, docContext.length - 2000)),
9971046
userPrompt: stepPrompt,
998-
enableThinking: false,
1047+
enableThinking: useThinking,
9991048
silent: true,
10001049
attachments: agentAttachments
10011050
});
10021051

1052+
// When Think is ON, refine each step's output
1053+
if (useThinking) {
1054+
var draft = cleanGeneratedOutput(result);
1055+
console.log('[Agent Think] 🧠 Step ' + steps[i].number + ' refining (' + draft.length + ' chars)...');
1056+
var refinePrompt = 'Here is a draft for step ' + steps[i].number + ':\n\n' + draft + '\n\n'
1057+
+ 'Improve this content by adding important details, examples, or missing information. '
1058+
+ 'Keep the same structure and tone. Output the complete improved version.';
1059+
result = await M.requestAiTask({
1060+
taskType: 'generate',
1061+
context: draft.substring(0, 2000),
1062+
userPrompt: refinePrompt,
1063+
enableThinking: false,
1064+
silent: true,
1065+
attachments: []
1066+
});
1067+
console.log('[Agent Think] 🧠 Step ' + steps[i].number + ' refined (' + cleanGeneratedOutput(result).length + ' chars)');
1068+
}
1069+
10031070
var cleaned = cleanGeneratedOutput(result);
10041071
accumulatedContext += '\n\n' + cleaned;
10051072
allResults.push(cleaned);

0 commit comments

Comments
 (0)