Documentation
¶
Index ¶
- Variables
- func DecodeValue(src any, dest any) error
- type Config
- type JSONStore
- func (js *JSONStore) Delete(ctx context.Context, collection, key string) error
- func (js *JSONStore) DeleteAgent(ctx context.Context, agentID string) error
- func (js *JSONStore) Exists(ctx context.Context, collection, key string) (bool, error)
- func (js *JSONStore) Get(ctx context.Context, collection, key string, dest any) error
- func (js *JSONStore) List(ctx context.Context, collection string) ([]any, error)
- func (js *JSONStore) ListAgents(ctx context.Context) ([]string, error)
- func (js *JSONStore) ListSnapshots(ctx context.Context, agentID string) ([]types.Snapshot, error)
- func (js *JSONStore) LoadInfo(ctx context.Context, agentID string) (*types.AgentInfo, error)
- func (js *JSONStore) LoadMessages(ctx context.Context, agentID string) ([]types.Message, error)
- func (js *JSONStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
- func (js *JSONStore) LoadTodos(ctx context.Context, agentID string) (any, error)
- func (js *JSONStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
- func (js *JSONStore) SaveInfo(ctx context.Context, agentID string, info types.AgentInfo) error
- func (js *JSONStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
- func (js *JSONStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
- func (js *JSONStore) SaveTodos(ctx context.Context, agentID string, todos any) error
- func (js *JSONStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
- func (js *JSONStore) Set(ctx context.Context, collection, key string, value any) error
- func (js *JSONStore) TrimMessages(ctx context.Context, agentID string, maxMessages int) error
- type RedisConfig
- type RedisStore
- func (rs *RedisStore) Close() error
- func (rs *RedisStore) Delete(ctx context.Context, collection, key string) error
- func (rs *RedisStore) DeleteAgent(ctx context.Context, agentID string) error
- func (rs *RedisStore) Exists(ctx context.Context, collection, key string) (bool, error)
- func (rs *RedisStore) Get(ctx context.Context, collection, key string, dest any) error
- func (rs *RedisStore) List(ctx context.Context, collection string) ([]any, error)
- func (rs *RedisStore) ListAgents(ctx context.Context) ([]string, error)
- func (rs *RedisStore) ListSnapshots(ctx context.Context, agentID string) ([]types.Snapshot, error)
- func (rs *RedisStore) LoadInfo(ctx context.Context, agentID string) (*types.AgentInfo, error)
- func (rs *RedisStore) LoadMessages(ctx context.Context, agentID string) ([]types.Message, error)
- func (rs *RedisStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
- func (rs *RedisStore) LoadTodos(ctx context.Context, agentID string) (any, error)
- func (rs *RedisStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
- func (rs *RedisStore) Ping(ctx context.Context) error
- func (rs *RedisStore) SaveInfo(ctx context.Context, agentID string, info types.AgentInfo) error
- func (rs *RedisStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
- func (rs *RedisStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
- func (rs *RedisStore) SaveTodos(ctx context.Context, agentID string, todos any) error
- func (rs *RedisStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
- func (rs *RedisStore) Set(ctx context.Context, collection, key string, value any) error
- func (rs *RedisStore) TrimMessages(ctx context.Context, agentID string, maxMessages int) error
- type Store
- type StoreError
- type StoreType
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNotFound 资源未找到错误 ErrNotFound = &StoreError{Code: "not_found", Message: "resource not found"} // ErrAlreadyExists 资源已存在错误 ErrAlreadyExists = &StoreError{Code: "already_exists", Message: "resource already exists"} )
Functions ¶
Types ¶
type Config ¶ added in v0.31.0
type Config struct {
Type StoreType `json:"type" yaml:"type"` // Store 类型: json, redis
// JSON Store 配置
DataDir string `json:"data_dir,omitempty" yaml:"data_dir,omitempty"` // 数据目录
// Redis Store 配置
RedisAddr string `json:"redis_addr,omitempty" yaml:"redis_addr,omitempty"` // Redis 地址
RedisPassword string `json:"redis_password,omitempty" yaml:"redis_password,omitempty"` // Redis 密码
RedisDB int `json:"redis_db,omitempty" yaml:"redis_db,omitempty"` // Redis 数据库
RedisPrefix string `json:"redis_prefix,omitempty" yaml:"redis_prefix,omitempty"` // Redis Key 前缀
RedisTTL time.Duration `json:"redis_ttl,omitempty" yaml:"redis_ttl,omitempty"` // Redis 数据过期时间
}
Config Store 配置
type JSONStore ¶
type JSONStore struct {
// contains filtered or unexported fields
}
JSONStore JSON文件存储实现
func (*JSONStore) DeleteAgent ¶
DeleteAgent 删除Agent所有数据
func (*JSONStore) ListAgents ¶
ListAgents 列出所有Agent
func (*JSONStore) ListSnapshots ¶
ListSnapshots 列出快照
func (*JSONStore) LoadMessages ¶
LoadMessages 加载消息列表
func (*JSONStore) LoadSnapshot ¶
func (js *JSONStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
LoadSnapshot 加载快照
func (*JSONStore) LoadToolCallRecords ¶
func (js *JSONStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
LoadToolCallRecords 加载工具调用记录
func (*JSONStore) SaveMessages ¶
func (js *JSONStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
SaveMessages 保存消息列表
func (*JSONStore) SaveSnapshot ¶
func (js *JSONStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
SaveSnapshot 保存快照
func (*JSONStore) SaveToolCallRecords ¶
func (js *JSONStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
SaveToolCallRecords 保存工具调用记录
type RedisConfig ¶ added in v0.31.0
type RedisConfig struct {
Addr string // Redis 地址,格式: "host:port"
Password string // 密码
DB int // 数据库编号 (0-15)
Prefix string // Key 前缀,默认 "aster:"
TTL time.Duration // 数据过期时间,默认 7 天
}
RedisConfig Redis 配置
type RedisStore ¶ added in v0.31.0
type RedisStore struct {
// contains filtered or unexported fields
}
RedisStore Redis 持久化存储 适用于分布式环境,支持多节点共享状态
func NewRedisStore ¶ added in v0.31.0
func NewRedisStore(config RedisConfig) (*RedisStore, error)
NewRedisStore 创建 Redis Store
func (*RedisStore) Delete ¶ added in v0.31.0
func (rs *RedisStore) Delete(ctx context.Context, collection, key string) error
Delete 删除资源
func (*RedisStore) DeleteAgent ¶ added in v0.31.0
func (rs *RedisStore) DeleteAgent(ctx context.Context, agentID string) error
DeleteAgent 删除 Agent 所有数据
func (*RedisStore) ListAgents ¶ added in v0.31.0
func (rs *RedisStore) ListAgents(ctx context.Context) ([]string, error)
ListAgents 列出所有 Agent
func (*RedisStore) ListSnapshots ¶ added in v0.31.0
ListSnapshots 列出快照
func (*RedisStore) LoadMessages ¶ added in v0.31.0
LoadMessages 加载消息列表
func (*RedisStore) LoadSnapshot ¶ added in v0.31.0
func (rs *RedisStore) LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
LoadSnapshot 加载快照
func (*RedisStore) LoadToolCallRecords ¶ added in v0.31.0
func (rs *RedisStore) LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
LoadToolCallRecords 加载工具调用记录
func (*RedisStore) Ping ¶ added in v0.31.0
func (rs *RedisStore) Ping(ctx context.Context) error
Ping 检查 Redis 连接
func (*RedisStore) SaveMessages ¶ added in v0.31.0
func (rs *RedisStore) SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
SaveMessages 保存消息列表
func (*RedisStore) SaveSnapshot ¶ added in v0.31.0
func (rs *RedisStore) SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
SaveSnapshot 保存快照
func (*RedisStore) SaveToolCallRecords ¶ added in v0.31.0
func (rs *RedisStore) SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
SaveToolCallRecords 保存工具调用记录
func (*RedisStore) TrimMessages ¶ added in v0.31.0
TrimMessages 修剪消息列表(原子操作)
type Store ¶
type Store interface {
// SaveMessages 保存消息列表
SaveMessages(ctx context.Context, agentID string, messages []types.Message) error
// LoadMessages 加载消息列表
LoadMessages(ctx context.Context, agentID string) ([]types.Message, error)
// TrimMessages 修剪消息列表,保留最近的 N 条消息
// 如果 maxMessages <= 0,则不修剪
TrimMessages(ctx context.Context, agentID string, maxMessages int) error
// SaveToolCallRecords 保存工具调用记录
SaveToolCallRecords(ctx context.Context, agentID string, records []types.ToolCallRecord) error
// LoadToolCallRecords 加载工具调用记录
LoadToolCallRecords(ctx context.Context, agentID string) ([]types.ToolCallRecord, error)
// SaveSnapshot 保存快照
SaveSnapshot(ctx context.Context, agentID string, snapshot types.Snapshot) error
// LoadSnapshot 加载快照
LoadSnapshot(ctx context.Context, agentID string, snapshotID string) (*types.Snapshot, error)
// ListSnapshots 列出快照
ListSnapshots(ctx context.Context, agentID string) ([]types.Snapshot, error)
// SaveInfo 保存Agent元信息
SaveInfo(ctx context.Context, agentID string, info types.AgentInfo) error
// LoadInfo 加载Agent元信息
LoadInfo(ctx context.Context, agentID string) (*types.AgentInfo, error)
// SaveTodos 保存Todo列表
SaveTodos(ctx context.Context, agentID string, todos any) error
// LoadTodos 加载Todo列表
LoadTodos(ctx context.Context, agentID string) (any, error)
// DeleteAgent 删除Agent所有数据
DeleteAgent(ctx context.Context, agentID string) error
// ListAgents 列出所有Agent
ListAgents(ctx context.Context) ([]string, error)
// Get 获取单个资源
Get(ctx context.Context, collection, key string, dest any) error
// Set 设置资源
Set(ctx context.Context, collection, key string, value any) error
// Delete 删除资源
Delete(ctx context.Context, collection, key string) error
// List 列出资源
List(ctx context.Context, collection string) ([]any, error)
// Exists 检查资源是否存在
Exists(ctx context.Context, collection, key string) (bool, error)
}
Store 持久化存储接口
func MustNewStore ¶ added in v0.31.0
MustNewStore 创建 Store,失败时 panic
type StoreError ¶
StoreError Store 错误类型
func (*StoreError) Error ¶
func (e *StoreError) Error() string
func (*StoreError) Unwrap ¶
func (e *StoreError) Unwrap() error
Click to show internal directories.
Click to hide internal directories.