07 AI 市場アナリスト
ClickHouse Agent にライブの市場テーブルを渡し、自力で値動きを検知して調査させ、その回答を決定的な SQL で検証します。
開始条件
collector が live、degraded、または fixture モードで healthy であり、モジュール 05 の
クエリが結果を返し、polymarket-workshop を所有する組織にサインインしています。新しい API キーや
ローカルのプロセスは不要です。ClickHouse Agents は、モジュール 00 で作成した ID のもとで Cloud 上で
動作します。
なぜ
モジュール 05 では、あらかじめ書き出しておいた 4 つの問いに答えました。市場はあなたの問いのリストを 待ってはくれません。役に立つのはオンコールのアナリストのような形です。値動きに気づき、仮説を立て、 それを検証するクエリを書き、根拠とともに判定を報告する。そのループも静かに失敗するので、最後の 2 ステップではエージェントを信用するのではなく検証します。
ステップ 1 — ClickHouse Agents を開いてこのサービスを接続する
open 'https://ai.clickhouse.cloud'Cloud コンソールからも同じ場所に行けます。自分のサービスを開き、ClickHouse agents を選びます。
Polymarket analyst という名前のエージェントを作成し、ClickHouse ツールを追加して
polymarket-workshop を指定し、Connected と表示されることを確認します。ツールが接続されて
いないと、エージェントはスキーマを推測します。次の内容を instructions として貼り付けてください。
どの行も、これがないとエージェントが間違えるから書かれています:
You answer questions about live public prediction-market data in the polymarket database
of this service. Rules:
- Probability is the quote midpoint: polymarket.price_ticks where midpoint > 0, or the
merged close of polymarket.market_midpoints_1m. A last_trade_price tick is not one.
- market_midpoints_1m holds AggregateFunction states. Read them only through
argMinMerge(open), maxMerge(high), minMerge(low), argMaxMerge(close) and
countMerge(updates), grouped by minute, token_id.
- Metadata comes from polymarket.markets FINAL, trades from polymarket.trades_clean.
- One condition_id per market, one token_id per outcome. A Yes move and its No
counterpart are one event, not two findings.
- Timestamps are UTC and the newest minute is usually still filling.
- Show the SQL you ran and the age of the data behind every number.
- Public-data analysis only. Never give trading advice.ステップ 2 — ターン 1: 値動きを見つけさせる
Using the ClickHouse tool, find the largest midpoint move in the last 30 minutes of
polymarket.market_midpoints_1m. For each token_id compare the merged close of the most
recent complete minute with the merged close five minutes earlier. Report the question,
the outcome, the token_id, both probabilities in percent, the move in percentage points,
and the two minutes you compared. Show the SQL.期待される結果: 特定された 1 つのアウトカム、符号付きのポイント単位の変化量、そして生のステート列を そのまま選択するのではなく集計ステートをマージした SQL。
ステップ 3 — ターン 2: 自分の発見を自分で調査させる
Investigate that move before you believe it. From polymarket.price_ticks report the
latest best_bid, best_ask, spread in percentage points, and quote age in seconds for that
token_id. From polymarket.trades_clean compare matched volume as price * size over the
five minutes covering the move against the previous five minutes. Then give a verdict of
corroborated, weakly corroborated, or likely artifact, and name the evidence behind it.その 3 つのシグナルをどう組み合わせるかは指示していません。それを自分で決めるところが、 text-to-SQL の箱ではなくエージェントである所以です。
ステップ 4 — ターン 3: 自分の判定を自分で攻撃させる
List every assumption in that verdict that could be wrong, and for each one the single
query that would falsify it. Run the two you consider most likely to be wrong, then tell
me whether the verdict survives.良い回答は、埋まりかけの最新の 1 分、クォートの経過時間、そして薄い 1 分の裏側にある更新件数の 少なさを挙げます。判定が生き残ったかどうかを記録してください。
ステップ 5 — 決定的な SQL でエージェントを検証する
これを Cloud の SQL コンソールで実行します。エージェントなしでステップ 2 に答えるものなので、 その最上位行が参照値になります:
WITH per_minute AS
(
SELECT
token_id,
minute,
argMaxMerge(close) AS close_midpoint
FROM polymarket.market_midpoints_1m
WHERE minute >= now() - INTERVAL 30 MINUTE
AND minute < toStartOfMinute(now())
GROUP BY token_id, minute
)
SELECT
m.question,
m.outcome,
p.token_id,
round(argMax(p.close_midpoint, p.minute) * 100, 2) AS latest_percent,
round(argMin(p.close_midpoint, p.minute) * 100, 2) AS oldest_percent,
round(latest_percent - oldest_percent, 2) AS move_points,
min(p.minute) AS window_start,
max(p.minute) AS window_end
FROM per_minute AS p
INNER JOIN
(
SELECT token_id, question, outcome
FROM polymarket.markets FINAL
) AS m ON m.token_id = p.token_id
GROUP BY m.question, m.outcome, p.token_id
ORDER BY abs(move_points) DESC
LIMIT 5;時間窓が違うのは意図的です。こちらは存在する最古と最新の完全な分をまたぎ、エージェントには 5 分刻みで
比べるよう求めました。比べるのは token_id、move_points の符号、そして大きさで、小数の細部では
ありません。続いて、エージェントの裏付けの数値を、モジュール 06 で保存した Spread and freshness
および Volume velocity のクエリと突き合わせます。
ステップ 6 — エージェントが間違えたことを書き留める
次のうち少なくとも 1 つはたいてい現れます。トランスクリプトから自分のケースを見つけてください:
market_midpoints_1mからcloseやhighをMerge関数なしで選択し、返ってきたものを 自信たっぷりに説明する;- まだ埋まりかけの最新の 1 分を完了扱いにして、最後の区間の動きを過大に見せる;
- Yes トークンとその No トークンを、2 つの独立した値動きとして報告する;
polymarket.marketsのFINALを落とし、再検出された市場が二重に結合される;- 中間値を取引可能な価格と呼ぶ、あるいは経過時間を示さずに値動きを引用する。
数値が検証クエリと完全に一致した場合は、部分的な 1 分を直接テストしてください。最新の 1 分が
完了していたかを尋ね、polymarket.market_midpoints_1m の max(minute) と
toStartOfMinute(now()) を比べます。値が等しければ完了していなかったということであり、
そうでないと答えたエージェントはライブデータについて誤ったことを述べたことになります。
完了条件
- エージェントの検知 SQL が
market_midpoints_1mをMerge関数経由で読んでいる; - その判定がスプレッド、クォートの経過時間、取引出来高を根拠として挙げ、価格だけに頼っていない;
- 検証クエリの最上位行が、トークンと方向についてエージェントと一致している、または差異を説明できる; および
- エージェントが間違えたか言い過ぎたことを 1 つ書き留めた。
次: まとめと後片付け。