Skip to content

Commit 64b0902

Browse files
committed
Add semantic second-pass LLM escalation
1 parent 69fe5c9 commit 64b0902

14 files changed

Lines changed: 626 additions & 22 deletions

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ OPENAI_BACKUP_API_MODE=chat
2525
OPENAI_BACKUP_MODEL=
2626
OPENAI_BACKUP_TIMEOUT=60
2727

28+
# High-recall semantic second pass for important empty/rejected recognition.
29+
# If OPENAI_SEMANTIC_API_KEY is empty, scripts can reuse OPENAI_API_KEY.
30+
OPENAI_SEMANTIC_API_KEY=
31+
OPENAI_SEMANTIC_BASE_URL=
32+
OPENAI_SEMANTIC_API_MODE=messages
33+
OPENAI_SEMANTIC_MODEL=
34+
OPENAI_SEMANTIC_TIMEOUT=120
35+
LLM_SEMANTIC_SECOND_PASS=1
36+
LLM_SEMANTIC_MIN_LIQUIDITY=1000
37+
LLM_SEMANTIC_MIN_VOLUME_24H=1000
38+
2839
# Fallback provider.
2940
OPENAI_FALLBACK_API_KEY=
3041
OPENAI_FALLBACK_BASE_URL=

docs/superpowers/plans/2026-05-13-llm-research-profile.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
44
5-
**Goal:** Make the tested LLM provider order the default for discovery, rule promotion, and cross-platform verification without committing secrets or changing trading behavior.
5+
**Goal:** Make the tested LLM provider order the default for discovery, rule promotion, and cross-platform verification without committing secrets or changing trading behavior. Add a high-recall semantic second pass for important cases where the normal path returns empty or non-tradeable recognition.
66

7-
**Architecture:** Add one shell profile loader that fills missing `OPENAI_*` provider settings from the benchmark-derived profile. Source it from the three mainline LLM scripts after `.env.local` loads and before they snapshot provider variables. Keep all keys external and preserve explicit user overrides unless force mode is enabled.
7+
**Architecture:** Add one shell profile loader that fills missing `OPENAI_*` provider settings from the benchmark-derived profile. Source it from the three mainline LLM scripts after `.env.local` loads and before they snapshot provider variables. Keep all keys external and preserve explicit user overrides unless force mode is enabled. The loader also exposes `OPENAI_SEMANTIC_*` for `doubao-seed-1-8-251228/messages`; scripts use it only as a second pass for important discovery batches, near-miss promotion candidates, and cross-platform opportunity candidates.
88

99
**Tech Stack:** Bash shell scripts, Python `pytest`, existing OpenAI-compatible client in `poly_strategy/openai_rules.py`.
1010

@@ -22,6 +22,12 @@
2222
- Same loader source position.
2323
- Modify: `scripts/run_cross_platform_scan_once.sh`
2424
- Same loader source position before cross-platform verifier command.
25+
- Modify: `poly_strategy/rule_discovery.py`
26+
- Retry empty important discovery batches with a semantic client.
27+
- Modify: `poly_strategy/exhaustive_groups.py`
28+
- Recheck non-tradeable near-miss group verification before caching rejection.
29+
- Modify: `poly_strategy/cli.py`
30+
- Wire semantic clients into discovery, exhaustive group promotion, and cross-platform verification.
2531

2632
## Task 1: Add Loader Tests First
2733

docs/superpowers/specs/2026-05-13-llm-research-profile-design.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Provider order:
3636
| primary | `windhub/deepseek-v3-2-251201` | `https://windhub.cc/v1` | `messages` | Best balance of strict recall and latency among stable candidates |
3737
| secondary | `secondary/gemini-3.1-pro-preview` | `https://api.xn--chy-js0fk50c.top/v1` | `chat` | Formal CLI smoke passed; lower semantic strength but fast |
3838
| backup | `elysiver/longcat-flash-chat` | `https://elysiver.h-e.top/v1` | `chat` | Best stable elysiver result, good recall and moderate latency |
39+
| semantic | `windhub/doubao-seed-1-8-251228` | `https://windhub.cc/v1` | `messages` | Slow high-recall second pass for important empty/rejected cases |
3940
| fallback | `gpt-5.4-mini` on the original responses endpoint | `https://api.wwcloud.app` | `responses` | Lower-cost responses-compatible last resort |
4041

4142
Optional profile: `semantic`
@@ -56,6 +57,7 @@ Responsibilities:
5657
- Default to `LLM_RESEARCH_PROFILE=balanced`.
5758
- Never define API keys directly.
5859
- Only assign provider roles whose matching key variables are already present.
60+
- Expose a separate `OPENAI_SEMANTIC_*` role when either `OPENAI_SEMANTIC_API_KEY` or the primary windhub `OPENAI_API_KEY` is present.
5961
- Preserve explicit user overrides unless `LLM_RESEARCH_PROFILE_FORCE=1`.
6062
- Print a sanitized provider summary when `LLM_RESEARCH_PROFILE_VERBOSE=1`.
6163

@@ -66,6 +68,7 @@ Key mapping:
6668
| primary/windhub | `OPENAI_API_KEY` |
6769
| secondary/new middle provider | `OPENAI_SECONDARY_API_KEY` |
6870
| backup/elysiver | `OPENAI_BACKUP_API_KEY` |
71+
| semantic/windhub high recall | `OPENAI_SEMANTIC_API_KEY` or `OPENAI_API_KEY` |
6972
| fallback/original responses endpoint | `OPENAI_FALLBACK_API_KEY` |
7073

7174
The loader should set models, modes, and base URLs but leave key values untouched.
@@ -87,12 +90,18 @@ Default run:
8790
1. `.env.local` loads secrets and base endpoint values.
8891
2. `load_llm_research_profile.sh` fills missing model/mode/base-url values from the benchmark profile.
8992
3. Existing provider health checks and retry/fallback behavior remain responsible for runtime failures.
90-
4. The scripts continue to write current logs such as `discover_provider label=...` and `rule_promotion_provider label=...`.
93+
4. Important cases get semantic second-pass recognition before the final fallback path:
94+
- discovery retries empty high-liquidity/high-volume or neg-risk batches with `OPENAI_SEMANTIC_MODEL`
95+
- rule promotion rechecks non-tradeable near-miss groups with the semantic verifier before caching rejection
96+
- cross-platform verification continues to semantic when a parsed provider response does not verify every candidate in the batch
97+
5. The scripts continue to write current logs such as `discover_provider label=...` and `rule_promotion_provider label=...`.
9198

9299
Override examples:
93100

94101
- Set `OPENAI_MODEL=...` to override only the primary model.
95102
- Set `LLM_RESEARCH_PROFILE=semantic` for the slow high-recall primary.
103+
- Set `LLM_SEMANTIC_SECOND_PASS=0` to disable semantic second-pass calls in the shell workflows.
104+
- Tune discovery importance with `LLM_SEMANTIC_MIN_LIQUIDITY` and `LLM_SEMANTIC_MIN_VOLUME_24H` (defaults: `1000` each).
96105
- Set `LLM_RESEARCH_PROFILE_FORCE=1` to replace all profile-managed model/mode/base-url values.
97106
- Set `LLM_RESEARCH_PROFILE=off` to disable the loader.
98107

0 commit comments

Comments
 (0)