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

设计一个更安全的AIFX工作流程, 将分析与执行批准分开: 一个代理研究宏观设置,第二个守门员执行风险规则,并在交易到达您的经纪人之前阻止不安全的交易.

其他语言版本 English
Share article X LinkedIn Email

建立一个由两个代理人组成的外汇团队:研究人员+执行门卫

编者: 汇率数据组
发表时间: May 21, 2026

单一代理的外汇机器人失败的原因很简单:同一个产生想法的模型也可以批准它们. 美国非农业工资只有一个推理错误就会直接导致风险.

本指南展示了一个更安全的架构:在两个代理人之间分担责任.第一个代理人进行市场研究并提出设置.第二个代理人是一个严格的守门员,只能根据严格风险规则批准,改变尺寸或拒绝建议.

您将在工作的最后获得一个实用的两名代理工作流程. 欧元/美元 现在我 汇率汇率 支持直接的REST API集成和基于MCP的工具集成.

目标: 通过在任何经纪人行动之前强制执行强制批准层,从"人工智能交易想法"转变为"风险验证的人工智能的交易候选人".

预先要求

  • 在Python3.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:在门卫代理人中执行严格风险规则

如何做: 通过第二个模型或第一规则验证器,

举例政策:

  • 交易每次最大风险: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")

为什么这很重要: 即使研究人员读错了, 守门员仍然可以阻止超大或弱的设置.


Step 5: Add MCP integration path (tool-native agent workflow)

如何做: 通过MCP暴露FXMacroData,以便代理框架可以本地调用工具,而不是为每个机器人构建自定义的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.

你所建立的

现在有一个由两个代理组成的FX架构,将创意生成与风险审批分开,支持直接REST集成,并支持通过 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/zh/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.