跳转至

其他类型

剩余的类型与方法:PluginSDK 本体的访问器、StageContext 的并发控制,以及多模态辅助类型。没有归入上面任何一个主题,但可能仍会用到。

DocMemoryAPI

DocMemoryAPI provides access to the document vector store.

方法 说明
Insert
InsertWithMedia InsertWithMedia 写入文档并关联媒体。attachments 里带 Data 的会落进
Query
Remove
Stats

DocMemoryAPI.Insert

Insert(doc *Doc) error

memory.go:76

DocMemoryAPI.InsertWithMedia

InsertWithMedia(doc *Doc, attachments []MediaAttachment) error

InsertWithMedia 写入文档并关联媒体。attachments 里带 Data 的会落进 内容寻址存储(相同字节只存一份),只带 Digest 的直接引用已有内容。 媒体成为文档直接持有的一等记忆块:文档向量会融合它们的原生向量, 因此图片按自己的向量被召回,不依赖任何生成的描述文本。

memory.go:81

DocMemoryAPI.Query

Query(text string, topK int) []*Doc

memory.go:75

DocMemoryAPI.Remove

Remove(id string)

memory.go:82

DocMemoryAPI.Stats

Stats() map[string]interface{}

memory.go:83

EventSubscriber

EventSubscriber allows plugins to subscribe to kernel events. This is a restricted interface: plugins can subscribe but the kernel controls which events are delivered.

方法 说明
Subscribe

EventSubscriber.Subscribe

仅内核内置插件可用

Subscribe(eventType EventType, handler EventHandler) func()

plugin.go:279

IOInjector

IOInjector provides methods for injecting input and interrupts into the agent pipeline. All methods accept (source, channel) where channel is the target output channel for routing the agent's response.

方法 说明
InjectInputMedia
InjectInputMediaOpts
InjectInputMediaSync
InjectInputMediaSyncOpts
InjectInputSync InjectInputSync 注入输入事件并同步等待 agent 回复,返回回复文本(无回复时返回空串)。
InjectInputSyncOpts
InjectInterruptMedia
InjectInterruptMediaOpts
InjectInterruptText
InjectInterruptTextOpts
InjectText
InjectTextNoMemory
InjectTextOpts 以下 Opts 变体让调用点在这一次注入上声明记忆与裁剪行为。
SetToolBlocks SetToolBlocks 插件工具注入多模态内容块(image_url/audio_url),内核在下一条

IOInjector.InjectInputMedia

InjectInputMedia(source, channel, text string, blocks []ContentBlock)

plugin.go:230

IOInjector.InjectInputMediaOpts

InjectInputMediaOpts(source, channel, text string, blocks []ContentBlock, opts InjectOptions)

plugin.go:241

IOInjector.InjectInputMediaSync

InjectInputMediaSync(source, channel, text string, blocks []ContentBlock) string

plugin.go:231

IOInjector.InjectInputMediaSyncOpts

InjectInputMediaSyncOpts(source, channel, text string, blocks []ContentBlock, opts InjectOptions) string

plugin.go:242

IOInjector.InjectInputSync

InjectInputSync(source, channel, text string) string

InjectInputSync 注入输入事件并同步等待 agent 回复,返回回复文本(无回复时返回空串)。 用于通道消息的完整闭环:收到入站 → agent 处理 → 回复取回 → 送回通道。

示例插件里的真实用法

插件 位置 代码
a2a example/a2a/plugin.go:345 reply := p.sdk.InjectInputSync(p.name, p.name,
acp example/acp/plugin.go:237 reply = p.sdk.InjectInputSync(p.name, p.name,

plugin.go:226

IOInjector.InjectInputSyncOpts

InjectInputSyncOpts(source, channel, text string, opts InjectOptions) string

plugin.go:240

IOInjector.InjectInterruptMedia

InjectInterruptMedia(source, channel, text string, blocks []ContentBlock)

plugin.go:232

IOInjector.InjectInterruptMediaOpts

InjectInterruptMediaOpts(source, channel, text string, blocks []ContentBlock, opts InjectOptions)

plugin.go:243

IOInjector.InjectInterruptText

InjectInterruptText(source, channel, text string)

plugin.go:221

IOInjector.InjectInterruptTextOpts

InjectInterruptTextOpts(source, channel, text string, opts InjectOptions)

示例插件里的真实用法

插件 位置 代码
browser example/browser/plugin.go:1319 p.sdk.InjectInterruptTextOpts(p.name, p.name,
calendar example/calendar/plugin.go:527 p.sdk.InjectInterruptTextOpts("calendar", "calendar", msg, sdk.InjectOptions{NoMemory: true})
memo example/memo/plugin.go:299 p.sdk.InjectInterruptTextOpts(p.name, p.name,
qq example/qq/plugin.go:1493 p.sdk.InjectInterruptTextOpts(p.name, p.name, text, sdk.InjectOptions{

plugin.go:239

IOInjector.InjectText

InjectText(source, channel, text string)

plugin.go:222

IOInjector.InjectTextNoMemory

InjectTextNoMemory(source, channel, text string)

示例插件里的真实用法

插件 位置 代码
browser example/browser/plugin.go:1114 p.sdk.InjectTextNoMemory(p.name, p.name, fmt.Sprintf("[浏览器 %s 已导航到 %s]", id, rawURL))

plugin.go:223

IOInjector.InjectTextOpts

InjectTextOpts(source, channel, text string, opts InjectOptions)

以下 Opts 变体让调用点在这一次注入上声明记忆与裁剪行为。

上面那些不带 opts 的方法等价于传零值 InjectOptions(记入记忆 + 不裁剪), 保留它们是为了不破坏已有插件;新代码应当用 Opts 变体把意图写清楚。

plugin.go:238

IOInjector.SetToolBlocks

SetToolBlocks(blocks []ContentBlock)

SetToolBlocks 插件工具注入多模态内容块(image_url/audio_url),内核在下一条 tool message 的 content 数组里带上这些块,让模型在后续轮次看到图/听到音频。

plugin.go:229

KnowledgeAPI

KnowledgeAPI provides access to the knowledge store.

方法 说明
Add
List
Search

KnowledgeAPI.Add

Add(name, content string) error

knowledge.go:6

KnowledgeAPI.List

List() ([]string, error)

knowledge.go:7

KnowledgeAPI.Search

Search(query string, topK int) ([]*Knowledge, error)

knowledge.go:5

LLMAPI

LLMAPI provides access to the LLM provider manager.

方法 说明
CurrentSource
ListSources
SetSource

LLMAPI.CurrentSource

CurrentSource() string

llm.go:7

LLMAPI.ListSources

ListSources() []string

llm.go:5

LLMAPI.SetSource

SetSource(name string) error

llm.go:6

MemoryAPI

MemoryAPI provides access to the graph memory (entity-relation store).

方法 说明
Commit
Introspect
MergeEntities
Purge
Recall

MemoryAPI.Commit

Commit(triples []Triple) error

memory.go:6

MemoryAPI.Introspect

Introspect() (map[string]interface{}, error)

memory.go:7

MemoryAPI.MergeEntities

MergeEntities(source, target string) (int, error)

memory.go:8

MemoryAPI.Purge

Purge(criteria map[string]string, mode string) (int, error)

memory.go:9

MemoryAPI.Recall

Recall(query []string, depth int) ([]Entity, []Relation, error)

memory.go:5

Plugin

Plugin is the interface every plugin must implement.

方法 说明
Name
Start
Stop

Plugin.Name

Name() string

plugin.go:14

Plugin.Start

Start(sdk *PluginSDK) error

plugin.go:15

Plugin.Stop

Stop() error

plugin.go:16

PluginMgrAPI

PluginMgrAPI 提供插件管理能力(外部插件可调用)。 由 bridge 注入 dispatch 实现,走 C ABI CORE_PLUGIN_RELOAD_ONE 等。

方法 说明
IsPluginDisabled IsPluginDisabled 查询插件是否被禁用。
ListLoadedPlugins ListLoadedPlugins 列出已加载插件。
ReloadOne ReloadOne 重载单个插件(停止后重新加载)。

PluginMgrAPI.IsPluginDisabled

IsPluginDisabled(name string) bool

IsPluginDisabled 查询插件是否被禁用。

plugin.go:290

PluginMgrAPI.ListLoadedPlugins

ListLoadedPlugins() []string

ListLoadedPlugins 列出已加载插件。

plugin.go:288

PluginMgrAPI.ReloadOne

ReloadOne(name string) error

ReloadOne 重载单个插件(停止后重新加载)。

plugin.go:286

SettingsAPI

方法 说明
DataDir DataDir returns the plugin-specific data directory (guaranteed to exist):
Defs Defs returns config definitions matching the prefix.
Dump Dump returns all config values.
Get Get reads the plugin's own config value (config_ table).
GetCore GetCore reads the core config table.
GetPlugin GetPlugin reads another plugin's config table.
List List returns all keys matching the given prefix.
ListCore ListCore lists core config keys matching the prefix.
ListPlugin ListPlugin lists another plugin's config keys matching the prefix.
Plugins Plugins returns a list of all plugin config namespaces.
RegisterDef RegisterDef registers a config definition for UI display.
Set Set writes a config value to the plugin's own config table.
SetCore SetCore writes to the core config table.
SetPlugin SetPlugin writes to another plugin's config table.

SettingsAPI.DataDir

DataDir() string

DataDir returns the plugin-specific data directory (guaranteed to exist): /plugin_data/. Plugins should persist any runtime files (generated images, caches, downloads) here.

settings.go:25

SettingsAPI.Defs

Defs(prefix string) []*ConfigDef

Defs returns config definitions matching the prefix.

settings.go:40

SettingsAPI.Dump

Dump() map[string]interface{}

Dump returns all config values.

settings.go:43

SettingsAPI.Get

Get(key string) (interface{}, error)

Get reads the plugin's own config value (config_ table).

settings.go:5

SettingsAPI.GetCore

GetCore(key string) (interface{}, error)

GetCore reads the core config table.

settings.go:14

SettingsAPI.GetPlugin

GetPlugin(plugin, key string) (interface{}, error)

GetPlugin reads another plugin's config table.

settings.go:28

SettingsAPI.List

List(prefix string) ([]string, error)

List returns all keys matching the given prefix.

settings.go:11

SettingsAPI.ListCore

ListCore(prefix string) ([]string, error)

ListCore lists core config keys matching the prefix.

settings.go:20

SettingsAPI.ListPlugin

ListPlugin(plugin, prefix string) ([]string, error)

ListPlugin lists another plugin's config keys matching the prefix.

settings.go:34

SettingsAPI.Plugins

Plugins() []string

Plugins returns a list of all plugin config namespaces.

settings.go:46

SettingsAPI.RegisterDef

RegisterDef(def ConfigDef)

RegisterDef registers a config definition for UI display.

settings.go:37

SettingsAPI.Set

Set(key string, value interface{}) error

Set writes a config value to the plugin's own config table.

settings.go:8

SettingsAPI.SetCore

SetCore(key string, value interface{}) error

SetCore writes to the core config table.

settings.go:17

SettingsAPI.SetPlugin

SetPlugin(plugin, key string, value interface{}) error

SetPlugin writes to another plugin's config table.

settings.go:31

SocialAPI

SocialAPI provides read-only access to the social graph (person profiles and relationships). External plugins can query person traits and social networks but cannot modify them.

方法 说明
GetNetwork
GetPerson
GetRelations
GetTrait
ListPersons

SocialAPI.GetNetwork

GetNetwork(name string, depth int) ([]*PersonProfile, error)

memory.go:104

SocialAPI.GetPerson

GetPerson(name string) (*PersonProfile, error)

memory.go:101

SocialAPI.GetRelations

GetRelations(name string) ([]SocialRelation, error)

memory.go:103

SocialAPI.GetTrait

GetTrait(name, trait string) (string, bool)

memory.go:102

SocialAPI.ListPersons

ListPersons() ([]string, error)

memory.go:105

TextMemoryAPI

TextMemoryAPI provides access to chronological text event storage.

方法 说明
Append

TextMemoryAPI.Append

Append(evt TextEvent) error

memory.go:44

AudioURL

type AudioURL struct { URL string `json:"url"` }

plugin.go:862

ImageURL

type ImageURL struct { URL string `json:"url"` Detail string `json:"detail,omitempty"` }

plugin.go:857

MemItem

type MemItem struct { Role string `json:"role"` Content string `json:"content"` Score float64 `json:"score"` }

MemItem represents a memory item in stage context.

plugin.go:179

PluginSDK

type PluginSDK struct { name string regTool ToolRegistrar regStage StageRegistrar regAPI APIRegistrar regOutput OutputChannelRegistrar 

PluginSDK is the main API surface provided to plugins at runtime. It wraps tool registration, settings, memory, knowledge, LLM, and IO injection.

plugin.go:337

SDKVersion

var SDKVersion

SDKVersion 是对外暴露的 SDK 版本号。

plugin.go:10

PluginSDK.UnregisterOutputChannel

仅内核内置插件可用

外部插件的桥接模板只注入 SetOutputChannelRegistrar(proc_main.go.tmpl:693-705),注入 SetOutputChannelUnregistrar(grep Unregistrar 在 templates/ 下无命中)。因此外部插件的 regOutputUnreg 为 nil,UnregisterOutputChannel 会命中 if reg != nil 的 else 分支直接返回 nil(sdk/plugin.go:539-549)——即静默无效:不报错、通道也没注销。内置插件由 internal/sdk/plugin.go:330 注入 cfg.RegOutputUnreg,真正生效。外部插件要让通道下线,只能重载插件。

func (s *PluginSDK) UnregisterOutputChannel(name string) error

UnregisterOutputChannel 注销一个输出通道(动态通道随资源生灭时必须调用)。

plugin.go:539