Documentation
¶
Overview ¶
config 包的 HTTP 配置管理 API。
提供配置查询、更新、热重载触发与变更历史查询能力。
默认配置定义与默认值构造函数。
配置热重载管理器实现。
支持局部更新、变更通知、应用前校验与审计记录。
配置加载器实现。
支持默认值、YAML 文件与环境变量覆盖,并按优先级合并配置。
配置文件变更监听器实现。
基于文件系统事件与轮询兜底机制触发配置重载回调。
Index ¶
- func GetHotReloadableFields() map[string]HotReloadableField
- func IsHotReloadable(path string) bool
- func MaskAPIKey(key string) string
- func MaskSensitive(s string) string
- type AgentConfig
- type ChangeCallback
- type Config
- type ConfigAPIHandler
- func (h *ConfigAPIHandler) HandleChanges(w http.ResponseWriter, r *http.Request)
- func (h *ConfigAPIHandler) HandleConfig(w http.ResponseWriter, r *http.Request)
- func (h *ConfigAPIHandler) HandleFields(w http.ResponseWriter, r *http.Request)
- func (h *ConfigAPIHandler) HandleReload(w http.ResponseWriter, r *http.Request)
- func (h *ConfigAPIHandler) RegisterRoutes(mux *http.ServeMux)
- type ConfigAPIMiddleware
- type ConfigChange
- type ConfigSnapshot
- type ConfigUpdateRequest
- type DatabaseConfig
- type DuckDuckGoToolConfig
- type FieldInfo
- type FileEvent
- type FileOp
- type FileWatcher
- func (w *FileWatcher) AddPath(path string) error
- func (w *FileWatcher) IsRunning() bool
- func (w *FileWatcher) OnChange(callback func(FileEvent))
- func (w *FileWatcher) Paths() []string
- func (w *FileWatcher) RemovePath(path string) error
- func (w *FileWatcher) Start(ctx context.Context) error
- func (w *FileWatcher) Stop() error
- type FirecrawlToolConfig
- type HTTPScrapeToolConfig
- type HotReloadManager
- func (m *HotReloadManager) ApplyConfig(newConfig *Config, source string) error
- func (m *HotReloadManager) GetChangeLog(limit int) []ConfigChange
- func (m *HotReloadManager) GetConfig() *Config
- func (m *HotReloadManager) GetConfigHistory() []ConfigSnapshot
- func (m *HotReloadManager) GetCurrentVersion() int
- func (m *HotReloadManager) OnChange(callback ChangeCallback)
- func (m *HotReloadManager) OnReload(callback ReloadCallback)
- func (m *HotReloadManager) OnRollback(callback RollbackCallback)
- func (m *HotReloadManager) ReloadFromFile() error
- func (m *HotReloadManager) Rollback() error
- func (m *HotReloadManager) RollbackToVersion(version int) error
- func (m *HotReloadManager) SanitizedConfig() map[string]any
- func (m *HotReloadManager) Start(ctx context.Context) error
- func (m *HotReloadManager) Stop() error
- func (m *HotReloadManager) UpdateField(path string, value any) error
- type HotReloadOption
- type HotReloadableField
- type JWTConfig
- type JinaToolConfig
- type LLMConnectionConfig
- type Loader
- type LogConfig
- type MemoryConfig
- type MilvusConfig
- type MongoDBConfig
- type MultimodalConfig
- type MultimodalImageConfig
- type MultimodalVideoConfig
- type QdrantConfig
- type RedisConfig
- type ReloadCallback
- type RollbackCallback
- type RollbackEvent
- type SearXNGToolConfig
- type ServerConfig
- type TavilyToolConfig
- type TelemetryConfig
- type ToolsConfig
- type ValidateFunc
- type WatcherOption
- type WeaviateConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetHotReloadableFields ¶
func GetHotReloadableFields() map[string]HotReloadableField
GetHotReloadableFields 返回可热重载字段的列表
func MaskAPIKey ¶
MaskAPIKey 掩码 API Key,用于日志记录 例如: "sk-1234567890abcdef" -> "sk-123...def"
func MaskSensitive ¶
MaskSensitive 掩码敏感信息,用于日志记录 例如: "mysecretpassword" -> "mys***ord"
Types ¶
type AgentConfig ¶
type AgentConfig struct {
// 名称
Name string `yaml:"name" env:"NAME"`
// 描述
Description string `yaml:"description" env:"DESCRIPTION"`
// 模型名称
Model string `yaml:"model" env:"MODEL"`
// 系统提示词
SystemPrompt string `yaml:"system_prompt" env:"SYSTEM_PROMPT"`
// 最大迭代次数
MaxIterations int `yaml:"max_iterations" env:"MAX_ITERATIONS"`
// 温度参数
Temperature float64 `yaml:"temperature" env:"TEMPERATURE"`
// 最大 Token 数
MaxTokens int `yaml:"max_tokens" env:"MAX_TOKENS"`
// 超时时间
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
// 是否启用流式输出
StreamEnabled bool `yaml:"stream_enabled" env:"STREAM_ENABLED"`
// 记忆配置
Memory MemoryConfig `yaml:"memory" env:"MEMORY"`
}
AgentConfig Agent 配置(与 types.AgentConfig 兼容)
type Config ¶
type Config struct {
// Server 服务器配置
Server ServerConfig `yaml:"server" env:"SERVER"`
// Agent 默认 Agent 配置
Agent AgentConfig `yaml:"agent" env:"AGENT"`
// Redis 配置(缓存与可选的多模态引用存储复用)。
Redis RedisConfig `yaml:"redis" env:"REDIS"`
// Database 数据库配置
Database DatabaseConfig `yaml:"database" env:"DATABASE"`
// Qdrant 向量存储配置
Qdrant QdrantConfig `yaml:"qdrant" env:"QDRANT"`
// Weaviate 向量存储配置
Weaviate WeaviateConfig `yaml:"weaviate" env:"WEAVIATE"`
// Milvus 向量存储配置
Milvus MilvusConfig `yaml:"milvus" env:"MILVUS"`
// MongoDB 文档型数据存储配置
MongoDB MongoDBConfig `yaml:"mongodb" env:"MONGODB"`
// LLM 大语言模型配置
LLM LLMConnectionConfig `yaml:"llm" env:"LLM"`
// Multimodal 多模态框架能力配置
Multimodal MultimodalConfig `yaml:"multimodal" env:"MULTIMODAL"`
// Log 日志配置
Log LogConfig `yaml:"log" env:"LOG"`
// Telemetry 遥测配置
Telemetry TelemetryConfig `yaml:"telemetry" env:"TELEMETRY"`
// Tools 工具提供者配置
Tools ToolsConfig `yaml:"tools" env:"TOOLS"`
}
Config 是 AgentFlow 的完整配置结构
type ConfigAPIHandler ¶
type ConfigAPIHandler struct {
// contains filtered or unexported fields
}
ConfigAPIHandler 处理配置 API 请求
func NewConfigAPIHandler ¶
func NewConfigAPIHandler(manager *HotReloadManager, allowedOrigin ...string) *ConfigAPIHandler
NewConfigAPIHandler 创建一个新的配置 API 处理程序。 allowedOrigin 指定 CORS 允许的来源,为空时默认不设置 Access-Control-Allow-Origin。
func (*ConfigAPIHandler) HandleChanges ¶ added in v1.0.0
func (h *ConfigAPIHandler) HandleChanges(w http.ResponseWriter, r *http.Request)
HandleChanges 返回配置变更历史(导出方法)
func (*ConfigAPIHandler) HandleConfig ¶ added in v1.0.0
func (h *ConfigAPIHandler) HandleConfig(w http.ResponseWriter, r *http.Request)
HandleConfig 处理配置的 GET 和 PUT 请求(导出方法,供外部认证中间件包装使用)
func (*ConfigAPIHandler) HandleFields ¶ added in v1.0.0
func (h *ConfigAPIHandler) HandleFields(w http.ResponseWriter, r *http.Request)
HandleFields 返回可热重载字段列表(导出方法)
func (*ConfigAPIHandler) HandleReload ¶ added in v1.0.0
func (h *ConfigAPIHandler) HandleReload(w http.ResponseWriter, r *http.Request)
HandleReload 处理配置热重载请求(导出方法)
func (*ConfigAPIHandler) RegisterRoutes ¶
func (h *ConfigAPIHandler) RegisterRoutes(mux *http.ServeMux)
RegisterRoutes 注册配置 API 路由
type ConfigAPIMiddleware ¶
type ConfigAPIMiddleware struct {
// contains filtered or unexported fields
}
ConfigAPIMiddleware 为配置API提供中间件
func NewConfigAPIMiddleware ¶
func NewConfigAPIMiddleware(handler *ConfigAPIHandler, apiKey string) *ConfigAPIMiddleware
NewConfigAPIMiddleware 创建一个新的配置API中间件
func (*ConfigAPIMiddleware) LogRequests ¶
func (m *ConfigAPIMiddleware) LogRequests(next http.HandlerFunc, logger func(method, path string, status int, duration time.Duration)) http.HandlerFunc
LogRequests 使用请求日志记录来包装处理程序
func (*ConfigAPIMiddleware) RequireAuth ¶
func (m *ConfigAPIMiddleware) RequireAuth(next http.HandlerFunc) http.HandlerFunc
RequireAuth 使用 API 密钥身份验证包装处理程序
type ConfigChange ¶
type ConfigChange struct {
// 变更的时间戳
Timestamp time.Time `json:"timestamp"`
// 更改的来源(文件、api、env)
Source string `json:"source"`
// 已更改字段的路径(例如“Server.HTTPPort”)
Path string `json:"path"`
// 更改前的 OldValue(可能会对敏感字段进行编辑)
OldValue any `json:"old_value,omitempty"`
// 更改后的 NewValue(可能会对敏感字段进行编辑)
NewValue any `json:"new_value,omitempty"`
// RequiresRestart 指示此更改是否需要重新启动
RequiresRestart bool `json:"requires_restart"`
// 已应用指示是否应用了更改
Applied bool `json:"applied"`
// 如果更改失败则出错
Error string `json:"error,omitempty"`
}
ConfigChange 代表配置更改
type ConfigSnapshot ¶
type ConfigSnapshot struct {
Config *Config `json:"config"`
Timestamp time.Time `json:"timestamp"`
Source string `json:"source"` // 变更来源:file, api, env
Version int `json:"version"` // 递增版本号
Checksum string `json:"checksum"` // 配置内容校验和
}
ConfigSnapshot 配置快照(用于历史记录和回滚)
type ConfigUpdateRequest ¶
ConfigUpdateRequest 代表配置更新请求
type DatabaseConfig ¶
type DatabaseConfig struct {
// 驱动类型: postgres, mysql, sqlite
Driver string `yaml:"driver" env:"DRIVER"`
// 主机
Host string `yaml:"host" env:"HOST"`
// 端口
Port int `yaml:"port" env:"PORT"`
// 用户名
User string `yaml:"user" env:"USER"`
// 密码
Password string `yaml:"password" env:"PASSWORD"`
// 数据库名
Name string `yaml:"name" env:"NAME"`
// SSL 模式
SSLMode string `yaml:"ssl_mode" env:"SSL_MODE"`
// 最大连接数
MaxOpenConns int `yaml:"max_open_conns" env:"MAX_OPEN_CONNS"`
// 最大空闲连接
MaxIdleConns int `yaml:"max_idle_conns" env:"MAX_IDLE_CONNS"`
// 连接最大生命周期
ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime" env:"CONN_MAX_LIFETIME"`
}
DatabaseConfig 数据库配置
func DefaultDatabaseConfig ¶
func DefaultDatabaseConfig() DatabaseConfig
DefaultDatabaseConfig 返回默认数据库配置
func (*DatabaseConfig) SafeDSN ¶
func (d *DatabaseConfig) SafeDSN() string
SafeDSN 返回用于日志记录的安全连接字符串(密码已掩码) 使用此方法而非 DSN() 来记录日志,防止敏感信息泄露
type DuckDuckGoToolConfig ¶ added in v1.0.0
DuckDuckGoToolConfig DuckDuckGo 搜索工具配置(完全免费)
type FieldInfo ¶
type FieldInfo struct {
// Path是字段路径
Path string `json:"path"`
// 字段描述
Description string `json:"description"`
// RequiresRestart 指示更改是否需要重新启动
RequiresRestart bool `json:"requires_restart"`
// Sensitive 表示该字段是否敏感
Sensitive bool `json:"sensitive"`
// CurrentValue 是当前值(如果敏感则进行编辑)
CurrentValue any `json:"current_value,omitempty"`
}
FieldInfo 提供有关配置字段的信息
type FileEvent ¶
type FileEvent struct {
// Path是改变的文件路径
Path string `json:"path"`
// op 是操作类型
Op FileOp `json:"op"`
// 时间戳是事件发生的时间
Timestamp time.Time `json:"timestamp"`
// 检测过程中如有错误
Error error `json:"error,omitempty"`
}
FileEvent 代表文件更改事件
type FileWatcher ¶
type FileWatcher struct {
// contains filtered or unexported fields
}
FileWatcher 监视配置文件的更改
func NewFileWatcher ¶
func NewFileWatcher(paths []string, opts ...WatcherOption) (*FileWatcher, error)
NewFileWatcher 创建一个新的文件观察器
func (*FileWatcher) OnChange ¶
func (w *FileWatcher) OnChange(callback func(FileEvent))
OnChange 注册文件更改事件的回调
func (*FileWatcher) RemovePath ¶
func (w *FileWatcher) RemovePath(path string) error
RemovePath 从观看中删除一条路径
type FirecrawlToolConfig ¶ added in v1.0.0
type FirecrawlToolConfig struct {
// API Key(建议使用环境变量 AGENTFLOW_TOOLS_FIRECRAWL_API_KEY)
APIKey string `yaml:"api_key" env:"API_KEY" json:"-"`
// 基础 URL(可选,默认 https://api.firecrawl.dev)
BaseURL string `yaml:"base_url" env:"BASE_URL"`
// 请求超时
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
}
FirecrawlToolConfig Firecrawl 工具配置
type HTTPScrapeToolConfig ¶ added in v1.0.0
type HTTPScrapeToolConfig struct {
// 自定义 User-Agent
UserAgent string `yaml:"user_agent" env:"USER_AGENT"`
// 请求超时
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
}
HTTPScrapeToolConfig 纯 HTTP 抓取工具配置(零依赖,无需 API Key)
type HotReloadManager ¶
type HotReloadManager struct {
// contains filtered or unexported fields
}
HotReloadManager 管理配置热重载
func NewHotReloadManager ¶
func NewHotReloadManager(config *Config, opts ...HotReloadOption) *HotReloadManager
NewHotReloadManager 创建一个新的热重载管理器
func (*HotReloadManager) ApplyConfig ¶
func (m *HotReloadManager) ApplyConfig(newConfig *Config, source string) error
ApplyConfig 应用新配置 修复 TOCTOU 竞态:validate、apply、pushHistory 和 changeLog 更新 全部在同一把锁内完成,确保原子性。回调通知在锁外执行以避免死锁。
func (*HotReloadManager) GetChangeLog ¶
func (m *HotReloadManager) GetChangeLog(limit int) []ConfigChange
GetChangeLog 返回配置变更日志
func (*HotReloadManager) GetConfig ¶
func (m *HotReloadManager) GetConfig() *Config
GetConfig 返回当前配置
func (*HotReloadManager) GetConfigHistory ¶
func (m *HotReloadManager) GetConfigHistory() []ConfigSnapshot
GetConfigHistory 获取配置变更历史
func (*HotReloadManager) GetCurrentVersion ¶
func (m *HotReloadManager) GetCurrentVersion() int
GetCurrentVersion 获取当前配置版本号
func (*HotReloadManager) OnChange ¶
func (m *HotReloadManager) OnChange(callback ChangeCallback)
OnChange 注册配置更改的回调
func (*HotReloadManager) OnReload ¶
func (m *HotReloadManager) OnReload(callback ReloadCallback)
OnReload 注册配置重新加载的回调
func (*HotReloadManager) OnRollback ¶
func (m *HotReloadManager) OnRollback(callback RollbackCallback)
OnRollback 注册回滚事件回调
func (*HotReloadManager) ReloadFromFile ¶
func (m *HotReloadManager) ReloadFromFile() error
ReloadFromFile 从文件重新加载配置
func (*HotReloadManager) RollbackToVersion ¶
func (m *HotReloadManager) RollbackToVersion(version int) error
RollbackToVersion 回滚到指定版本
func (*HotReloadManager) SanitizedConfig ¶
func (m *HotReloadManager) SanitizedConfig() map[string]any
SanitizedConfig 返回包含敏感字段的配置副本
func (*HotReloadManager) Start ¶
func (m *HotReloadManager) Start(ctx context.Context) error
Start 启动热重载管理器
func (*HotReloadManager) UpdateField ¶
func (m *HotReloadManager) UpdateField(path string, value any) error
UpdateField 更新单个配置字段
type HotReloadOption ¶
type HotReloadOption func(*HotReloadManager)
HotReloadOption 配置 HotReloadManager
func WithHotReloadLogger ¶
func WithHotReloadLogger(logger *zap.Logger) HotReloadOption
WithHotReloadLogger 设置记录器
func WithMaxHistorySize ¶
func WithMaxHistorySize(size int) HotReloadOption
WithMaxHistorySize 设置配置历史最大记录数
func WithValidateFunc ¶
func WithValidateFunc(fn ValidateFunc) HotReloadOption
WithValidateFunc 设置配置验证钩子
type HotReloadableField ¶
type HotReloadableField struct {
// Path 是字段路径(例如“Log.Level”)
Path string
// 字段描述
Description string
// RequiresRestart 指示更改此字段是否需要重新启动
RequiresRestart bool
// Sensitive 表示该字段是否包含敏感数据
Sensitive bool
// Validator 是可选的校验函数
Validator func(value any) error
}
HotReloadableField 定义哪些字段可以热重载
type JWTConfig ¶ added in v1.0.0
type JWTConfig struct {
// HMAC 签名密钥
Secret string `yaml:"secret" env:"SECRET" json:"-"`
// RSA 公钥(PEM 格式)
PublicKey string `yaml:"public_key" env:"PUBLIC_KEY" json:"-"`
// 期望的签发者
Issuer string `yaml:"issuer" env:"ISSUER" json:"issuer,omitempty"`
// 期望的受众
Audience string `yaml:"audience" env:"AUDIENCE" json:"audience,omitempty"`
}
JWTConfig JWT 认证配置
type JinaToolConfig ¶ added in v1.0.0
type JinaToolConfig struct {
// API Key(建议使用环境变量 AGENTFLOW_TOOLS_JINA_API_KEY)
APIKey string `yaml:"api_key" env:"API_KEY" json:"-"`
// 基础 URL(可选,默认 https://r.jina.ai)
BaseURL string `yaml:"base_url" env:"BASE_URL"`
// 请求超时
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
}
JinaToolConfig Jina Reader 工具配置
type LLMConnectionConfig ¶ added in v1.2.0
type LLMConnectionConfig struct {
// 默认 Provider
DefaultProvider string `yaml:"default_provider" env:"DEFAULT_PROVIDER"`
// API Key(通用)
APIKey string `yaml:"api_key" env:"API_KEY"`
// 基础 URL(可选)
BaseURL string `yaml:"base_url" env:"BASE_URL"`
// 请求超时
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
// 最大重试次数
MaxRetries int `yaml:"max_retries" env:"MAX_RETRIES"`
}
LLMConnectionConfig 连接级 LLM 配置(YAML 反序列化用)。 注意:与 types.LLMConfig(运行时 Agent 配置)和 llm/config.LLMConfig(路由/降级配置)不同, 此结构体仅用于应用启动时的连接参数加载。
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader 配置加载器(Builder 模式)
func (*Loader) WithConfigPath ¶
WithConfigPath 设置配置文件路径
func (*Loader) WithEnvPrefix ¶
WithEnvPrefix 设置环境变量前缀
type LogConfig ¶
type LogConfig struct {
// 日志级别: debug, info, warn, error
Level string `yaml:"level" env:"LEVEL"`
// 输出格式: json, console
Format string `yaml:"format" env:"FORMAT"`
// 输出路径
OutputPaths []string `yaml:"output_paths" env:"OUTPUT_PATHS"`
// 是否启用调用者信息
EnableCaller bool `yaml:"enable_caller" env:"ENABLE_CALLER"`
// 是否启用堆栈跟踪
EnableStacktrace bool `yaml:"enable_stacktrace" env:"ENABLE_STACKTRACE"`
}
LogConfig 日志配置
type MemoryConfig ¶
type MemoryConfig struct {
// 是否启用
Enabled bool `yaml:"enabled" env:"ENABLED"`
// 类型: buffer, summary, vector
Type string `yaml:"type" env:"TYPE"`
// 最大消息数
MaxMessages int `yaml:"max_messages" env:"MAX_MESSAGES"`
// Token 限制
TokenLimit int `yaml:"token_limit" env:"TOKEN_LIMIT"`
}
MemoryConfig 记忆配置
type MilvusConfig ¶
type MilvusConfig struct {
// 主机
Host string `yaml:"host" env:"HOST"`
// gRPC 端口
Port int `yaml:"port" env:"PORT"`
// 用户名(可选)
Username string `yaml:"username" env:"USERNAME"`
// 密码(可选)
Password string `yaml:"password" env:"PASSWORD"`
// Token(用于 Zilliz Cloud)
Token string `yaml:"token" env:"TOKEN"`
// 数据库名
Database string `yaml:"database" env:"DATABASE"`
// 默认集合名
Collection string `yaml:"collection" env:"COLLECTION"`
// 向量维度
VectorDimension int `yaml:"vector_dimension" env:"VECTOR_DIMENSION"`
// 索引类型: IVF_FLAT, HNSW, FLAT, IVF_SQ8, IVF_PQ
IndexType string `yaml:"index_type" env:"INDEX_TYPE"`
// 距离度量: L2, IP, COSINE
MetricType string `yaml:"metric_type" env:"METRIC_TYPE"`
// 是否自动创建集合
AutoCreateCollection bool `yaml:"auto_create_collection" env:"AUTO_CREATE_COLLECTION"`
// 请求超时
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
// 批量操作大小
BatchSize int `yaml:"batch_size" env:"BATCH_SIZE"`
// 一致性级别: Strong, Session, Bounded, Eventually
ConsistencyLevel string `yaml:"consistency_level" env:"CONSISTENCY_LEVEL"`
}
MilvusConfig Milvus 向量存储配置
func DefaultMilvusConfig ¶
func DefaultMilvusConfig() MilvusConfig
DefaultMilvusConfig 返回默认 Milvus 配置
type MongoDBConfig ¶ added in v1.1.0
type MongoDBConfig struct {
// 连接 URI(优先级最高,设置后忽略 Host/Port/User/Password)
URI string `yaml:"uri" env:"URI"`
// 主机
Host string `yaml:"host" env:"HOST"`
// 端口
Port int `yaml:"port" env:"PORT"`
// 用户名
User string `yaml:"user" env:"USER"`
// 密码
Password string `yaml:"password" env:"PASSWORD"`
// 数据库名
Database string `yaml:"database" env:"DATABASE"`
// 认证数据库
AuthSource string `yaml:"auth_source" env:"AUTH_SOURCE"`
// 副本集名称(可选)
ReplicaSet string `yaml:"replica_set" env:"REPLICA_SET"`
// 最大连接池大小
MaxPoolSize int `yaml:"max_pool_size" env:"MAX_POOL_SIZE"`
// 最小连接池大小
MinPoolSize int `yaml:"min_pool_size" env:"MIN_POOL_SIZE"`
// 连接超时
ConnectTimeout time.Duration `yaml:"connect_timeout" env:"CONNECT_TIMEOUT"`
// 请求超时
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
// 健康检查间隔
HealthCheckInterval time.Duration `yaml:"health_check_interval" env:"HEALTH_CHECK_INTERVAL"`
// 是否启用 TLS
TLSEnabled bool `yaml:"tls_enabled" env:"TLS_ENABLED"`
// TLS CA 证书路径
TLSCAFile string `yaml:"tls_ca_file" env:"TLS_CA_FILE"`
// TLS 客户端证书路径
TLSCertFile string `yaml:"tls_cert_file" env:"TLS_CERT_FILE"`
// TLS 客户端密钥路径
TLSKeyFile string `yaml:"tls_key_file" env:"TLS_KEY_FILE"`
}
MongoDBConfig MongoDB 文档型数据存储配置
func DefaultMongoDBConfig ¶ added in v1.1.0
func DefaultMongoDBConfig() MongoDBConfig
DefaultMongoDBConfig 返回默认 MongoDB 配置
type MultimodalConfig ¶ added in v1.2.0
type MultimodalConfig struct {
// 是否启用多模态 API 路由
Enabled bool `yaml:"enabled" env:"ENABLED"`
// 引用图上传的最大字节数
ReferenceMaxSizeBytes int64 `yaml:"reference_max_size_bytes" env:"REFERENCE_MAX_SIZE_BYTES"`
// 引用图默认存活时长
ReferenceTTL time.Duration `yaml:"reference_ttl" env:"REFERENCE_TTL"`
// 引用图存储后端(仅支持 redis)
ReferenceStoreBackend string `yaml:"reference_store_backend" env:"REFERENCE_STORE_BACKEND"`
// 引用图存储 key 前缀(Redis 后端使用)
ReferenceStoreKeyPrefix string `yaml:"reference_store_key_prefix" env:"REFERENCE_STORE_KEY_PREFIX"`
// 默认图像提供商标识(openai/gemini 等)
DefaultImageProvider string `yaml:"default_image_provider" env:"DEFAULT_IMAGE_PROVIDER"`
// 默认视频提供商标识(runway/veo 等)
DefaultVideoProvider string `yaml:"default_video_provider" env:"DEFAULT_VIDEO_PROVIDER"`
// 图像提供商配置
Image MultimodalImageConfig `yaml:"image" env:"IMAGE"`
// 视频提供商配置
Video MultimodalVideoConfig `yaml:"video" env:"VIDEO"`
}
MultimodalConfig 多模态框架配置(能力层,不绑定具体业务)。
func DefaultMultimodalConfig ¶ added in v1.2.0
func DefaultMultimodalConfig() MultimodalConfig
DefaultMultimodalConfig 返回默认多模态框架配置
type MultimodalImageConfig ¶ added in v1.3.0
type MultimodalVideoConfig ¶ added in v1.3.0
type QdrantConfig ¶
type QdrantConfig struct {
// 主机
Host string `yaml:"host" env:"HOST"`
// gRPC 端口
Port int `yaml:"port" env:"PORT"`
// API Key(可选)
APIKey string `yaml:"api_key" env:"API_KEY"`
// 默认集合名
Collection string `yaml:"collection" env:"COLLECTION"`
}
QdrantConfig Qdrant 向量存储配置
func DefaultQdrantConfig ¶
func DefaultQdrantConfig() QdrantConfig
DefaultQdrantConfig 返回默认 Qdrant 配置
type RedisConfig ¶
type RedisConfig struct {
// 地址
Addr string `yaml:"addr" env:"ADDR"`
// 密码
Password string `yaml:"password" env:"PASSWORD"`
// 数据库编号
DB int `yaml:"db" env:"DB"`
// 连接池大小
PoolSize int `yaml:"pool_size" env:"POOL_SIZE"`
// 最小空闲连接
MinIdleConns int `yaml:"min_idle_conns" env:"MIN_IDLE_CONNS"`
}
RedisConfig Redis 配置
type ReloadCallback ¶
type ReloadCallback func(oldConfig, newConfig *Config)
ReloadCallback 重新加载配置后调用
type RollbackEvent ¶
type RollbackEvent struct {
Timestamp time.Time `json:"timestamp"`
Reason string `json:"reason"`
FailedConfig *Config `json:"failed_config"`
RestoredConfig *Config `json:"restored_config"`
Version int `json:"version"`
Error error `json:"error,omitempty"`
}
RollbackEvent 回滚事件
type SearXNGToolConfig ¶ added in v1.0.0
type SearXNGToolConfig struct {
// SearXNG 实例地址(必填,如 https://searx.example.com)
BaseURL string `yaml:"base_url" env:"BASE_URL"`
// 请求超时
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
}
SearXNGToolConfig SearXNG 搜索工具配置(自托管,无需 API Key)
type ServerConfig ¶
type ServerConfig struct {
// HTTP 端口
HTTPPort int `yaml:"http_port" env:"HTTP_PORT"`
// gRPC 端口 — Reserved for future gRPC support, not currently used.
GRPCPort int `yaml:"grpc_port" env:"GRPC_PORT"`
// Metrics 端口
MetricsPort int `yaml:"metrics_port" env:"METRICS_PORT"`
// 读取超时
ReadTimeout time.Duration `yaml:"read_timeout" env:"READ_TIMEOUT"`
// 写入超时
WriteTimeout time.Duration `yaml:"write_timeout" env:"WRITE_TIMEOUT"`
// 优雅关闭超时
ShutdownTimeout time.Duration `yaml:"shutdown_timeout" env:"SHUTDOWN_TIMEOUT"`
// CORS 允许的源
CORSAllowedOrigins []string `yaml:"cors_allowed_origins" json:"cors_allowed_origins,omitempty"`
// API 密钥
APIKeys []string `yaml:"api_keys" json:"api_keys,omitempty"`
// 是否允许从 URL Query 读取 API Key(默认 false,出于安全考虑)
AllowQueryAPIKey bool `yaml:"allow_query_api_key" env:"ALLOW_QUERY_API_KEY" json:"allow_query_api_key,omitempty"`
// 限流 RPS,默认 100
RateLimitRPS int `yaml:"rate_limit_rps" json:"rate_limit_rps,omitempty"`
// 限流 Burst,默认 200
RateLimitBurst int `yaml:"rate_limit_burst" json:"rate_limit_burst,omitempty"`
// JWT 认证配置
JWT JWTConfig `yaml:"jwt" json:"jwt,omitempty"`
// 租户级限流 RPS,默认 50
TenantRateLimitRPS int `yaml:"tenant_rate_limit_rps" json:"tenant_rate_limit_rps,omitempty"`
// 租户级限流 Burst,默认 100
TenantRateLimitBurst int `yaml:"tenant_rate_limit_burst" json:"tenant_rate_limit_burst,omitempty"`
// AllowNoAuth 允许在无认证配置时启动(默认 false)。
// 生产环境必须显式设置为 true 才能在无 JWT/API Key 配置时启动。
AllowNoAuth bool `yaml:"allow_no_auth" env:"ALLOW_NO_AUTH" json:"allow_no_auth,omitempty"`
}
ServerConfig 服务器配置
type TavilyToolConfig ¶ added in v1.0.0
type TavilyToolConfig struct {
// API Key(建议使用环境变量 AGENTFLOW_TOOLS_TAVILY_API_KEY)
APIKey string `yaml:"api_key" env:"API_KEY" json:"-"`
// 基础 URL(可选,默认 https://api.tavily.com)
BaseURL string `yaml:"base_url" env:"BASE_URL"`
// 请求超时
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
}
TavilyToolConfig Tavily 搜索工具配置
type TelemetryConfig ¶
type TelemetryConfig struct {
// 是否启用
Enabled bool `yaml:"enabled" env:"ENABLED"`
// OTLP 端点
OTLPEndpoint string `yaml:"otlp_endpoint" env:"OTLP_ENDPOINT"`
// 是否使用非加密连接(仅用于开发/测试环境)
OTLPInsecure bool `yaml:"otlp_insecure" env:"OTLP_INSECURE"`
// 服务名称
ServiceName string `yaml:"service_name" env:"SERVICE_NAME"`
// 采样率
SampleRate float64 `yaml:"sample_rate" env:"SAMPLE_RATE"`
}
TelemetryConfig 遥测配置
func DefaultTelemetryConfig ¶
func DefaultTelemetryConfig() TelemetryConfig
DefaultTelemetryConfig 返回默认遥测配置
type ToolsConfig ¶ added in v1.0.0
type ToolsConfig struct {
// Tavily 搜索配置(需要 API Key)
Tavily TavilyToolConfig `yaml:"tavily" env:"TAVILY"`
// Jina Reader 抓取配置(可选 API Key,免费可用)
Jina JinaToolConfig `yaml:"jina" env:"JINA"`
// Firecrawl 搜索+抓取配置(需要 API Key)
Firecrawl FirecrawlToolConfig `yaml:"firecrawl" env:"FIRECRAWL"`
// DuckDuckGo 搜索配置(完全免费,无需 API Key)
DuckDuckGo DuckDuckGoToolConfig `yaml:"duckduckgo" env:"DUCKDUCKGO"`
// SearXNG 搜索配置(自托管,无需 API Key)
SearXNG SearXNGToolConfig `yaml:"searxng" env:"SEARXNG"`
// HTTP 抓取配置(纯 HTTP,无需 API Key)
HTTPScrape HTTPScrapeToolConfig `yaml:"http_scrape" env:"HTTP_SCRAPE"`
}
ToolsConfig 工具提供者配置
func DefaultToolsConfig ¶ added in v1.0.0
func DefaultToolsConfig() ToolsConfig
DefaultToolsConfig 返回默认工具提供者配置
type ValidateFunc ¶
ValidateFunc 配置验证钩子函数 接收新配置,返回 error 表示验证失败
type WatcherOption ¶
type WatcherOption func(*FileWatcher)
WatcherOption 配置文件观察器
func WithDebounceDelay ¶
func WithDebounceDelay(d time.Duration) WatcherOption
WithDebounceDelay 设置文件事件的去抖延迟
func WithWatcherLogger ¶
func WithWatcherLogger(logger *zap.Logger) WatcherOption
WithWatcherLogger 设置观察者的记录器
type WeaviateConfig ¶
type WeaviateConfig struct {
// 主机
Host string `yaml:"host" env:"HOST"`
// HTTP 端口
Port int `yaml:"port" env:"PORT"`
// 协议: http 或 https
Scheme string `yaml:"scheme" env:"SCHEME"`
// API Key(可选)
APIKey string `yaml:"api_key" env:"API_KEY"`
// 默认类名(集合名)
ClassName string `yaml:"class_name" env:"CLASS_NAME"`
// 是否自动创建 Schema
AutoCreateSchema bool `yaml:"auto_create_schema" env:"AUTO_CREATE_SCHEMA"`
// 距离度量: cosine, dot, l2
Distance string `yaml:"distance" env:"DISTANCE"`
// 混合搜索 Alpha 值 (0=BM25, 1=向量)
HybridAlpha float64 `yaml:"hybrid_alpha" env:"HYBRID_ALPHA"`
// 请求超时
Timeout time.Duration `yaml:"timeout" env:"TIMEOUT"`
}
WeaviateConfig Weaviate 向量存储配置
func DefaultWeaviateConfig ¶
func DefaultWeaviateConfig() WeaviateConfig
DefaultWeaviateConfig 返回默认 Weaviate 配置