Query interpreter

From lowtidebuild/stock-analysis-agent · View interactive version

Query interpreter is an AI agent skill from the GitHub repository lowtidebuild/stock-analysis-agent. **Role**: Step 1 — Parse the user's query to extract ticker(s), determine output mode, detect language, and validate intent.

How to use this skill

Skill file

Query Interpreter — SKILL.md

Role: Step 1 — Parse the user's query to extract ticker(s), determine output mode, detect language, and validate intent.

Triggered by: CLAUDE.md after Step 0 determines fresh collection needed

Reads: User query, references/ticker-resolution-guide.md

Writes: Sets session variables: ticker, market, output_mode, output_language, peers (if multi-ticker)

References: ticker-resolution-guide.md


Instructions

Step 1.1 — Detect Analysis Intent

First, determine if this is an analysis request or a price-only query (not supported).

Price-only queries (not supported — respond with guidance):

IF price-only query detected:
    → Respond: "가격 조회는 지원하지 않습니다. Yahoo Finance / Perplexity에서 확인하시거나,
                '{ticker} 분석해줘'로 심층 분석을 요청하세요."
    → Do not proceed further

Analysis triggers (full analysis — proceed with workflow):

Step 1.2 — Detect Multi-Ticker Query

Check for comparison/peer analysis indicators:

Multi-ticker triggers: vs, versus, 비교, and, compare, 대, 와, comma-separated tickers

Examples:

IF multi-ticker:
    → Set workflow = 2
    → Extract all tickers (deduplicated, max 5)
    → Set output_mode = "B" (default for Workflow 2) unless user specifies differently

Step 1.3 — Ticker Resolution

US tickers (1–5 uppercase letters):

Korean tickers (6-digit numeric):

Ambiguous cases:

  1. If ticker could be US or Korean: ask user to clarify market
  2. If Korean company name not resolved: attempt web search, then ask if still unresolved
  3. If US ticker returns no data: suggest similar tickers

Clarification protocol (max 3 questions total, then proceed with best guess):

Question format:

"{ticker}를 분석하시려는 건가요? 확인해드리기 위해 몇 가지 확인이 필요합니다:
1. [clarification question]"

Step 1.4 — Output Mode Selection

Apply this decision table:

| User Signal | Output Mode |

|------------|-------------|

| "빠르게" / "간략하게" / "quick" / "brief" / "glance" / "스크리닝" / "한눈에" | A |

| "비교" / "vs" / "compare" (multi-ticker) | B |

| "심층" / "자세히" / "deep dive" / "detailed" / "full" | C |

| "투자 메모" / "memo" / "investment memo" / "리포트" | D |

| "실적" / "earnings" / "프리뷰" / "preview" / "review" / "어닝스" / "Q1" / "Q2" / "Q3" / "Q4" + 분석 의도 | E (Earnings Preview/Review) |

| --earnings-mode preview\|review flag | E (forced sub_mode) |

| --mode E flag | E (force earnings dispatch) |

| Workflow 1 + earnings-window-detector returns preview or review (no explicit mode in user query) | E (auto-suggested, user can override) |

| No explicit mode signal, single ticker | C (default) |

| No explicit mode signal, multi-ticker | B (default) |

| Portfolio review | C per stock (abbreviated) |

| Watchlist scan | A per stock (abbreviated) |

Mode E sub-mode selection (preview vs review):

  1. If user passes --earnings-mode preview|review → forced.
  2. Else if earnings-window-detector returned window="preview" → sub_mode="preview".
  3. Else if window="review" → sub_mode="review".
  4. Else if user explicitly typed "프리뷰/preview" → preview; "review/리뷰" → review.
  5. Else if window="none" and user typed "실적/earnings" only → confirm with user or downgrade to Mode C with informational note "현재 실적 윈도우(D-7~D+3)가 아닙니다. Mode C로 진행할까요?"

Mode E precedence rule: when both an explicit Mode A/B/C/D signal and an earnings keyword are present in the same query, the explicit mode wins. Surface a one-line informational note: "[{ticker}] 실적 윈도우 진행 중 — Mode E도 가능합니다. 진행: Mode {explicit}."

Mode confirmation (optional):

Step 1.5 — Output Language Detection

| Condition | Language |

|-----------|----------|

| Query in Korean | Korean (ko) |

| Query in English | English (en) |

| Mixed or ambiguous | Detect by majority language |

| Korean stock (KR market) | Korean preferred, English accepted |

| US stock | English preferred, Korean accepted |

Language affects: all output text, section headers, verdict translations, price formatting (₩ vs $).

Step 1.6 — Company Type Pre-detection

Attempt to identify company type early (for metric selection in later steps):

| Indicator | Type |

|-----------|------|

| Bank / 은행 / Insurance | Financial |

| Pharma / Biotech / biopharma / 제약 / 바이오 | Biotech/Pharma |

| REIT / 리츠 | Financial (REIT) |

| Manufacturing / 제조 / Industrial / 산업 | Industrial |

| Consumer / Retail / 유통 / 소비 | Consumer |

| Tech / Software / Platform | Technology/Platform |

| Energy / Oil / Gas / 에너지 / 정유 | Energy |

This is a preliminary assessment; market-router/SKILL.md will confirm via API in Step 2.

Step 1.7 — Set Session State

Output session state block:

=== Query Interpretation ===
Ticker(s): {list}
Market(s): {US/KR}
Workflow: {1/2/3}
Output Mode: {A/B/C/D/E}
Earnings Sub-Mode: {preview/review/—}     # only when Mode E
Earnings Window: {preview/review/none}    # from earnings-window-detector (Workflow 1)
Days until next ER: {N or —}
Output Language: {en/ko}
Company Type (pre-detected): {type or "unknown"}
Peer tickers: {list or none}
Delta mode: {yes/no}

→ Proceeding to Step 2 (Market Router)

Mode E branch — Workflow 1 only: when output_mode=E, the session state must also surface:

When output_mode=E and next_earnings_confirmed=false, do NOT advance. Print: "실적 발표일을 확정할 수 없습니다. Mode C로 전환할까요?" and either confirm Mode C or wait.

When output_mode=E and earnings_sub_mode is unset (e.g. user said "earnings" outside the window), apply Step 1.4 rule 5 (downgrade-with-confirm).

For Mode A/B/C/D, leave the earnings-related fields as —.


Completion Check

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.