capability

package
v0.0.0-...-1c978d5 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package capability 定义框架的最小统一抽象:一切节点皆能力。

工具、ChatModel、Memory、RAG、Skill、完整的 Agent,都实现同一个 Capability 接口。每个能力有两种挂载形态:

  • AsTool:挂到模型的工具面,由"大脑"(LLM)决定何时调用 —— 动态编排;
  • AsLambda:挂到 eino Graph 的固定节点,由流程决定何时执行 —— 静态编排。

能力以 Ref(cap://kind/ns/name@version)标识,携带 Risk 分级供运行时做审批拦截与准入控制。

Index

Constants

View Source
const TagInteractive = "interactive"

TagInteractive 标记"阻塞等待用户输入"的交互类能力(ask_user 等): 工具超时闸门对其豁免——等人回复的时间不是执行时间。

View Source
const TagProcedureCard = "procedure-card"

TagProcedureCard 标记过程卡能力(mode: inline 的 skill):结果是执行 指引而非数据——消化会毁掉指令结构(豁免 digest),一次性计划也编排 不了"照着指引临场干"(rewoo 计划面剔除)。

View Source
const TagRawResult = "result:raw"

TagRawResult 标记能力的结果不参与消化(结果本身就是给模型的原文, 如 read_result 的分页输出)。声明于 core:消化闸门(loop)与引擎的 计划面筛选(engine)都要认它,而 engine 不得依赖 loop。

Variables

View Source
var NoParams = &schema.ParamsOneOf{}

NoParams 显式声明"该工具确实无入参":工具形态的 ToolInfo.ParamsOneOf 置为 nil——eino FAQ 明确无参工具必须传 nil,空 schema 会被部分厂商 拒绝(400)。仅作身份标记,不要调用其方法。

Functions

func AsTools

func AsTools(ctx context.Context, caps []Capability) ([]tool.BaseTool, error)

AsTools 批量转换能力为 eino 工具,供 ToolsNode / ReAct 使用。

func Invoke

func Invoke(ctx context.Context, c Capability, argsJSON string) (string, error)

Invoke 以统一契约直接调用一个能力(工具形态的执行路径)。

func ParamsSchema

func ParamsSchema(params map[string]ParamDecl) (*schema.ParamsOneOf, error)

ParamsSchema 把 ParamDecl 映射为工具入参 schema;无参数时退化为单个 string 入参 {"input": ...}(与 capability.New 的默认一致)。 type 词汇装配期锁死:int/str/bool 等拼法此前静默转 string,模型按错 类型传参、后端拒收,错误面在运行期且难归因。

func ParseSingle

func ParseSingle(argsJSON, field string) string

ParseSingle 从参数 JSON 里取出单个字符串字段;解析失败时把整个 入参当作该字段的值(容忍图节点直接传裸字符串)。

func SingleParam

func SingleParam(name, desc string) *schema.ParamsOneOf

SingleParam 生成单参数的入参 schema,减少样板代码。

Types

type Capability

type Capability interface {
	Meta() Meta
	// AsTool 返回能力的工具形态,供模型自主调用。
	AsTool(ctx context.Context) (tool.BaseTool, error)
	// AsLambda 返回能力的图节点形态(string 入参 JSON -> string 出参),
	// 供 compose.Graph 静态编排。
	AsLambda(ctx context.Context) (*compose.Lambda, error)
}

Capability 是所有节点的统一抽象。

func FromTool

func FromTool(ctx context.Context, t tool.BaseTool, ref Ref, risk Risk) (Capability, error)

FromTool 把一个已有的 eino 工具(如 MCP 拉取的工具)包装成能力。 ref 的 Name 为空时取工具自报的名字。构造时调用一次 Info 获取元信息。

func New

func New(meta Meta, fn InvokeFunc) Capability

New 从一个执行函数构造能力,是自定义能力最直接的入口。

func NewModel

func NewModel(ref Ref, description string, m model.ToolCallingChatModel) Capability

NewModel 把 ChatModel 纳入能力体系:AsTool 时是可被上级大脑调用的 "问答子模型"(如廉价小模型做摘要),AsLambda 时是图里的模型节点。

func Rename

func Rename(c Capability, toolName string) Capability

Rename 返回一个模型可见短名不同的能力副本,目录在撞名升级时使用。 Ref 与其余元信息不变。

type DeliverMode

type DeliverMode string

DeliverMode 是能力产出的交付语义:证据(缺省)由大脑消费合成; 交付物由 Ring 0 捕获原文、经出站事实位直达用户——大脑保留策展权 (引用哪些、写导读),失去转述权(原文不经它的嘴)。 设计:docs/deliverable-channel-plan.md。

const (
	DeliverNone   DeliverMode = ""       // 证据(默认)
	DeliverAttach DeliverMode = "attach" // 存底;终答引用 #dN 即随行
	DeliverAlways DeliverMode = "always" // 存底;不待引用恒随行
	DeliverDirect DeliverMode = "direct" // 独占轮次时原文即终答;否则退化 attach
)

func ParseDeliver

func ParseDeliver(s string) (DeliverMode, error)

ParseDeliver 解析交付语义,未知值报错(配置词汇 fail fast)。

type Duration

type Duration time.Duration

Duration 是配置里的时长字段,YAML 里写 "30s"/"5m" 这类字符串, 或裸数字(按秒解释)。零值表示未配置(取默认),负值表示显式关闭。 放在 capability(基座)是因为它是各层共享的配置词汇——engine 的编排 步骤、loop 的可靠性、config 的 TTL 都用它;loop.Duration 是本类型的别名。

func (Duration) Std

func (d Duration) Std() time.Duration

Std 返回标准库时长。

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML 支持 "30s" 字符串与裸数字(秒)两种写法。

type InvokeFunc

type InvokeFunc func(ctx context.Context, argsJSON string) (string, error)

InvokeFunc 是能力的统一执行契约:入参为 JSON 字符串,出参为字符串。

type Meta

type Meta struct {
	Ref         Ref
	Description string
	// Params 是工具形态的入参 schema;为 nil 时默认单个 string 入参 {"input": ...}。
	Params *schema.ParamsOneOf
	Risk   Risk
	// Deliver 是产出的交付语义(证据/attach/always/direct),
	// Ring 0 的 DeliverResults 按此捕获。
	Deliver DeliverMode
	Tags    []string
}

Meta 是能力的自描述清单。Description 会作为工具描述暴露给模型, 是大脑调用决策的直接依据,写得越清楚决策越准。

type ParamDecl

type ParamDecl struct {
	Type     string `yaml:"type" json:"type"`
	Desc     string `yaml:"desc" json:"desc"`
	Required bool   `yaml:"required" json:"required"`
}

ParamDecl 描述一个可调用单元(skill / component / 编排步骤)的入参。 它是「可调用单元的参数接口」,循环族与编排族共用,故归基座 capability。

type Ref

type Ref struct {
	Kind    string // tool | skill | component | agent | prompt | store | retriever
	Domain  string // 归属域:源名 / builtin / 存储用途 / prompt 源
	Name    string
	Version string
}

Ref 是能力的结构化标识,文本形式(4 段):

cap://<kind>/<domain>/<name>@<version>
cap://tool/fs/read_file@1.0
cap://skill/research/competitor_report@1
cap://store/session/sess

kind 是对象类别;domain 是该 kind 下 name 的归属域(见 domain 不变式: callable→源/ns,store/retriever→slot-kind,prompt→prompt 源);version 可以是语义版本或通道名(production/staging),空表示任意。

不变式:kind 段永远精确,通配只出现在 name 段(见 Match)。Key 不含 version(见 Key)。

func ParseRef

func ParseRef(s string) (Ref, error)

ParseRef 解析完整标识或带 * 通配的模式。 形式:cap://kind/domain/name[@version];各段可为 * (模式), name 段允许前缀通配(如 todo_*)。

func (Ref) Key

func (r Ref) Key() string

Key 返回不含版本的唯一键,用于目录索引与冲突检测。 版本共存靠 registry 的 Key→{version→entry},不进 Key。

func (Ref) Match

func (r Ref) Match(pattern Ref) bool

Match 判断 r 是否命中模式 pattern。通配不变式:**kind 段永远精确**; domain 与 name 段支持 *(任意)与 name 前缀通配(foo_*); pattern.Version 为空表示任意版本。

kind 精确是「kind 优先 dispatch」得以成立的前提——`*`-kind 无法 选解析域,故不允许。domain 可通配("某 kind 的全部",如 cap://tool/*/*); 「跨 kind 挂载全部」不是通配匹配,是 Catalog.SelectAll 的显式操作。

func (Ref) String

func (r Ref) String() string

String 渲染为 URI 形式;version 为空时省略 @ 段。

type Risk

type Risk int

Risk 是能力的风险分级,是审批拦截与目录准入的依据。

零值是 RiskUnspecified 而非 readonly:忘写 Risk 的 mutating 能力若默认 最宽松,会静默绕过审批闸门。门闸与准入对 Unspecified 按 mutating 保守 对待(经 Effective);内置只读工具全部显式标注 RiskReadonly。

const (
	RiskUnspecified Risk = iota // 未声明:门闸按 mutating 保守对待
	RiskReadonly                // 只读,无副作用
	RiskMutating                // 有改动性副作用(写文件、发消息、下单)
	RiskDangerous               // 危险(删除、资金、不可逆),默认不入目录
)

func ParseRisk

func ParseRisk(s string) (Risk, error)

ParseRisk 解析风险级别字符串,空串按 readonly 处理。

func (Risk) Effective

func (r Risk) Effective() Risk

Effective 返回门闸/准入视角的等效级别:未声明按 mutating 保守处理。

func (Risk) String

func (r Risk) String() string

Jump to

Keyboard shortcuts

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