Claude Agent SDK + Ertas
使用 Claude Agent SDK 建構代理——Anthropic 官方框架,具備 computer-use、程式碼執行與檔案系統原語,可設定為透過 OpenAI 相容轉接器對 Ertas 訓練本地模型運行。
Overview
Claude Agent SDK 是 Anthropic 官方框架,用於建構能在電腦環境中採取行動的代理。它暴露一小組高階原語——computer-use(滑鼠、鍵盤、螢幕截圖)、程式碼執行(Python sandbox)、檔案系統存取與網頁搜尋——這些一起實作 Anthropic「給代理一台電腦」的設計哲學。SDK 不是讓代理從低階工具呼叫組合動作,而是提供常見環境的正式上線等級實作,讓模型在更高的層級進行推理。2026 年 5 月 8 日的發布在 `PreToolUse` hook 中加入了 `defer` 權限決策(這樣 hook 可以延後呼叫直到取得額外脈絡)、`strict` MCP 設定選項、用於即時轉錄追蹤的批次與及早 `session_store_flush` 模式,以及新的 `xhigh` 努力等級——這些操作原語顯著改善正式上線可觀測性與安全審查工作流程。
SDK 最常與 Claude 本身一同使用,但其設計在編排層上是模型無關的。代理迴圈、行動執行器與安全原語全都位於模型 API 之上,這意味著任何支援工具呼叫與函式輸出的模型都可以接入。對於想要 SDK 環境原語但不想被鎖定在 Claude API 經濟模型的團隊,框架可以設定為呼叫提供 Ertas 訓練模型的 OpenAI 相容端點——獲得 computer-use、程式碼執行與檔案系統行動的同時控制推論成本。
Claude Agent SDK 在 2026 年因其環境原語而快速被採用。大多數代理框架讓使用者自行實作 computer-use、sandbox 程式碼執行與檔案系統工具——這些工作非平凡,且常常是生產環境 bug 與安全漏洞的源頭。SDK 開箱即用提供這些經實戰測試的實作。
How Ertas Integrates
Ertas 訓練的模型透過 Claude Agent SDK 的模型 provider 設定層協同運作。在 Ertas Studio 微調模型並部署到 OpenAI 相容端點後,你設定 SDK 將你的端點作為模型 provider。SDK 的環境原語——computer-use、程式碼執行、檔案系統存取——無論由哪個模型產生行動都透明地運作。
對於需要對電腦環境推理的代理工作流程,微調異常地有價值。通用的 7B–14B 模型在獲得一台電腦時常產生笨拙或不安全的動作序列;而 Ertas 訓練模型——其訓練資料包含來自目標領域的代表性 computer-use 軌跡(例如,貴公司的內部 CRM、Salesforce 實例、自訂管理工具)——產生顯著更可靠的動作序列。SDK 處理 執行;Studio 處理專業化。
這種組合對於受監管產業部署特別具吸引力。Claude Agent SDK 加上在本地端執行的 Ertas 訓練模型,讓組織能取得 SDK 的環境原語而無需傳送資料或行動到 Anthropic API。曾考慮過 Claude 用於代理工作流程但因資料主權限制而無法部署的醫療、法律與金融服務團隊,可使用此組合在自有基礎設施上部署。
Getting Started
- 1
在 Ertas Studio 微調領域特定模型
在來自目標環境的 computer-use、工具呼叫與程式碼執行軌跡上訓練。Studio 的訓練資料格式支援 Agent SDK 使用的結構化動作-觀察配對。
- 2
部署到 OpenAI 相容端點
匯出為 GGUF 並透過 Ollama、vLLM 或 Ertas Cloud 提供服務。SDK 呼叫任何暴露具工具呼叫的標準 chat-completion API 的端點。
- 3
安裝 Claude Agent SDK 並設定 provider
安裝 claude-agent-sdk 並將其模型 provider 設定為指向你的 Ertas 推論端點。SDK 的轉接層透明地處理 API 轉譯。
- 4
設定環境原語
依需要啟用 SDK 的 computer-use、程式碼執行與檔案系統原語。每一個都在自己的 sandbox 中運行,並暴露模型可呼叫的結構化動作 API。
- 5
以安全與追蹤執行代理迴圈
使用 SDK 內建的代理迴圈。安全檢查、行動權限與追蹤無論底層模型為何都透明地運作。使用追蹤資料回饋至 Studio 進行漸進式改進。
from claude_agent_sdk import Agent, ComputerUseTool, FileSystemTool
from claude_agent_sdk.providers import OpenAICompatibleProvider
# Configure the SDK to use your Ertas-trained model
provider = OpenAICompatibleProvider(
base_url="http://localhost:11434/v1",
api_key="not-needed",
model="ertas-internal-ops-14b",
)
agent = Agent(
provider=provider,
tools=[
ComputerUseTool(sandbox="docker:secure-desktop"),
FileSystemTool(root="/data/internal-ops"),
],
instructions="You operate the internal-ops console — schedule reports, run queries, file tickets.",
)
# Run an action sequence — the SDK handles screenshots, action permissions, and tracing
result = agent.run(
"Run the weekly revenue report and file a ticket for any rows where revenue dropped >20% week-over-week."
)
print(result.summary)Benefits
- 正式上線等級的環境原語——computer-use、程式碼執行、檔案系統、網頁搜尋
- 模型無關的編排層可與 Claude 或任何相容替代品協同運作
- 內建安全原語——行動權限、sandbox、稽核軌跡
- 與 Ertas 微調搭配可實現領域特定的 computer-use 專業化
- 為受監管產業提供本地端部署故事——無雲端外傳
- 內建正式上線追蹤與可觀測性
Related Resources
Fine-Tuning
Function Calling
Structured Output
Fine-Tuning for Tool Calling: How to Build Reliable AI Agents with Small Models
Agentic AI On-Premise: Enterprise Deployment Without Cloud Dependency
Building Reliable AI Agents with Fine-Tuned Local Models: Complete Guide
LangGraph
Ollama
OpenAI Agents SDK
Pydantic AI
vLLM
Ertas for SaaS Product Teams
Ertas for AI Automation Agencies
Ertas for Internal Knowledge Bases
Ship AI that runs on your users' devices.
Early bird pricing starts at $14.50/mo — locked in for life. Plans for builders and agencies.