Documentation
¶
Index ¶
- Constants
- Variables
- func AnalystSystemPrompt(sl *skills.SkillLoader, longTermMemory, dailyMemory string) func(context.Context, any) (string, error)
- func GetMetaCurrentModelUsageValue(meta any) (tokentracker.Summary, bool)
- func GetMetaIntValue(meta any, key string) int
- func GetMetaStringValue(meta any, key string) string
- func GetMetaValue(meta any, key string) any
- func NewAgentSystemPrompt(data AgentSystemPromptData) (string, error)
- func NewGenkitWithModels(ctx context.Context, providers []models.ModelProvider, ...) (*genkit.Genkit, []models.ModelConfig)
- func SaveSession(sessionsDir string, sessionID acp.SessionId, history []*ai.Message) error
- func SetMetaCurrentModelUsage(meta any, summary tokentracker.Summary)
- type AgentSystemPromptData
- type DataProviders
- type NFAAgent
- func (a *NFAAgent) Authenticate(_ context.Context, _ acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
- func (a *NFAAgent) AvailableModels() []models.ModelConfig
- func (a *NFAAgent) Cancel(_ context.Context, params acp.CancelNotification) error
- func (a *NFAAgent) CloseSession(_ context.Context, _ acp.CloseSessionRequest) (acp.CloseSessionResponse, error)
- func (a *NFAAgent) ConnectClientIO(in io.Reader, out io.Writer)
- func (a *NFAAgent) InitGenkit(ctx context.Context)
- func (a *NFAAgent) Initialize(ctx context.Context, _ acp.InitializeRequest) (acp.InitializeResponse, error)
- func (a *NFAAgent) ListSessions(_ context.Context, _ acp.ListSessionsRequest) (acp.ListSessionsResponse, error)
- func (a *NFAAgent) LoadSession(ctx context.Context, params acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
- func (a *NFAAgent) NewSession(ctx context.Context, _ acp.NewSessionRequest) (acp.NewSessionResponse, error)
- func (a *NFAAgent) Prompt(ctx context.Context, params acp.PromptRequest) (acp.PromptResponse, error)
- func (a *NFAAgent) ResumeSession(_ context.Context, _ acp.ResumeSessionRequest) (acp.ResumeSessionResponse, error)
- func (a *NFAAgent) SetClient(client acp.Client)
- func (a *NFAAgent) SetSessionConfigOption(_ context.Context, _ acp.SetSessionConfigOptionRequest) (acp.SetSessionConfigOptionResponse, error)
- func (a *NFAAgent) SetSessionMode(_ context.Context, _ acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
- type Options
- type Session
- type SessionData
Constants ¶
const ChatFlowName = "Chat"
const (
MetaKeyCurrentModelUsage = "currentModelUsage"
)
const SessionFileName = "session.json"
SessionFileName 会话文件名
const SessionsDirName = "sessions"
SessionsDirName 会话存储目录名
Variables ¶
var AgentSystemPromptTpl = template.Must(template.New("AgentSystemPrompt"). Funcs(template.FuncMap{ "add": func(a, b int) int { return a + b }, }). Parse(`{{ .Overview }} ## 目标 {{ .Goal }} ## 回答流程 {{- range $i, $v := .Workflow }} {{ add $i 1 }}. {{ $v }} {{- end }} ## 严格遵循以下要求进行回答 {{- range .Requirements }} - {{ . }} {{- end }} {{- if .Skills }} ## 可用技能 你可以通过调用 Skill 工具加载技能来扩展你的能力,当用户问题匹配技能描述时尽可能在开始查询或分析前先加载技能,在分析过程中发现匹配也可在分析过程中加载。 当需要使用某个技能时,调用 Skill 工具并传入以下列出的技能名称,工具会返回技能内容: {{- range .Skills }} - {{ .Name }}: {{ .Description }} {{- end }} {{- end }} {{- if .Extra }} {{ .Extra }} {{- end }} {{- if .LongTermMemory }} ## 记忆 以下是对用户的长期记忆,可在回答时参考这些信息提供更个性化的建议,但注意这些信息可能存在过时或偏差: {{ .LongTermMemory }} {{- end }} {{- if .DailyMemory }} ## 近期动态 以下是对用户最近数天的中期记忆,可帮助你了解用户近期的关注点和上下文,但注意这些信息可能存在偏差或滞后: {{ .DailyMemory }} {{- end }} ## 其它信息 - 当前时间: {{ .Time }} `))
AgentSystemPromptTpl Agent 系统提示模版
var (
MsgCmdDescClear = &i18n.Message{
ID: "ui.chat.CmdDescClear",
Other: "Start a fresh conversation",
}
)
Functions ¶
func AnalystSystemPrompt ¶
func AnalystSystemPrompt( sl *skills.SkillLoader, longTermMemory, dailyMemory string, ) func(context.Context, any) (string, error)
AnalystSystemPrompt 分析师系统提示
func GetMetaCurrentModelUsageValue ¶
func GetMetaCurrentModelUsageValue(meta any) (tokentracker.Summary, bool)
GetMetaCurrentModelUsageValue 从 _meta 中获取当前模型用量
func GetMetaIntValue ¶ added in v0.2.0
GetMetaIntValue 从 _meta 中获取指定 key 的整数值
func GetMetaStringValue ¶
GetMetaStringValue 从 _meta 中获取指定 key 的字符串值
func NewAgentSystemPrompt ¶
func NewAgentSystemPrompt(data AgentSystemPromptData) (string, error)
NewAgentSystemPrompt 创建 Agent 系统提示
func NewGenkitWithModels ¶
func NewGenkitWithModels( ctx context.Context, providers []models.ModelProvider, defaultModels models.Models, ) (*genkit.Genkit, []models.ModelConfig)
NewGenkitWithModels 创建 genkit 对象并注册模型
func SaveSession ¶ added in v0.1.1
SaveSession 保存会话到文件
func SetMetaCurrentModelUsage ¶
func SetMetaCurrentModelUsage(meta any, summary tokentracker.Summary)
SetMetaCurrentModelUsage 往 _meta 设置当前模型用量
Types ¶
type AgentSystemPromptData ¶
type AgentSystemPromptData struct {
// 能力概述
Overview string
// 目标
Goal string
// 工作流程
Workflow []string
// 要求
Requirements []string
// 技能列表
Skills []skills.SkillMeta
// 额外信息
Extra string
// 长期记忆
LongTermMemory string
// 近期每日动态(中期记忆)
DailyMemory string
// 当前时间
Time string
}
AgentSystemPromptData 组装 Agent 系统提示的数据
type DataProviders ¶ added in v0.1.1
type DataProviders struct {
AlphaVantage *alphavantage.Options `json:"alphaVantage,omitempty"`
TencentCloudWSA *websearch.TencentCloudWSAOptions `json:"tcloudWSA,omitempty"`
}
DataProviders 数据供应商配置
type NFAAgent ¶
type NFAAgent struct {
// contains filtered or unexported fields
}
NFAAgent NFA Agent
func (*NFAAgent) Authenticate ¶
func (a *NFAAgent) Authenticate(_ context.Context, _ acp.AuthenticateRequest) (acp.AuthenticateResponse, error)
Authenticate 认证
func (*NFAAgent) AvailableModels ¶
func (a *NFAAgent) AvailableModels() []models.ModelConfig
AvailableModels 获取可用模型列表
func (*NFAAgent) CloseSession ¶ added in v0.5.0
func (a *NFAAgent) CloseSession(_ context.Context, _ acp.CloseSessionRequest) (acp.CloseSessionResponse, error)
CloseSession 关闭会话
func (*NFAAgent) ConnectClientIO ¶ added in v0.2.0
ConnectClientIO 连接客户端输入输出流
func (*NFAAgent) InitGenkit ¶
InitGenkit 初始化 genkit
func (*NFAAgent) Initialize ¶
func (a *NFAAgent) Initialize(ctx context.Context, _ acp.InitializeRequest) (acp.InitializeResponse, error)
Initialize 初始化连接
func (*NFAAgent) ListSessions ¶ added in v0.5.0
func (a *NFAAgent) ListSessions(_ context.Context, _ acp.ListSessionsRequest) (acp.ListSessionsResponse, error)
ListSessions 列出会话
func (*NFAAgent) LoadSession ¶ added in v0.1.1
func (a *NFAAgent) LoadSession(ctx context.Context, params acp.LoadSessionRequest) (acp.LoadSessionResponse, error)
LoadSession 加载已有会话
func (*NFAAgent) NewSession ¶
func (a *NFAAgent) NewSession(ctx context.Context, _ acp.NewSessionRequest) (acp.NewSessionResponse, error)
NewSession 创建会话
func (*NFAAgent) Prompt ¶
func (a *NFAAgent) Prompt(ctx context.Context, params acp.PromptRequest) (acp.PromptResponse, error)
Prompt 对话
func (*NFAAgent) ResumeSession ¶ added in v0.5.0
func (a *NFAAgent) ResumeSession(_ context.Context, _ acp.ResumeSessionRequest) (acp.ResumeSessionResponse, error)
ResumeSession 恢复会话
func (*NFAAgent) SetSessionConfigOption ¶ added in v0.5.0
func (a *NFAAgent) SetSessionConfigOption( _ context.Context, _ acp.SetSessionConfigOptionRequest, ) (acp.SetSessionConfigOptionResponse, error)
SetSessionConfigOption 设置会话选项
func (*NFAAgent) SetSessionMode ¶
func (a *NFAAgent) SetSessionMode(_ context.Context, _ acp.SetSessionModeRequest) (acp.SetSessionModeResponse, error)
SetSessionMode 设置会话模式
type Options ¶
type Options struct {
Logger logr.Logger
Localizer *i18n.Localizer
ModelProviders []models.ModelProvider
DataProviders DataProviders
DefaultModels models.Models
DataRoot string
MaxContextWindow int64
}
Options Agent 运行选项
type SessionData ¶ added in v0.1.1
SessionData 会话持久化数据结构
func LoadSessionData ¶ added in v0.1.1
func LoadSessionData(sessionsDir string, sessionID acp.SessionId) (*SessionData, error)
LoadSessionData 从文件加载会话数据