Liking cljdoc? Tell your friends :D

im.ttalk.agent.approval.model

模型审阅者(designs/runtime-borrow.md §7;借 Keelson Advisors/ModelApprover.cs, 它又借 Codex guardian-reviewer)。

把工具名、策略理由、参数与最近的对话(都有 token 预算)交给一个(通常更小的) 模型,要它回严格 JSON:

{"risk_level":"low|medium|high|critical",
 "user_authorization":"unknown|low|medium|high",
 "outcome":"allow|deny", "rationale":"..."}

outcome = allow → 批,deny → 拒(rationale 作理由回给主模型)。失败即拒:超时、 模型抛错、回的不是合格 JSON → 拒;:abstain-on-failure? true 时改为不表态(nil), 交给审批链的下一环(典型:审阅不了再问人)。

产出的是 im.ttalk.agent.approval 的审批者,放进 chain-approver / approval-filter :approver 即可。core 零依赖,故自带一个最小 JSON 读取器。

模型审阅者(designs/runtime-borrow.md §7;借 Keelson `Advisors/ModelApprover.cs`,
它又借 Codex guardian-reviewer)。

把工具名、策略理由、参数与最近的对话(**都有 token 预算**)交给一个(通常更小的)
模型,要它回严格 JSON:

    {"risk_level":"low|medium|high|critical",
     "user_authorization":"unknown|low|medium|high",
     "outcome":"allow|deny", "rationale":"..."}

`outcome` = allow → 批,deny → 拒(rationale 作理由回给主模型)。**失败即拒**:超时、
模型抛错、回的不是合格 JSON → 拒;`:abstain-on-failure? true` 时改为不表态(nil),
交给审批链的下一环(典型:审阅不了再问人)。

产出的是 `im.ttalk.agent.approval` 的**审批者**,放进 `chain-approver` /
`approval-filter :approver` 即可。core 零依赖,故自带一个最小 JSON 读取器。
raw docstring

default-instructionsclj

source

model-approverclj

(model-approver chat-model
                &
                {:keys [history-fn timeout-ms instructions options
                        abstain-on-failure?]
                 :or {timeout-ms 90000}
                 :as opts})

模型审阅者 → 审批者 (fn [req] -> {:approved? :reason :risk-level :user-authorization} | nil)。

opts:

  • :history-fn (fn [req] -> 中立消息):对话证据(如按 conversation-id 读 ChatMemory)
  • :timeout-ms 一次审阅最多等多久(缺省 90000);到点 → 失败
  • :transcript-tokens 对话证据总预算(6000);:message-tokens 单条上限(900)
  • :args-tokens 参数上限(2000);:reason-tokens 理由上限(512)
  • :instructions 换掉缺省审阅提示(输出契约必须仍是那段 JSON)
  • :options 额外调用选项(模型名 / 温度 …)
  • :abstain-on-failure? 失败时不表态(nil)而不是拒(缺省 false)
模型审阅者 → 审批者 `(fn [req] -> {:approved? :reason :risk-level :user-authorization} | nil)`。

opts:
- :history-fn         (fn [req] -> 中立消息):对话证据(如按 conversation-id 读 ChatMemory)
- :timeout-ms         一次审阅最多等多久(缺省 90000);到点 → 失败
- :transcript-tokens  对话证据总预算(6000);:message-tokens 单条上限(900)
- :args-tokens        参数上限(2000);:reason-tokens 理由上限(512)
- :instructions       换掉缺省审阅提示(输出契约必须仍是那段 JSON)
- :options            额外调用选项(模型名 / 温度 …)
- :abstain-on-failure? 失败时不表态(nil)而不是拒(缺省 false)
sourceraw docstring

parse-assessmentclj

(parse-assessment text)

解析审阅结论:先整段按 JSON 读;不行再取第一个 { 到最后一个 }(模型在外面包了散文)。 outcome 必须是 allow / deny;缺 risk_level → allow 记 low、deny 记 high;缺 user_authorization → unknown;给了却不在枚举里 → nil(⇒ 失败)。

解析审阅结论:先整段按 JSON 读;不行再取第一个 `{` 到最后一个 `}`(模型在外面包了散文)。
`outcome` 必须是 allow / deny;缺 risk_level → allow 记 low、deny 记 high;缺
user_authorization → unknown;给了却不在枚举里 → nil(⇒ 失败)。
sourceraw docstring

read-jsonclj

(read-json s)

读一段 JSON 文本(键保持字符串)。非法抛 ex-info。

读一段 JSON 文本(键保持字符串)。非法抛 ex-info。
sourceraw docstring

review-messagesclj

(review-messages req
                 {:keys [transcript-tokens message-tokens args-tokens
                         reason-tokens history]})

审阅请求:一条用户消息(工具、理由、参数、最近对话;都有预算)。

审阅请求:一条用户消息(工具、理由、参数、最近对话;都有预算)。
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close