mcpField
I
IdentArk Gateway

IdentArk Gateway

远程服务
identark.io安全161 天前更新

关于 IdentArk Gateway

IdentArk Gateway 是用于通过网关接口构建 Agent 的 SDK,提供本地实现和 IdentArk 控制平面实现。它面向希望避免 Agent 进程持有凭据,并通过授权、预算和人工审批管理操作的团队。

主要功能

  1. 01将 Agent 逻辑与网关实现分离
  2. 02将生产凭据保存在控制平面
  3. 03在 Agent 之外保存对话历史
  4. 04跟踪 LLM 调用和会话成本
  5. 05提供用于测试的 MockGateway
  6. 06DirectGateway 支持 OpenAI 和 Anthropic

适用场景

  1. 01将 Agent 从本地开发迁移到控制平面运行
  2. 02通过审批请求受管控的支付操作
  3. 03无需调用 LLM 即可测试 Agent 行为

配置

远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。

服务地址https://api.identark.io/v1/mcp/rpc
一键复制安装命令
Claude CodeTerminal
Cursor.cursor/mcp.json
VS Code.vscode/mcp.json
Claude Desktopclaude_desktop_config.json
Windsurf~/.codeium/windsurf/mcp_config.json

命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。

全部服务地址
Streamable HTTPhttps://api.identark.io/v1/mcp/rpc需要授权

工具

详细介绍

IdentArk

identark

AgentGateway 协议——安全、可扩展的 AI Agent 执行基础设施。

CI PyPI Python License: MIT


问题

AI Agent 能够执行代码、调用 API 或访问文件时,就会在进程中运行。该进程拥有一个运行环境,其中通常包含可能造成严重损害的一切信息:大模型 API 密钥、数据库凭据、AWS 令牌。

最简单的解决方案——让 Agent 与 REST API 在同一个后端运行——会同时引发两个问题:

  1. 安全性:Agent 可以访问机器上的所有机密信息。
  2. 可靠性:耗费大量内存的 Agent 会拖慢 API。重新部署 API 会终止所有正在运行的 Agent。

identark 可以同时解决这两个问题。


工作原理

该 SDK 实现了 AgentGateway 协议——在 Agent 逻辑与外部世界之间提供简洁的接口。开箱即用地提供两种实现:

网关适用场景凭据历史记录
DirectGateway本地开发、CI 评估你的 API 密钥内存中
ControlPlaneGateway在 IdentArk 上用于生产环境零——Agent 中没有凭据控制平面数据库

在这两种环境中,你的 Agent 代码完全相同。只需更改两行代码即可切换。


快速开始

pip install identark[openai]
import asyncio
from openai import AsyncOpenAI
from identark import DirectGateway, Message, Role

async def main():
    gateway = DirectGateway(
        llm_client=AsyncOpenAI(),   # Your API key — not in the agent loop
        model="gpt-4o",
    )

    response = await gateway.invoke_llm(
        new_messages=[Message(role=Role.USER, content="Hello, IdentArk!")]
    )

    print(response.message.content)
    print(f"Cost: ${response.cost_usd:.6f}")

asyncio.run(main())
切换到生产环境

更改两行代码即可。无需改动 Agent 逻辑。

# Before (local)
from identark import DirectGateway
gateway = DirectGateway(llm_client=AsyncOpenAI(), model="gpt-4o")

# After (production — agent holds zero secrets)
from identark import ControlPlaneGateway
gateway = ControlPlaneGateway()  # auto-detects env vars inside a IdentArk sandbox
受管控的操作(付款、付款链接、退款)

Agent 请求控制平面执行操作;服务提供商密钥(Stripe、Paystack、 GitHub 或 AWS)保留在 IdentArk 中。执行任何操作前都会应用授权、预算和人工审批, 且重复使用的幂等键不会导致操作执行两次。

request = await gateway.request_capability(
    "payments.payment_link.create",
    "paystack",
    {"amount_minor": 1_500_000, "currency": "NGN",
     "customer_email": "[email protected]", "reference": "order-1001"},
    idempotency_key="order-1001-link",
)
# "succeeded" returns the checkout link; "pending_approval" waits for a person.
execution = await gateway.get_capability_execution(request["request_id"])

安装

# Core SDK only
pip install identark

# With OpenAI support
pip install identark[openai]

# With Anthropic support
pip install identark[anthropic]

# With Google Gemini support
pip install identark[gemini]

# With Mistral AI support (EU provider)
pip install identark[mistral]

# All cloud providers
pip install identark[all]

要求: Python 3.10+

使用 TypeScript?同等功能的 SDK 以零运行时依赖的形式提供, 即 identark npm package,并具备相同的 AgentGateway 契约和结构化凭据会话。


数据主权

IdentArk 从设计之初就支持任何大模型提供商,包括那些 会将数据保留在英国或欧盟境内的提供商。AgentGateway 协议将 Agent 逻辑与 推理提供商解耦——切换提供商只需更改一行代码。

使用 Ollama 完全本地运行(数据零外传)
from openai import AsyncOpenAI
from identark import DirectGateway

gateway = DirectGateway(
    llm_client=AsyncOpenAI(
        base_url="http://localhost:11434/v1",
        api_key="ollama",
    ),
    model="llama3.2",
    provider="local",   # forces $0 cost tracking; inference stays on your machine
)

安装 Ollama:brew install ollama && ollama pull llama3.2 && ollama serve

使用 Mistral AI(欧盟数据驻留)
from openai import AsyncOpenAI
from identark import DirectGateway

gateway = DirectGateway(
    llm_client=AsyncOpenAI(
        base_url="https://api.mistral.ai/v1",
        api_key="your-mistral-api-key",
    ),
    model="mistral-small-latest",   # auto-detected as "mistral" provider
)

Mistral AI 是一家法国公司。所有推理都在欧盟数据中心运行,并受欧盟数据 保护法(GDPR)约束。如果英国或欧盟的数据治理要求禁止将推理流量发送到 美国云服务提供商,请使用此方案。

完整的可运行脚本请参阅 examples/。


AgentGateway 协议

任何实现以下四个异步方法的类都是有效的网关:

class AgentGateway(Protocol):
    async def invoke_llm(self, new_messages, tools=None, tool_choice="auto") -> LLMResponse: ...
    async def persist_messages(self, messages) -> None: ...
    async def request_file_url(self, file_path, method="PUT") -> PresignedURL: ...
    async def get_session_cost(self) -> float: ...

让 Agent 基于该协议编写。具体实现——本地或生产环境——属于运行时细节。


功能

  • 无需密钥的 Agent — ControlPlaneGateway 不持有 API 密钥、数据库凭据或云令牌
  • 为无状态而设计 — 对话历史由网关持有,而非 Agent;终止并重启也不会丢失数据
  • 与框架无关 — 适用于 LangChain、LlamaIndex、原始 API 调用或任何自定义 Agent 框架
  • 内置成本跟踪 — 每次 invoke_llm 调用都会返回 cost_usd;get_session_cost() 会返回累计总额
  • 支持 OpenAI + Anthropic — DirectGateway 开箱即支持这两家服务商
  • 用于测试的 MockGateway — 测试套件中无需调用大模型;可完整记录调用以供断言
  • 完整类型注解 — 带有 py.typed 标记;支持 mypy 严格模式

测试你的 Agent

from identark.testing import MockGateway
from identark.models import LLMResponse, Message, Role

async def test_my_agent():
    mock = MockGateway()
    mock.queue_response(LLMResponse(
        message=Message(role=Role.ASSISTANT, content="The answer is 42."),
        cost_usd=0.001,
        model="mock",
        finish_reason="stop",
    ))

    result = await my_agent(gateway=mock)

    assert mock.invoke_llm_call_count == 1
    assert mock.total_messages_sent == 1

支持的服务商

服务商数据驻留地DirectGatewayGeminiGatewayControlPlaneGateway
OpenAI(gpt-4o、gpt-4o-mini 等)美国✓—✓
Anthropic(Claude 模型)美国✓—✓
Google Gemini不定✓*✓规划中
Mistral AI不定✓—✓
Kimi / Moonshot不定✓*—✓
Azure OpenAI配置的 Azure 区域✓*—✓
AWS Bedrock配置的 AWS 区域——✓
OpenRouter取决于服务商✓*—✓
Ollama本地 🏠✓—非托管路由
任何兼容 OpenAI 的端点不定✓—✓(自定义端点)

*通过兼容 OpenAI 的客户端/基础 URL 使用。要使用 Gemini 原生 SDK 功能,请使用 GeminiGateway。


错误处理

from identark.exceptions import CostCapExceededError, RateLimitError, IdentArkError

try:
    response = await gateway.invoke_llm(new_messages=[...])
except CostCapExceededError as e:
    print(f"Cost cap of ${e.cap_usd} reached. Spent: ${e.consumed_usd}")
except RateLimitError as e:
    await asyncio.sleep(e.retry_after_seconds)
except IdentArkError as e:
    # Catch-all for any SDK error
    raise

完整异常层级:IdentArkError > GatewayError > ControlPlaneError > AuthenticationError | CostCapExceededError | SessionNotFoundError


架构

┌─────────────────────────────────────┐
│            Your Agent Code          │
│   (depends only on AgentGateway)    │
└──────────────┬──────────────────────┘
               │
    ┌──────────▼──────────┐
    │    AgentGateway      │  ← Protocol (interface)
    │      Protocol        │
    └──────┬────────┬──────┘
           │        │
  ┌────────▼─┐  ┌───▼──────────────┐
  │  Direct  │  │  ControlPlane    │
  │ Gateway  │  │    Gateway       │
  │          │  │                  │
  │ Local /  │  │   Production     │
  │  Evals   │  │  (zero secrets)  │
  └──────────┘  └────────┬─────────┘
                         │ HTTP
                ┌────────▼─────────┐
                │  IdentArk        │
                │  Control Plane   │
                │  (holds creds)   │
                └──────────────────┘

社区


参与贡献

欢迎贡献。提交重大更改前,请先创建 Issue。

git clone https://github.com/identark/identark.git
cd identark
pip install -e ".[dev]"
pre-commit install
pytest tests/unit/

完整指南请参阅 CONTRIBUTING.md。


路线图

  • LangChain 适配器(IdentArkChatModel)
  • LlamaIndex 适配器(IdentArkLLM)
  • 流式支持(invoke_llm_stream)
  • CrewAI 集成
  • LangGraph 集成(IdentArkNode、IdentArkStreamNode)
  • 可插拔推理后端(分布式计算)
  • 用于一键部署控制平面的 identark-cli

许可证

IdentArk SDK 采用 MIT 许可证 — 可免费用于任何用途,包括商业项目和闭源项目。请参阅 LICENSE。

IdentArk 控制平面(托管服务)为专有软件。SDK 可与任何 AgentGateway 后端配合使用,包括完全可自托管的后端。


基于 How We Built Secure, Scalable Agent Sandbox Infrastructure 中介绍的控制平面模式构建。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。