v0.10.5

決策型別

最後更新


決策的請求與結果型別、共用的請求組裝與回應解析函式,以及各供應商呼叫的端點。

介面


  1. type DecisionAgent interface {
  2. Decide(ctx context.Context, state any, questions map[string]DecisionQuestion) (*DecisionResult, error)
  3. }

由 *typesafe.Agent 與 *openrouter.Agent 實作。

題目


  1. type DecisionType string
  2. const (
  3. DecisionNoul DecisionType = "noul"
  4. DecisionChoice DecisionType = "choice"
  5. DecisionScore DecisionType = "score"
  6. )
  7. type DecisionQuestion struct {
  8. Type DecisionType
  9. Instructions any
  10. Criteria any
  11. }

結果


  1. type DecisionAnswer struct {
  2. Type DecisionType
  3. Noul float64
  4. Choice string
  5. Score float64
  6. Confidence *float64
  7. Probabilities map[string]float64
  8. Legend map[string]any
  9. }
  10. type DecisionResult struct {
  11. Model string
  12. Answers map[string]DecisionAnswer
  13. Usage Usage
  14. }

欄位適用題型Wire 欄位
Noulnoulanswers.<name>.noul
Choicechoiceanswers.<name>.choice
Scorescoreanswers.<name>.score
Confidencechoice、scoreanswers.<name>.confidence
Probabilitieschoice(依選項)、score(依等級索引)answers.<name>.probabilities
Legendscoreanswers.<name>.legend
Usage.Input/Usage.Output全部usage.input_tokens/usage.output_tokens
Usage.CacheRead僅 openrouterusage.input_tokens_details.cached_tokens

共用函式


兩個 adapter 以 core 內同一組函式組裝請求與解析回應。
符號簽章說明
DecisionBodyfunc(model string, state any, questions map[string]DecisionQuestion) (map[string]any, error)驗證後回傳 {model, state, questions};值為 nil 的 Instructions/Criteria 不送出。model 為空、state 為 nil、questions 為空或 Type 不合法時回傳 [Invalid] decision...
DecisionResponsestruct兩個上游回應共用的 wire 格式:model、answers、usage
(DecisionResponse).Resultfunc(label string) (*DecisionResult, error)轉成 DecisionResult;answers 為空時回傳 [Upstream] <label>: response has no answers
HTTPErrorLabelfunc(code int, err error) stringHTTP 失敗對應的錯誤標示,見下節

HTTPErrorLabel


adapter 在每個上游錯誤前加上這個標示,呼叫端可依類別分流處理。
條件標示
err 包含 context.CanceledCanceled
err 包含 context.DeadlineExceededTimeout
code == 0(沒有回應)Unavailable
400、415、422Invalid
401、403Denied
402、413Limit
404Not found
409Conflict
408、504、524Timeout
429、503、529Unavailable
其他,包含 200 但回應無法解析Upstream

各供應商端點


供應商套件端點Header
typesafecore/typesafePOST https://api.typesafe.ai/v1/systemoneAuthorization: Bearer <APIKey>
openroutercore/openRouterPOST https://openrouter.ai/api/alpha/decisions與 OpenRouter 對話相同的 header

core/typesafe


符號簽章說明
Agentstruct只做決策的 agent;沒有 Send,不是 llmrouter.Agent
Newfunc(config llmrouter.Config) (*Agent, error)使用 Model 與 APIKey;APIKey 為空時回傳 [Denied] typesafe.New: APIKey is required
(*Agent).Namefunc() stringtypesafe@<model>
(*Agent).DecideDecisionAgent呼叫 /v1/systemone
Modelsfunc(ctx context.Context, config llmrouter.Config) ([]string, error)GET /v1/models 的模型名稱,逾時 15 秒;不接受 ModelFilter

相關頁面


EN