fix: NOFXi Agent real AI integration + quality improvements

Critical fixes:
1. Agent now uses NOFX's MCP client for AI calls (real models, not placeholder)
   - Gets AI client from first configured trader's MCP config
   - Added AutoTrader.GetMCPClient() export
2. /analyze uses REAL market data (market.Get → EMA/MACD/RSI/BB/OI/funding)
   then sends to AI — no more hallucinated prices
3. AI chat enriches prompts with live market data when user mentions a coin
4. Fallback: if AI unavailable, shows raw formatted market data (still useful)

Router improvements:
- Better natural language detection for Chinese
- '该不该买' '走势' '趋势' '行情' → analyze intent
- '多少钱' '赚了' '亏了' → query intent
- Fewer messages falling through to generic chat

Web UI:
- Endpoints updated to /api/agent/* namespace
- nofxi.html served at agent root (localhost:8900)

Result: AI analysis now shows real BTC price, real RSI, real EMA — not fiction.
This commit is contained in:
shinchan-zhai
2026-03-23 00:11:24 +08:00
parent 27498b8ec9
commit 017a8df265
6 changed files with 94 additions and 14 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"log/slog"
"net/http"
"os"
"time"
)
@@ -76,9 +77,27 @@ func (w *WebHandler) StartStandalone(port int) {
// Ticker
mux.HandleFunc("/api/agent/ticker", handleTicker)
// Serve nofxi.html as the root page
mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(rw, r)
return
}
// Try web/nofxi.html relative to executable, then working dir
paths := []string{"web/nofxi.html", "../web/nofxi.html"}
for _, p := range paths {
if _, err := os.Stat(p); err == nil {
http.ServeFile(rw, r, p)
return
}
}
rw.Header().Set("Content-Type", "text/html")
rw.Write([]byte("<h1>NOFXi Agent</h1><p>API is running. Web UI not found.</p>"))
})
go func() {
addr := fmt.Sprintf(":%d", port)
w.logger.Info("NOFXi agent web API starting", "port", port)
w.logger.Info("NOFXi agent web starting", "port", port, "url", fmt.Sprintf("http://localhost:%d", port))
if err := http.ListenAndServe(addr, mux); err != nil {
w.logger.Error("agent web server error", "error", err)
}