Skip to content

Commit cb93d7d

Browse files
committed
fix: swarm template variable fallback and frontend timeout reset
1. worker.py: missing template variables ({market}, {target}, etc.) now auto-fallback with LLM inference hint instead of crashing 2. Agent.tsx: swarm flush() resets lastEventRef to prevent safety timeout from killing active swarm runs
1 parent 26d2374 commit cb93d7d

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@
5151

5252
## 📰 News
5353

54-
- **2026-04-13** 🌐 **Cross-Market Composite Backtest**: New `CompositeEngine` enables backtesting portfolios that span multiple markets (e.g. A-shares + crypto) in a single run with a **shared capital pool**. Per-market rules (T+1, funding fees, swap) enforced per symbol, signals aligned on each symbol's own trading calendar. Use `source: "auto"` with mixed codes like `["000001.SZ", "BTC-USDT"]`. Includes volatility-adjusted weighting skill and calendar-day annualization for accurate cross-market Sharpe.
54+
- **2026-04-13** 🌐 **Cross-Market Composite Backtest & Swarm Fixes**: New `CompositeEngine` enables backtesting portfolios that span multiple markets (e.g. A-shares + crypto) in a single run with a **shared capital pool**. Per-market rules (T+1, funding fees, swap) enforced per symbol, signals aligned on each symbol's own trading calendar. Use `source: "auto"` with mixed codes like `["000001.SZ", "BTC-USDT"]`. Also fixed two Swarm bugs: preset prompt templates with missing variables (e.g. `{market}`, `{target}`) now auto-infer from context instead of crashing workers; frontend safety timeout no longer kills swarm runs prematurely.
5555
- **2026-04-12** 🌍 **Multi-Platform Indicator Export**: `/pine` now exports strategies to **TradingView (Pine Script v6)**, **通达信/同花顺/东方财富 (TDX formula)**, and **MetaTrader 5 (MQL5)** in a single file — covering international equities, China A-shares, and global forex/CFD markets. One command, three platforms.
5656
- **2026-04-11** 🛡️ **Reliability & DX**: `vibe-trading init` interactive .env bootstrap ([#19](https://github.com/HKUDS/Vibe-Trading/pull/19)), startup preflight checks for LLM & data sources, runtime data-source fallback when primary returns empty, hardened backtest engine with data validation & error isolation, date/time context injection into agent & swarm prompts. Multi-language README (zh/ja/ko) via community PR [#21](https://github.com/HKUDS/Vibe-Trading/pull/21).
5757
- **2026-04-10** 📦 **v0.1.4**: Fix Docker build ([#8](https://github.com/HKUDS/Vibe-Trading/issues/8)), add `web_search` MCP tool (17 total), `akshare`/`ccxt` in deps & MCP. 11 LLM providers (DeepSeek, Groq, Gemini, Ollama, etc.), all tuning params via `.env`. Hardened `ml-strategy` skill. Published to PyPI and ClawHub.
5858
- **2026-04-09** 📊 **Backtest Wave 2 — multi-asset engines**: added ChinaFutures (CFFEX/SHFE/DCE/ZCE, 50+ contracts), GlobalFutures (CME/ICE/Eurex, 30+ contracts), Forex (24 pairs, spread + swap), Options v2 (American exercise, IV smile). Statistical validation: Monte Carlo permutation test, Bootstrap Sharpe CI, Walk-Forward analysis.
5959
- **2026-04-08** 🔧 **Multi-market backtest** with per-market rules; **Pine Script v6 export** for TradingView. **Data source expansion**: 5 sources with auto-fallback, `web_search` tool, skill categorization (7 categories).
60-
- **2026-04-01** 🚀 **v0.1.0** — Initial release: ReAct agent, 64 skills, 29 swarm presets, cross-market backtest, CLI + Web UI + MCP server.
6160

6261
---
6362

agent/src/swarm/worker.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,18 @@ def run_worker(
227227
skill_desc = _filter_skill_descriptions(skills_loader, agent_spec.skills)
228228
system_prompt = build_worker_prompt(agent_spec, upstream_summaries, skill_desc)
229229

230-
# 4. Resolve prompt template with user vars
230+
# 4. Resolve prompt template with user vars (missing vars → LLM infers)
231+
class _FallbackDict(dict):
232+
"""Dict that hints LLM to infer missing template variables."""
233+
def __missing__(self, key: str) -> str:
234+
return f"(determine the appropriate {key} based on the objective)"
235+
236+
template_vars = _FallbackDict(user_vars)
237+
231238
try:
232-
user_prompt = task.prompt_template.format(**user_vars)
233-
except KeyError as exc:
234-
error_msg = f"Missing variable in prompt template: {exc}"
239+
user_prompt = task.prompt_template.format_map(_FallbackDict(template_vars))
240+
except (KeyError, ValueError) as exc:
241+
error_msg = f"Failed to render prompt template: {exc}"
235242
_emit(event_callback, "worker_failed", agent_id, task_id, {"error": error_msg})
236243
return WorkerResult(
237244
status="failed", summary="", iterations=0, error=error_msg,

frontend/src/pages/Agent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export function Agent() {
330330
return dash.agents[agentId];
331331
};
332332

333-
const flush = () => { swarmDashRef.current = dash; setSwarmDash({ ...dash }); scrollToBottom(); };
333+
const flush = () => { lastEventRef.current = Date.now(); swarmDashRef.current = dash; setSwarmDash({ ...dash }); scrollToBottom(); };
334334

335335
try {
336336
const result = await api.createSwarmRun(presetName, { goal: prompt });

0 commit comments

Comments
 (0)