Live release feed
Sub-second macro releases for FX backtests
Point-in-time history
Official CPI, jobs, GDP, and central-bank events with point-in-time history.
USD 25/month 14-day free trial
Start Free Trial
Build a Two-Agent FX Stack: Research Agent + Execution Gatekeeper image
Share headline card X LinkedIn Email
Download

Reference

Macro Education

Build a Two-Agent FX Stack: Research Agent + Execution Gatekeeper

Design a safer AI FX workflow by splitting analysis from execution approval: one agent researches macro setups, a second gatekeeper enforces risk rules and blocks unsafe trades before they reach your broker.

他言語版 English
Share article X LinkedIn Email

研究エージェント + 執行ゲートキーパー

執筆者: FXマクロデータチーム
発行: May 21, 2026

単一の代理人FXボットが失敗する理由は単純です.アイデアを生成する同じモデルが,それらを承認することも許されています. アメリカ合衆国 非農業の給与ポジションリスクに直接飛び込むことができます

This guide shows a safer architecture: split responsibilities between two agents. The first agent does market research and proposes setups. The second agent is a strict gatekeeper that can only approve, resize, or reject proposals based on hard risk rules.

作業の流れがうまく行きます EUR/USD ほら 通貨の対価 直接REST API統合と MCPベースのツール統合の両方をサポートします

目標: 取引先の行動前に承認層を強制的に適用することで"AI取引アイデア"から"リスク検証されたAI取引候補"に移行します.

条件

  • Python 3.10+ 以上のものです
  • からのFXMacroData API キー API管理わかった
  • 研究者やゲートキーパーの 目的地です
  • JSONとHTTPAPIの基本的な知識

依存をインストールする:

pip install requests python-dotenv pydantic

創る .env ファイル:

FXMD_API_KEY=your_fxmacrodata_key
RESEARCH_MODEL=claude-or-hermes
GATEKEEPER_MODEL=claude-or-hermes
MAX_RISK_PCT=0.50

ステップ1: スタッフの役割を明確に定義する

どうしたらいいか 鍵の責任はコードを書く前に

  • 研究担当者:マクロ+市場文脈を読み込み,候補設定を提案する.
  • ゲートキーパーエージェント: 制限のみを検証する. 新しい取引を発明することはできません. 承認/拒否/サイズ変更のみです.

なぜ重要か この分離は,信頼性が高いのに証拠が弱い場合,単一のモデルがリスク制御を回避することを防ぐ.


Step 2: Pull structured context with direct REST calls

どうしたらいいか 公開情報とスポットデータを FXMacroDataから取得して 構造化されていない見出しではなく 清潔な入力を得ます

curl "https://fxmacrodata.com/api/v1/calendar/usd?api_key=YOUR_API_KEY"
curl "https://fxmacrodata.com/api/v1/announcements/eur/inflation?api_key=YOUR_API_KEY"
curl "https://fxmacrodata.com/api/v1/announcements/gbp/unemployment?api_key=YOUR_API_KEY"
curl "https://fxmacrodata.com/api/v1/forex?base=EUR&quote=USD&api_key=YOUR_API_KEY"

なぜ重要か 一貫した構造化されたフィールドは 両者とも同じ真実の源を与え 検証を決定的にするのです

Pythonの最小収集器:

import os
import requests
from datetime import datetime, timezone

API = "https://fxmacrodata.com/api/v1"
KEY = os.environ["FXMD_API_KEY"]


def fxmd_get(path, **params):
    r = requests.get(
        f"{API}{path}",
        params={"api_key": KEY, **params},
        timeout=25,
    )
    r.raise_for_status()
    return r.json()


def build_market_context():
    return {
        "asof_utc": datetime.now(timezone.utc).isoformat(),
        "calendar_usd": fxmd_get("/calendar/usd").get("data", [])[:8],
        "calendar_eur": fxmd_get("/calendar/eur").get("data", [])[:8],
        "eur_inflation": fxmd_get("/announcements/eur/inflation").get("data", [])[-1:],
        "gbp_unemployment": fxmd_get("/announcements/gbp/unemployment").get("data", [])[-1:],
        "eurusd": fxmd_get("/forex", base="EUR", quote="USD").get("data", [])[-48:],
        "gbpusd": fxmd_get("/forex", base="GBP", quote="USD").get("data", [])[-48:],
    }

ステップ3:研究代理人と取引候補者を生成する

どうしたらいいか 組織化された取引候補者だけ調査担当者に尋ねてください 実行準備の指示を送信させないで下さい

{
  "pair": "EUR/USD",
  "bias": "long|short|flat",
  "thesis": "string",
  "confidence": 0.0,
  "entry_zone": "string",
  "invalidation": "string",
  "event_risks": ["string"]
}

なぜ重要か 固定式ではゲートキーパーが 予測可能なフィールドに規則を適用できるのであり 自由形式のテキストを解析する代わりに

ポイント: 銀行内での状況も含む. 連邦準備制度理事会 ほら 銀行 検索プロンプトに通信を,しかし最終的な出力をコンパクトに保つ.

ステップ4: ゲートキーパーエージェントでハードリスク規則を執行

どうしたらいいか run every candidate through a second model or rule-first validator with strict limits.

政策の例:

  • 取引額最大リスク: 資本の0.50%
  • 市場から15分以内に新取引は行われない リリースカレンダーわかった
  • 強制的な無効化レベル
  • 信頼度 < 0.60 の場合は拒否する.

プイドンティックゲートと決定出力:

from pydantic import BaseModel, Field


class Candidate(BaseModel):
    pair: str
    bias: str
    thesis: str
    confidence: float = Field(ge=0.0, le=1.0)
    entry_zone: str
    invalidation: str
    event_risks: list[str]


class GateDecision(BaseModel):
    status: str  # approve, resize, reject
    approved_size_pct: float
    reason: str


def gate(candidate: Candidate, max_risk_pct: float = 0.50) -> GateDecision:
    if candidate.confidence < 0.60:
        return GateDecision(status="reject", approved_size_pct=0.0, reason="Low confidence")
    if not candidate.invalidation.strip():
        return GateDecision(status="reject", approved_size_pct=0.0, reason="Missing invalidation")
    proposed = 0.50 if candidate.confidence >= 0.75 else 0.30
    size = min(proposed, max_risk_pct)
    return GateDecision(status="approve", approved_size_pct=size, reason="Within policy")

なぜ重要か 研究エージェントが 悪い読み方をしても 門番は 大きすぎたか弱かったか ブロックできます


ステップ 5: MCP 統合 パスを追加 (ツールネイティブ エージェント ワークフロー)

どうしたらいいか FXMacroData を MCP を通して公開することで,各ボットにカスタム REST 粘着剤を構築するのではなく,エージェントフレームワークがツールをネイティブで呼び出すことができます.

Python ベースの MCP サーバを起動します uvxについて

uvx fxmacrodata-mcp --transport http --server-url https://fxmacrodata.com/mcp

クライアント設定例:

{
  "mcpServers": {
    "fxmacrodata": {
      "command": "uvx",
      "args": [
        "fxmacrodata-mcp",
        "--transport",
        "http",
        "--server-url",
        "https://fxmacrodata.com/mcp"
      ]
    }
  }
}

検索エージェントの MCP ツールコール スキーマの例:

{
  "name": "get_fx_calendar_and_spot",
  "description": "Get upcoming macro events and current spot context for selected pairs",
  "input_schema": {
    "type": "object",
    "properties": {
      "currencies": {
        "type": "array",
        "items": { "type": "string" }
      },
      "pairs": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "base": { "type": "string" },
            "quote": { "type": "string" }
          },
          "required": ["base", "quote"]
        }
      }
    },
    "required": ["currencies", "pairs"]
  }
}

エージェント呼び出し例 (MCP パス):

Research Agent:
"Using the fxmacrodata MCP tools, pull today's USD/EUR/GBP calendar and spot for EUR/USD and GBP/USD.
Return up to 3 candidate setups in strict JSON schema."

Gatekeeper Agent:
"Validate each candidate against risk policy v1. Reject anything violating confidence,
size, invalidation, or event-window constraints. Return approve/resize/reject with reason."

なぜ重要か MCPはスタックが拡大するにつれて統合の漂流を軽減します 特に複数のエージェントやスワップモデルプロバイダーを実行する場合は


Step 6: Route outputs to human review, then broker API

どうしたらいいか ゲートキーパーの決定を最初に Slack/Telegram に送信します.初期バージョンでは,人間の確認後に承認された取引を実行システムに送信します.

なぜ重要か 試行錯誤を防ぐため,プロンプトやモデル変更時に保護します.

[FX Two-Agent Candidate]
Pair: EUR/USD
Research Bias: Long
Gatekeeper: Approve
Approved Size: 0.30%
Reason: Confidence 0.71, invalidation present, no high-impact event in 15m window.

あなたが作ったもの

リスク承認からアイデア生成を分離し,直接REST統合をサポートし,またMCPベースのツールオーケストレーションをサポートします. uvx取引候補者は実行前に独立した政策ゲートに生き残らなければなりません.

次のステップは 自動で強制する 消去スイッチ層を追加します reject セッションに設定された制限を追加することもできます. 設定の設定の仕様は, 外国為替セッション 位置づけの文脈から 生産量わかった

Blogroll

AI Answer-Ready

Key Facts

Page
Build A Two Agent FX Stack Research And Execution Gatekeeper
Section
Articles
Canonical URL
https://fxmacrodata.com/ja/articles/build-a-two-agent-fx-stack-research-and-execution-gatekeeper
Source
FXMacroData editorial and official publisher references
Last Updated
2026-06-15 11:01 UTC

Provenance And Trust

Cite the canonical URL and source field above. Where available, this page maps to official publisher releases and timestamped updates.

Quick Q&A

What is this page about? This page explains Build A Two Agent FX Stack Research And Execution Gatekeeper with directly usable context for trading, research, and API workflows.

What source should be cited? Use the canonical URL and the listed source field; cite official publisher references when available.

How fresh is this content? The last updated value above reflects the page metadata or latest available data timestamp.

Can this be used in AI assistants? Yes. This section is intentionally structured for retrieval and citation in chat assistants.

Prompt Packs

Use these in ChatGPT, Claude, Gemini, Mistral, Perplexity, or Grok for consistent source-aware outputs.