2026-06-09 23:53:08 +08:00
|
|
|
package model
|
2026-06-10 12:49:29 +08:00
|
|
|
|
2026-06-10 13:41:18 +08:00
|
|
|
import "context"
|
2026-06-10 12:49:29 +08:00
|
|
|
|
|
|
|
|
// ============================================================
|
|
|
|
|
// 核心接口
|
|
|
|
|
// ============================================================
|
|
|
|
|
|
|
|
|
|
// Tool 外部工具接口
|
|
|
|
|
type Tool interface {
|
|
|
|
|
Name() string
|
|
|
|
|
Description() string
|
|
|
|
|
Call(ctx context.Context, input string) (string, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ChatModel 聊天模型接口,支持同步生成和流式输出
|
|
|
|
|
type ChatModel interface {
|
|
|
|
|
Generate(ctx context.Context, messages []ChatMessage) (ChatReply, error)
|
|
|
|
|
Stream(ctx context.Context, messages []ChatMessage) (<-chan ChatStreamEvent, <-chan error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Agent 智能体接口
|
|
|
|
|
type Agent interface {
|
|
|
|
|
Name() string
|
|
|
|
|
Run(ctx context.Context, content ChatContent) (string, error)
|
|
|
|
|
Stream(ctx context.Context, content ChatContent, out chan<- string) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Runner 运行器接口,管理会话并执行 Agent
|
|
|
|
|
type Runner interface {
|
|
|
|
|
CreateSession(userID string) (string, error)
|
|
|
|
|
Run(userID, sessionID string, content ChatContent) ([]string, error)
|
|
|
|
|
Stream(userID, sessionID string, content ChatContent) (<-chan string, <-chan error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================================================
|
2026-06-10 13:41:18 +08:00
|
|
|
// 注册与存储接口
|
2026-06-10 12:49:29 +08:00
|
|
|
// ============================================================
|
|
|
|
|
|
|
|
|
|
// RegisteredAgent 已注册的 Agent 信息
|
|
|
|
|
type RegisteredAgent struct {
|
|
|
|
|
AppName string
|
|
|
|
|
AgentID string
|
|
|
|
|
AgentName string
|
|
|
|
|
AgentDesc string
|
|
|
|
|
Runner Runner
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AgentRegistry Agent 注册表接口
|
|
|
|
|
type AgentRegistry interface {
|
|
|
|
|
Register(agent RegisteredAgent) error
|
|
|
|
|
Get(agentID string) (RegisteredAgent, bool)
|
|
|
|
|
List() []RegisteredAgent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SessionStore 会话存储接口
|
|
|
|
|
type SessionStore interface {
|
|
|
|
|
Get(userID, agentID string) (string, bool)
|
|
|
|
|
Set(userID, agentID, sessionID string) error
|
|
|
|
|
}
|