contract

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package contract 是 einox 对应用层暴露的最小契约面:工具/事件/审批/ 挂起/上下文注入协议(event.go/tool.go/hitl.go/suspend.go)+ 会话域载荷 (session.go:UserPrefs/Attachment/Participant/QueuedMsg)+ 横切常量与 小函数(错误码封闭词表、effort 归一、参数错误翻译)。零 eino 类型—— 业务系统只见本包与基座各机制包的公开面,换地基只动基座内部 (2026-08-24 agent 基座定案 §2:从现状提炼,不发明)。

Index

Constants

View Source
const (
	EvTextDelta         = "text_delta"
	EvThinkingDelta     = "thinking_delta"
	EvToolCall          = "tool_call"
	EvToolResult        = "tool_result"
	EvApprovalRequest   = "approval_request"
	EvApprovalDecision  = "approval_decision"
	EvApprovalTimeout   = "approval_timeout"
	EvAskRequest        = "ask_user_request"
	EvAskDecision       = "ask_decision"
	EvAskTimeout        = "ask_timeout"
	EvAskIgnored        = "ask_ignored"
	EvPlanRequest       = "plan_request"
	EvPlanDecision      = "plan_decision"
	EvPlanTimeout       = "plan_timeout"
	EvTodoUpdate        = "todo_update"
	EvSteerQueued       = "steer_queued"
	EvSteerUpdated      = "steer_updated"
	EvSteerRemoved      = "steer_removed"
	EvSteerInjected     = "steer_injected"
	EvSteerReordered    = "steer_reordered"
	EvNotifyQueued      = "notify_queued"
	EvNotifyInjected    = "notify_injected"
	EvUserMessage       = "user_message"
	EvParticipantUpdate = "participant_update"
	EvUsage             = "usage"
	EvSessionEnd        = "session_end"
	EvError             = "error"
	EvInterrupted       = "interrupted"
	EvHarnessNote       = "harness_note"
	EvSubAgent          = "subagent"
	EvModelChange       = "model_change"
	EvTransportRetry    = "transport_retry"
)

事件族(名称常量):事件流是会话记录与前端渲染的真源——text_delta / thinking_delta / tool_call / tool_result / approval_request / approval_decision / approval_timeout / ask_user_request / ask_decision / ask_timeout / ask_ignored / plan_request / plan_decision / plan_timeout / todo_update / steer_queued / steer_updated / steer_removed / steer_injected / steer_reordered / notify_queued / notify_injected / user_message / participant_update / usage / session_end / error / interrupted / harness_note / subagent / model_change / transport_retry。 传输无关:应用层订阅 Session 事件后映射到自己的管线(SSE 编码归应用)。

View Source
const (
	ErrCodeConfig    = "CONFIG"     // 装配/配置类(未配模型、键不在清单、构造失败)
	ErrCodeServer    = "SERVER"     // 服务端/未知类(含轮次预算耗尽——可发消息接续)
	ErrCodeTransport = "TRANSPORT"  // 网络传输类(可重试)
	ErrCodeAborted   = "ABORTED"    // 取消/中断(非故障)
	ErrCodeAuth      = "AUTH"       // 认证失败(网络容错 ③ 分类器)
	ErrCodeRateLimit = "RATE_LIMIT" // 限速重试耗尽(网络容错 ③ 分类器)
	ErrCodeOverflow  = "OVERFLOW"   // 上下文超窗(manager 裁剪重装配有界重试一次后才如实报错)
)

错误码封闭词表(ErrorOut.Code 的唯一常量源——llm.Classify 归约、engine/ session 发卡、前端按 code 分支渲染全部经此引用;此前权威只在注释、字面量 散落 llm/engine 各写一份,typo 即静默漂移且无编译期对账,审查 P2-10)。

View Source
const (
	ModeManual = "manual" // 写工具逐次审批
	ModePlan   = "plan"   // 计划模式:submit_plan 出计划文档供审,批准授权任务期全部写(taskGrant)
	ModeAuto   = "auto"   // 裸传直落(硬红线仍在工具实现内代码级拒绝)
)

会话模式三档(应用可自定义集合;这三档是审批矩阵的既有语义)。

View Source
const (
	StateRunning         = "running"
	StatePendingApproval = "pending_approval"
	StateEnded           = "ended"
	StateError           = "error"
)

会话状态常量(会话域状态机公开值)。

View Source
const (
	BehaviorRead  = "read"  // 探索组:读文件/列表/搜索/取网页
	BehaviorWrite = "write" // 更改组:写文件/改数据/落文档
	BehaviorExec  = "exec"  // 终端组:跑命令/跑脚本(非只读进程执行)
)

行为面标记值(ToolInfo.Behavior;工具注册期自declare——内容归业务)。

Variables

This section is empty.

Functions

func ImageInputOf

func ImageInputOf(ctx context.Context) bool

ImageInputOf 读取图片输入能力(false = 未声明或不支持)。

func ModelArgError added in v0.5.0

func ModelArgError(err error, owner ...reflect.Type) error

ModelArgError 把工具参数反序列化错误翻译为面向模型的可行动文案(六层 防御层 3′:错误必达模型由 mid.ErrFeed 承担,但 encoding/json 默认文本 含结构体名/偏移量等开发者视角信息,对模型是噪声——2026-08-27 盘点定案 的基座缺口)。说清三件事:哪个参数、实得什么、应为什么。非参数类错误 原样返回(业务自定义 UnmarshalJSON 的友好文案不被改写)。2026-09-06 自 tools/infer.go 迁入契约面(审查 P3-3:错误也是契约——einoext 桥与工具 构造器(InferTool)共用;errors.As 穿透上游 %w 包装链);owner 可选 传入参数结构体类型,用于核对可选性(encoding/json 报错的 Type 已解引用 指针,元素类型无法自判可选)。

func NormalizeEffort added in v0.5.0

func NormalizeEffort(effort string) string

NormalizeEffort 思考档归一:off | low | high | max(2026-08-31 关档回归 四档——机制层能力,模型是否真支持关由端点定)。旧值兼容——升级前用户 偏好与存量会话快照存的是 on/off(旧「开」即 enabled+effort max):on/ max → max,off → off(关档回归后恢复本义),其余(""/未知)→ 默认 low。 全链路唯一权威:四档外的值任何一环都不外流。

func OperatorOf

func OperatorOf(ctx context.Context) string

OperatorOf 读取操作者(空 = 无审计主体上下文)。

func ResumeStateOf

func ResumeStateOf(ctx context.Context) (state any, ok bool)

ResumeStateOf 读取恢复态(挂起重放时工具消费;ok = 本次调用是恢复流)。

func WithChangeRecorder

func WithChangeRecorder(ctx context.Context, rec ChangeRecorder) context.Context

WithChangeRecorder 注入变更记录器(业务工具写文件时报备)。

func WithImageInput

func WithImageInput(ctx context.Context, ok bool) context.Context

WithImageInput 注入会话模型的图片输入能力(引擎按模型声明写入;读图工具 经 ImageInputOf 消费——当前路由明示能力才放行,对齐官方 harness 的路由 能力断言)。

func WithOperator

func WithOperator(ctx context.Context, op string) context.Context

WithOperator 注入操作者(审计主体——会话发起人;业务工具经 OperatorOf 消费)。

func WithResumeState

func WithResumeState(ctx context.Context, state any) context.Context

WithResumeState 注入挂起恢复态(适配层在引擎恢复重放时调用)。

Types

type ApprovalCard

type ApprovalCard struct {
	Tool     string     `json:"tool"`
	Action   string     `json:"action,omitempty"` // 动作名(缺省回退 Tool)
	Args     string     `json:"-"`
	ItemID   string     `json:"item_id,omitempty"`
	PlanMode bool       `json:"plan_mode,omitempty"` // plan 档计划卡(批准授权本轮全部写)
	Plan     []PlanItem `json:"plan"`
	Note     string     `json:"note,omitempty"`
	Diff     string     `json:"diff,omitempty"` // 审批卡逐行 diff 载荷——apply_patch 透传补丁原文 / repo_commit 现算 git diff;超长截断
}

ApprovalCard 审批中断载荷(Suspend.Info;approval_request 事件数据源)。 ItemID = 合并决议卡的项标识(H4-2:挂起时生成,随卡与保存态双带—— Resume 重放时工具按保存态领各自项的决议)。

type ApprovalDecision

type ApprovalDecision struct {
	Approve     bool
	Reason      string
	DeciderID   string
	DeciderName string
}

ApprovalDecision 审批决议(应用 approve 端点 → 审批包装工具消费)。 Decider*(T6):谁决议的——空 = 单用户零变化;落 DecisionOut 回执可审计。

type ApprovalItem

type ApprovalItem struct {
	ItemID   string     `json:"item_id"` // 项标识(工具挂起时生成、随保存态回放)
	Tool     string     `json:"tool"`
	Action   string     `json:"action,omitempty"`
	Plan     []PlanItem `json:"plan"`
	PlanMode bool       `json:"plan_mode,omitempty"`
	Note     string     `json:"note,omitempty"`
	Diff     string     `json:"diff,omitempty"`
	// T6 多参与者:谁的动作(同轮同 actor——顶层镜像之外的逐项署名,
	// 合并卡逐项可独立归因)。空 = 单用户零变化。
	RequesterID   string `json:"requester_id,omitempty"`
	RequesterName string `json:"requester_name,omitempty"`
}

ApprovalItem 合并决议卡单项(H4-2:一轮并行写调用聚合为一卡 N 项, 逐项审阅、一次提交携带全部决议)。

type ApprovalReq

type ApprovalReq struct {
	ApprovalID string         `json:"approval_id"`
	Tool       string         `json:"tool"`
	Action     string         `json:"action,omitempty"` // 动作名(直白话;缺省回退 tool)
	Plan       []PlanItem     `json:"plan"`
	TimeoutAt  time.Time      `json:"timeout_at"`
	PlanMode   bool           `json:"plan_mode,omitempty"` // plan 档计划卡语义(批准授权本轮全部写)
	Note       string         `json:"note,omitempty"`      // 卡面提示(如「批准后本轮后续写操作一并执行」)
	Diff       string         `json:"diff,omitempty"`      // 审批卡逐行 diff 载荷(apply_patch 补丁原文 / repo_commit git diff;超长截断)
	Items      []ApprovalItem `json:"items,omitempty"`     // 合并决议卡逐项(空 = 旧单卡形态)

	// T6 多参与者:谁的动作触发的审批(当轮说话人,回退 Owner ID——
	//「问谁」路由与审计「这条指令谁下的」的数据前提)
	RequesterID   string `json:"requester_id,omitempty"`
	RequesterName string `json:"requester_name,omitempty"`
	// T6 路由目标(Options.ApprovalRouter 裁决「问谁」;空 = 不路由——
	// 全员可见谁先点谁决议):前端定向提示 + DecisionGuard 校验依据
	TargetID   string `json:"target_id,omitempty"`
	TargetName string `json:"target_name,omitempty"`
}

ApprovalReq 审批请求(事件载荷,前端审批卡数据源)。Items = 合并决议卡 的逐项清单(并行写调用聚合);顶层旧字段 = 首项镜像——旧事件无 Items 时 前端按 N=1 单卡渲染(回放兼容),新事件两处都填。

type AskCard

type AskCard struct {
	Question      string      `json:"question"`
	Options       []AskOption `json:"options"`
	AllowMulti    bool        `json:"allow_multi"`
	AllowFreeText bool        `json:"allow_free_text"`
}

AskCard 提问中断载荷(Suspend.Info;ask_user_request 事件数据源)。

type AskDecision

type AskDecision struct {
	Answers     []string
	FreeText    string
	DeciderID   string // T6:谁作答(空 = 单用户零变化)
	DeciderName string
}

AskDecision ask_user 作答(应用 answer 端点 → ask_user 工具消费)。

type AskOption

type AskOption struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

AskOption 提问候选项(value 缺省 = label)。

type AskReq

type AskReq struct {
	AskID         string      `json:"ask_id"`
	Question      string      `json:"question"`
	Options       []AskOption `json:"options"`
	AllowMulti    bool        `json:"allow_multi,omitempty"`
	AllowFreeText bool        `json:"allow_free_text,omitempty"`
	TimeoutAt     time.Time   `json:"timeout_at"`
}

AskReq 提问请求(事件载荷,前端提问卡数据源)。

type Attachment

type Attachment struct {
	Name    string `json:"name"`
	Path    string `json:"path"`
	IsImage bool   `json:"is_image"`
}

Attachment 用户消息附件(应用层注入文本以路径引用带给模型;IsImage 供 前端渲染图片标)。

type ChangeRecorder

type ChangeRecorder func(path, action string)

ChangeRecorder 文件变更报备(会话域注入;session_end 载荷数据源)。

func ChangeRecorderOf

func ChangeRecorderOf(ctx context.Context) ChangeRecorder

ChangeRecorderOf 读取变更记录器(nil = 无记录上下文)。

type DecisionOut

type DecisionOut struct {
	ApprovalID string            `json:"approval_id"`
	Approve    bool              `json:"approve"`
	Reason     string            `json:"reason,omitempty"`
	Items      []ItemDecisionOut `json:"items,omitempty"` // 合并决议逐项回执(空 = 旧单卡决议)

	// T6:顶层镜像(首项决议者;N=1 主形态直读)
	DeciderID   string `json:"decider_id,omitempty"`
	DeciderName string `json:"decider_name,omitempty"`
}

DecisionOut 审批决议回执(事件流是切回/回放重建审批卡终态的真源)。 顶层 Approve/Reason = N=1 镜像或全项一致语义;N>1 分歧态以 Items 为准。

type Delta

type Delta struct {
	Delta string `json:"delta"`
}

Delta 文本/思考增量。

type DiffProvider

type DiffProvider interface {
	ApprovalDiff(args string) string
}

DiffProvider 工具可选接口:审批卡 diff 载荷(hitl.WrapTools 组卡时探测; 参数为工具入参 JSON,返回 diff 文本——人审逐行 diff 的数据源)。

type ErrorOut

type ErrorOut struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ErrorOut 错误卡片(Code 取上方封闭词表常量;AUTH/RATE_LIMIT 为网络容错 ③ 分类器新增〔认证失败 / 限速重试耗尽〕;OVERFLOW = 上下文超窗〔manager 裁剪 重装配有界重试一次后才如实报错〕)。

type Event

type Event struct {
	ID    int    `json:"id"`
	Event string `json:"event"`
	Data  any    `json:"data"`
	Ts    int64  `json:"ts,omitempty"` // 记录时刻墙钟毫秒(UI-B1:历史回放的时长计算源;旧数据零值=前端降级不显示)
}

Event 已发事件(回放/订阅的统一载体;Data 为下方载荷类型之一或 map)。

type FileChange

type FileChange struct {
	Path   string `json:"path"`
	Action string `json:"action"` // created | edited | deleted
	Count  int    `json:"count"`
}

FileChange session_end 文件变更清单条目(会话累计,path 排序)。

type HarnessNote

type HarnessNote struct {
	Kind   string `json:"kind"`             // offload(外置)| compaction(摘要压缩)
	Title  string `json:"title"`            // 单行标题(常显)
	Detail string `json:"detail,omitempty"` // 可展开内容(路径清单/全文指引)
}

HarnessNote harness 通知卡(H8-3:summarization 压缩 / reduction 外置—— 统一可折叠系统卡形态,非 error 非普通消息;呈现归应用)。

type InterruptOut

type InterruptOut struct {
	Message string `json:"message"`
}

InterruptOut 打断行载荷(interrupted 事件——立即处理排队的取消收尾, 非故障形态;区别于 error ABORTED 的停止)。

type ItemDecisionOut

type ItemDecisionOut struct {
	ItemID  string `json:"item_id"`
	Approve bool   `json:"approve"`
	Reason  string `json:"reason,omitempty"`
	// T6 多参与者:谁决议的(空 = 单用户零变化——回放可答「谁批的」)
	DeciderID   string `json:"decider_id,omitempty"`
	DeciderName string `json:"decider_name,omitempty"`
}

ItemDecisionOut 合并决议卡单项决议回执(切回/回放重建逐项终态的真源)。

type ModelChange

type ModelChange struct {
	From string `json:"from"`
	To   string `json:"to"`
}

ModelChange 会话内模型切换注记(UI-B5:居中分隔条数据源——界面注记即数据, 回放/live 一致)。语义(2026-09-03 定调):选择器切换只记录不落事件;下一次 模型调用时本次与上次实际调用不同才落(effort 变更不发)。ZCode 对位 = timeline part(model_change)。

type OutputContract added in v0.5.0

type OutputContract interface {
	// OutputSchema 结果 JSON Schema(object 形;nil = 只声明渲染不校验)。
	OutputSchema() *Schema
	// Render canonical 值 → 模型可见文本;空返回 = 退回原样 JSON。
	Render(args, result json.RawMessage) string
}

Tool 业务与通用工具的统一契约。args/result 均为 JSON 字节——传输无关 (SSE/WS/CLI 由应用层自定),参数 schema 由 ToolInfo 携带。 工具实现不落审批语义——写面审批由基座组装期包装(hitl)统一处理; 需要挂起交互的工具(ask_user 同构)以 *Suspend 哨兵上抛(见 suspend.go)。 OutputContract 可选输出契约(T8 吸收设计 §1.3-①——dsh ToolDefinition 的 output.schema + render 形态):实现了即被引擎在装配期识别(wrapFace 入口、 mid 包装前——包装链类型不可穿透,hitl.go:216 DiffProvider 同款先例)。 值 / 校验 / 渲染 / UI 四件事正交:canonical 值仍走工具返回,成功路径按 OutputSchema 校验(mid.ValidateJSON——required 在场校验),Render 产出模型 可见文本(回喂/reduction/transcript 共用同一投影——渲染只写一份)。 未实现 = 既有行为(自由 JSON 全量回喂)零变化;Render 返回空 = 退回原样。

type Participant added in v0.5.0

type Participant struct {
	ID   string `json:"id"`             // 稳定键(审计/权限/路由依据)
	Name string `json:"name,omitempty"` // 展示名(快照语义)
	Role string `json:"role,omitempty"` // 应用自定义角色
}

Participant 会话参与者(T6 多参与者模型:多人群聊/坐席协同场景——多个人 共用一个会话且分得清谁是谁)。ID 由应用分配(渠道账号 ↔ 业务用户的映射 归应用层,基座只透传);Name 为展示名快照(事件渲染/模型投影用——回放 零查表,人改名不追改历史事件);Role 应用自定义(owner/member/approver… 基座不解释)。Owner 不受影响:存储寻址与租户锚语义不变。

type ParticipantEvent added in v0.5.0

type ParticipantEvent struct {
	Participant Participant `json:"participant"`
	Kind        string      `json:"kind"` // joined | updated | left
}

ParticipantEvent 参与者名册变更(participant_update;回放重建 roster 的 真源——不依赖 session.json 快照)。Kind 封闭集:joined | updated | left。

type PlanCard

type PlanCard struct {
	Task        string     `json:"task"` // 任务一句话
	Summary     string     `json:"summary"`
	Steps       []PlanStep `json:"steps"`
	Risks       string     `json:"risks,omitempty"`
	Seq         int        `json:"seq"`  // 文档序号(修订递增留痕)
	Path        string     `json:"path"` // 用户域相对路径 plans/<sid>/<seq>.md
	Mode        string     `json:"mode"` // 提交时档位(决议语义分叉:plan 批准=任务授权,manual 批准=仅确认方向)
	SubmittedAt time.Time  `json:"submitted_at"`
}

PlanCard 计划中断载荷(Suspend.Info 第三形态;plan_request 事件数据源)。 文档内容可由本卡完整重建(恢复流按决议状态重写整文件)。

type PlanDecisionOut

type PlanDecisionOut struct {
	PlanID      string `json:"plan_id"`
	Approve     bool   `json:"approve"`
	Reason      string `json:"reason,omitempty"`
	DeciderID   string `json:"decider_id,omitempty"` // T6:谁决议的(空 = 零变化)
	DeciderName string `json:"decider_name,omitempty"`
}

PlanDecisionOut 计划决议回执(事件流是切回/回放重建计划卡终态的真源)。

type PlanItem

type PlanItem struct {
	Action  string `json:"action"`
	Summary string `json:"summary"`
	Count   int    `json:"count"`
}

PlanItem 审批卡计划清单行。

type PlanReq

type PlanReq struct {
	PlanID    string     `json:"plan_id"`
	Task      string     `json:"task"`
	Summary   string     `json:"summary"`
	Steps     []PlanStep `json:"steps"`
	Risks     string     `json:"risks,omitempty"`
	Path      string     `json:"path"` // 用户域相对路径 plans/<sid>/<seq>.md
	Seq       int        `json:"seq"`
	Mode      string     `json:"mode,omitempty"`
	TimeoutAt time.Time  `json:"timeout_at"`
}

PlanReq 计划请求(事件载荷,前端计划卡数据源)。Mode 分叉决议语义: plan 批准 = 授权任务期全部写(taskGrant);manual 批准 = 仅确认方向不授权。

type PlanStep

type PlanStep struct {
	Title  string `json:"title"`
	Detail string `json:"detail,omitempty"`
}

PlanStep 计划文档步骤。

type QueuedMsg

type QueuedMsg struct {
	ID          string       `json:"id"`
	Text        string       `json:"text"`
	Attachments []Attachment `json:"attachments,omitempty"`
	Kind        string       `json:"kind,omitempty"`
	// 多参与者(T6):谁排的队——空 = 单用户零变化(旧语义)
	SpeakerID   string `json:"speaker_id,omitempty"`
	SpeakerName string `json:"speaker_name,omitempty"`
}

QueuedMsg 排队消息(steering 入队;可编辑/删除。ID 是事件定位锚)。 Kind 标记条目来源:空 = 用户输入(可编辑/删除);notify = 系统通知 (后台子代理完成回传注入——只读,编辑/删除面拒绝)。

type Schema

type Schema struct {
	Type        string             `json:"type,omitempty"`
	Description string             `json:"description,omitempty"`
	Enum        []string           `json:"enum,omitempty"`
	Items       *Schema            `json:"items,omitempty"`
	Properties  map[string]*Schema `json:"properties,omitempty"`
	Required    []string           `json:"required,omitempty"`
	Minimum     *float64           `json:"minimum,omitempty"`
	Maximum     *float64           `json:"maximum,omitempty"`
}

Schema 参数 JSON Schema 的最小子集(object 形)。与 eino ParamsOneOf 经 JSON 往返互转(einox/einoext 的 Adapt/Bridge 桥)。Minimum/Maximum 供 mid.Validate 数值边界校验(数值类型约束,声明了才校验)。

type SessionEnd

type SessionEnd struct {
	Summary string       `json:"summary"`
	Files   []FileChange `json:"files,omitempty"` // 有改动才带(纯问答省缺)
	// HistLen 轮末历史长度(分叉锚定数据:ForkAt 截断重建依据;零值 = 不可
	// 锚——旧存量事件兼容)。记录时点先于本轮历史追加,值 = 追加前长度 +
	// 本轮待追加消息数(预测值即轮后精确值)。
	HistLen int `json:"hist_len,omitempty"`
}

SessionEnd 收尾。

type SteerEvent

type SteerEvent struct {
	ID          string       `json:"id"`
	Text        string       `json:"text,omitempty"`
	Attachments []Attachment `json:"attachments,omitempty"`
	Kind        string       `json:"kind,omitempty"`
	// T6 多参与者:谁排的队/谁的补充(空 = 单用户零变化)
	SpeakerID   string `json:"speaker_id,omitempty"`
	SpeakerName string `json:"speaker_name,omitempty"`
}

SteerEvent 排队消息事件载荷(steer_queued/updated/removed/injected)。 Kind 标记条目来源:空 = 用户输入;notify = 系统通知(后台子代理完成回传, notify_queued/notify_injected 专用——排队区渲染为只读系统通知)。

type SteerReorder

type SteerReorder struct {
	IDs []string `json:"ids"`
}

SteerReorder 排队消息重排回执(UI-B3:拖拽排序——IDs = 重排后的完整顺序, 前端按此重建排队条目顺序;回放/live 一致)。

type SubAgentEvent

type SubAgentEvent struct {
	SpawnID string `json:"spawn_id,omitempty"` // 实例键(后台派生;会话域唯一)
	Agent   string `json:"agent"`              // 子代理名(spawn)
	Kind    string `json:"kind"`               // text | tool_call | tool_result | done | failed
	Text    string `json:"text,omitempty"`     // text 正文 / tool_result 摘要 / done = 结论全文(超长 spill 外置)
	Tool    string `json:"tool,omitempty"`     // 子代理调用的工具名
	Args    string `json:"args,omitempty"`     // tool_call 参数摘要
	OK      bool   `json:"ok,omitempty"`       // tool_result 成败
	// 终态细分(非终态零值):
	StopReason string `json:"stop_reason,omitempty"` // completed | aborted | error | max_tokens
	Partial    string `json:"partial,omitempty"`     // failed 附带:终止前最后一段 assistant 输出(父模型可判补做/放弃)
}

SubAgentEvent 子代理过程事件(H8-2 全量转发档:spawn 子代理的内部事件 经泵翻译转发——只读流数据面,子过程不进父主流;折叠卡展开态消费)。 SpawnID = per-invocation 实例键(W-1):后台派生事件必带(会话域单调 "sp1/sp2/…",注册表分配——勿用回合内自增,跨回合后台任务会撞键); 同步调用事件不带(零值 = 前端回退「归最近」启发式,回放兼容)。 Kind 扩展 done | failed 两态(后台派生终态):Text = 结论全文 / 失败 errFeed 信封;killed/cancelled 位预留(v1.1 kill/wait 引入时扩第三态)。 终态细分走 StopReason 载荷字段(不拆 Kind 词表——软契约纯增量,dsh stopReason 形态对齐);failed 附 Partial 半成品。

type Suspend

type Suspend struct {
	Info  any
	State any
}

Suspend 工具挂起哨兵(ask_user 同构):Info = 事件面载荷(审批卡/提问卡, 应用层据此渲染交互卡),State = 恢复读回态(经 checkpoint 持久化)。 适配层(einox/einoext.Adapt)将其转引擎中断;恢复时经 WithResumeState 注回 ctx,工具据此走续跑分支(读取决议并继续)。

func (*Suspend) Error

func (s *Suspend) Error() string

type Tool

type Tool interface {
	// Info 工具元数据(名称/描述/参数 schema)。
	Info() *ToolInfo
	// Invoke 执行一次调用。返回值为 JSON 字节;业务性失败以 JSON 信封
	// {"ok":false,"error":…} 回喂模型自纠(Go error 会终止整轮)。
	Invoke(ctx context.Context, args json.RawMessage) (json.RawMessage, error)
}

type ToolCall

type ToolCall struct {
	CallID     string `json:"call_id"`
	Tool       string `json:"tool"`
	ArgsDigest string `json:"args_digest"`
	Behavior   string `json:"behavior,omitempty"` // 行为面标记(ToolInfo.Behavior 快照——过程流分组数据源;空=未标记)
}

ToolCall 工具调用卡片。

type ToolInfo

type ToolInfo struct {
	Name   string  `json:"name"`
	Desc   string  `json:"desc"`
	Params *Schema `json:"params,omitempty"` // JSON Schema(object 形)
	// Behavior 行为面标记(UI-B2:过程流「探索/更改/终端」分组的展示语义
	// 数据源;空 = 未标记——交互卡/待办类不入组,前端按工具名兜底)。
	// 与 hitl 写面名单无关:名单 = 审批语义(写才拦),本标记 = 展示语义。
	Behavior string `json:"behavior,omitempty"`
}

ToolInfo 工具元数据。

type ToolResult

type ToolResult struct {
	CallID  string `json:"call_id"`
	OK      bool   `json:"ok"`
	Digest  string `json:"digest"`
	Preview string `json:"preview,omitempty"`
	Counts  string `json:"counts,omitempty"` // B4 文件变更信封 "+A -D"(写类工具结果自带;编辑卡/汇总行数据源)
	Verb    string `json:"verb,omitempty"`   // B4 信封扩展键 create|edit(新建/修改写动词——工具名判别不可分时工具方自带)
}

ToolResult 工具结果收口(Digest = 语义摘要;Preview = 原始内容头,展开用)。

type TransportRetry

type TransportRetry struct {
	Attempt int `json:"attempt"` // 第几次重试(1 起)
	Max     int `json:"max"`     // 重试上限(llm.MaxRetries)
}

TransportRetry 传输重连通知(网络容错 ②:模型调用重试在途——事件层已实时 转发失败尝试的半截增量,eino 重试协议要求客户端自行 reset)。前端收此事件 回卷当前段半截显示 + 重连提示卡;历史不受影响(引擎侧已丢弃半截段)。

type UsageOut

type UsageOut struct {
	PromptTokens     int    `json:"prompt_tokens"`
	CompletionTokens int    `json:"completion_tokens"`
	TotalTokens      int    `json:"total_tokens"`
	SpawnID          string `json:"spawn_id,omitempty"` // 子代理来源(空 = 主面)
	EstInstruction   int    `json:"est_instruction"`
	EstTools         int    `json:"est_tools"`
	EstMessages      int    `json:"est_messages"`
	EstSaved         int    `json:"est_saved,omitempty"` // 整形节省(原始-整形;0/负值省略)
}

UsageOut usage 事件载荷(上下文按钮数据源)。分类三项为启发式估算—— est_messages 已是整形后出站口径(H8-1:reasoning 剥离/空壳剔除后的真实 发送面);est_saved = 原始口径差额(「整形节省」注记)。usage 真值注意 DeepSeek prompt_tokens 含缓存命中(= hit+miss,双口径展示归应用)。 SpawnID 非空 = 子代理面用量上卷(B2:子面无估算口径、四项为零;消费侧 按 SpawnID 归组聚合,空 = 主面)。

type UserMsg

type UserMsg struct {
	Text        string       `json:"text"`
	Attachments []Attachment `json:"attachments,omitempty"`
	// T6 多参与者:谁说的(Name = 快照;空 = 单用户零变化)
	SpeakerID   string `json:"speaker_id,omitempty"`
	SpeakerName string `json:"speaker_name,omitempty"`
}

UserMsg 用户消息记录(回放补全;附件结构化载荷)。

type UserPrefs

type UserPrefs struct {
	Model  string `json:"model"`  // provider/model 复合键
	Effort string `json:"effort"` // 思考档位 off | low | high | max(旧值 on 由读侧归一 max、未知归一 low;能否真关由端点定)
	Mode   string `json:"mode"`   // 会话模式 manual | plan | auto
}

UserPrefs 用户模型偏好(会话模型快照与用户默认;字段语义见 einox/llm)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL