Help us shape the future of Go! Take the 2026 Go Developer Survey

bus

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package bus 实现 Golem 的消息总线机制,支持通道与 Agent 之间的异步通信。

Index

Constants

View Source
const (
	SystemChannel            = "system"          // 系统内部专用通道
	SystemTypeSubagentResult = "subagent_result" // 系统消息类型:子 Agent 执行结果

	SystemMetaType          = "system_type"      // 元数据键:消息类型
	SystemMetaTaskID        = "task_id"          // 元数据键:任务 ID
	SystemMetaTaskLabel     = "task_label"       // 元数据键:任务标签
	SystemMetaOriginChannel = "origin_channel"   // 元数据键:原始请求通道
	SystemMetaOriginChatID  = "origin_chat_id"   // 元数据键:原始请求聊天 ID
	SystemMetaOriginSender  = "origin_sender_id" // 元数据键:原始发送者 ID
	SystemMetaStatus        = "status"           // 元数据键:执行状态
)

Variables

This section is empty.

Functions

func NewRequestID added in v0.1.5

func NewRequestID() string

NewRequestID 生成一个新的 UUID 用于请求追踪。

func RequestIDFromContext added in v0.1.5

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext 从 context 中读取请求 ID。

func WithRequestID added in v0.1.5

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID 将请求 ID 注入到 context 中。

Types

type InboundMessage

type InboundMessage struct {
	Channel   string         // 消息来源通道(如 "telegram")
	SenderID  string         // 发送者唯一 ID
	ChatID    string         // 聊天会话 ID
	SessionID string         // 显式指定的会话 ID(可选)
	Content   string         // 消息文本内容
	Timestamp time.Time      // 接收时间
	Media     []string       // 附件(如图片 URL)列表
	Metadata  map[string]any // 随消息携带的元数据
	RequestID string         // 用于追踪的请求 ID
}

InboundMessage 表示从外部通道(如 Telegram、飞书等)接收到的入站消息。

func NewSubagentResultInbound added in v0.3.0

func NewSubagentResultInbound(taskID, label, originChannel, originChatID, originSenderID, result, requestID string, runErr error) *InboundMessage

NewSubagentResultInbound 为异步子 Agent 回调创建一个规范化的系统入站消息。

func (*InboundMessage) SessionKey

func (m *InboundMessage) SessionKey() string

SessionKey 返回此消息对应的唯一会话标识符。

type MessageBus

type MessageBus struct {
	// contains filtered or unexported fields
}

MessageBus 负责管理通道与 Agent 之间的消息路由。

func NewMessageBus

func NewMessageBus(bufferSize int) *MessageBus

NewMessageBus 创建一个新的消息总线实例。

func (*MessageBus) Close

func (b *MessageBus) Close()

Close 关闭消息总线中的所有通道。

func (*MessageBus) Inbound

func (b *MessageBus) Inbound() <-chan *InboundMessage

Inbound 返回入站消息的只读通道。

func (*MessageBus) Outbound

func (b *MessageBus) Outbound() <-chan *OutboundMessage

Outbound 返回出站消息的只读通道。

func (*MessageBus) PublishInbound

func (b *MessageBus) PublishInbound(msg *InboundMessage)

PublishInbound 将消息发布到入站队列中供 Agent 处理。

func (*MessageBus) PublishOutbound

func (b *MessageBus) PublishOutbound(msg *OutboundMessage)

PublishOutbound 将消息发布到出站队列中供外部通道消费。

type OutboundMessage

type OutboundMessage struct {
	Channel   string         // 目标通道
	ChatID    string         // 目标聊天 ID
	Content   string         // 消息文本内容
	ReplyTo   string         // 回复的消息 ID(可选)
	Media     []string       // 待发送的媒体文件列表
	Metadata  map[string]any // 随消息携带的元数据
	RequestID string         // 关联的请求 ID
}

OutboundMessage 表示发送给外部通道的出站消息。

Jump to

Keyboard shortcuts

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