TypeSafe AI

Alpha 版 TypeSafe AI 整合功能可讓包括 Jev 在內的 System One 模型適配 Agent Framework Python 版。 這些模型會根據打字問題評估應用狀態,並回傳機率與分數。 它們不會產生一般的自由形式聊天回應。

安裝套件

pip install agent-framework-typesafe --pre

設定

在建立客戶端前先設定 API 金鑰:

TYPESAFE_API_KEY="<api-key>"
# Optional:
TYPESAFE_DEFAULT_MODEL="jev-latest"
TYPESAFE_BASE_URL="<api-root>"

建構值優先於環境變數。 你也可以注入已設定好的 TypeSafe AsyncTypeSafeClient。 注入的用戶端仍由呼叫端擁有;請使用 close() 或非同步內容管理器來關閉由 TypeSafeChatClient 建立的用戶端。

建立一個型別決策代理

透過 Agent Framework response_format選項傳遞 TypeSafe Questions對應:

import asyncio

from agent_framework import Agent
from agent_framework_typesafe import TypeSafeChatClient
from typesafe_sdk import Choice, Noul


async def main() -> None:
    client = TypeSafeChatClient()
    try:
        agent = Agent(
            client=client,
            name="TicketEvaluator",
            instructions="Evaluate the support request.",
        )
        response = await agent.run(
            "Our checkout has failed for three days and we are losing sales.",
            options={
                "response_format": {
                    "department": Choice(
                        instructions="Which team should handle this request?",
                        criteria={
                            "billing": None,
                            "technical": None,
                            "sales": None,
                        },
                    ),
                    "urgent": Noul(
                        instructions="Does this request need urgent attention?"
                    ),
                },
            },
        )
        print(response.value)
    finally:
        await client.close()


asyncio.run(main())

對於這個連接器,response_format 是一個非空的 TypeSafe Questions 映射,包含 Noul、Choice 或 Score 問題。 您可以透過response.value存取完整輸入的SystemOneResponse。

當整合只有一個固定合約時,請在客戶端使用 default_questions。 例如,帶有預設問題的 TypeSafe 用戶端可作為 的 SecureAgentConfig隔離用戶端。

功能與 MCP 工具

TypeSafeChatClient 支援封閉式結構的標準代理框架函式調用迴圈。 支持的論元形式包括:

  • 固定不變的常數。
  • 枚舉或 Python Literal 值。
  • 布林值。
  • 由列舉或 Literal 值組成的陣列,不含額外的陣列限制。
  • 這些形狀的可選版本。

客戶端不支援必須的自由形式字串或數字、巢狀物件、一般陣列、必須的可空參數,或連接器無法保留的結構約束。 如果你指定了無支持的論點,客戶端會自動排除整個工具,或在你需要時拒絕該工具。

MCP 工具是透過 Agent 運作,Agent 會探索 MCP 函式,並在 TypeSafe 路由之前將其展開為函式工具。 只有結構符合支援子集的函式才可路由。 請求最多支援 32 個可路由工具、每個工具 64 個屬性、每個參數 64 個枚舉成員,以及 128 個產生的內部問題。

客戶端預設每次執行只呼叫一次工具。 設定 function_invocation_configuration={"max_function_calls": N} 以允許工具進行連續往返呼叫。

功能與限制

能力 Support
型別化分類、評分與路由 TypeSafe Questions 與 SystemOneResponse
代理框架中介軟體與遙測 Supported
本機函式工具 支援受限的結構描述子集
MCP 功能 支援受限的結構描述子集
Streaming 不支援
自由形式文字生成 不支援
非簡訊內容 不支援
例如 temperature 等生成式選項 已拒絕

將 TypeSafeChatClient 用於標準框架層。 只有在你有意想組合自訂層堆疊或選擇退出函式執行、中介軟體和遙測時才使用 RawTypeSafeChatClient 。

下一步