agents

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 32 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ChatFlowName = "Chat"
View Source
const (
	MetaKeyCurrentModelUsage = "currentModelUsage"
)
View Source
const SessionFileName = "session.json"

SessionFileName 会话文件名

View Source
const SessionsDirName = "sessions"

SessionsDirName 会话存储目录名

Variables

View Source
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 系统提示模版

View Source
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

func GetMetaIntValue(meta any, key string) int

GetMetaIntValue 从 _meta 中获取指定 key 的整数值

func GetMetaStringValue

func GetMetaStringValue(meta any, key string) string

GetMetaStringValue 从 _meta 中获取指定 key 的字符串值

func GetMetaValue

func GetMetaValue(meta any, key string) any

GetMetaValue 从 _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

func SaveSession(sessionsDir string, sessionID acp.SessionId, history []*ai.Message) error

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 NewNFA

func NewNFA(opts Options) *NFAAgent

NewNFA 创建 NFA Agent

func (*NFAAgent) Authenticate

Authenticate 认证

func (*NFAAgent) AvailableModels

func (a *NFAAgent) AvailableModels() []models.ModelConfig

AvailableModels 获取可用模型列表

func (*NFAAgent) Cancel

func (a *NFAAgent) Cancel(_ context.Context, params acp.CancelNotification) error

Cancel 取消

func (*NFAAgent) CloseSession added in v0.5.0

CloseSession 关闭会话

func (*NFAAgent) ConnectClientIO added in v0.2.0

func (a *NFAAgent) ConnectClientIO(in io.Reader, out io.Writer)

ConnectClientIO 连接客户端输入输出流

func (*NFAAgent) InitGenkit

func (a *NFAAgent) InitGenkit(ctx context.Context)

InitGenkit 初始化 genkit

func (*NFAAgent) Initialize

Initialize 初始化连接

func (*NFAAgent) ListSessions added in v0.5.0

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

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

ResumeSession 恢复会话

func (*NFAAgent) SetClient added in v0.2.0

func (a *NFAAgent) SetClient(client acp.Client)

SetClient 设置客户端

func (*NFAAgent) SetSessionConfigOption added in v0.5.0

SetSessionConfigOption 设置会话选项

func (*NFAAgent) SetSessionMode

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 运行选项

func (*Options) Complete

func (opts *Options) Complete()

Complete 使用默认值补全选项

type Session

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

Session 会话

type SessionData added in v0.1.1

type SessionData struct {
	Messages []*ai.Message `json:"messages"`
}

SessionData 会话持久化数据结构

func LoadSessionData added in v0.1.1

func LoadSessionData(sessionsDir string, sessionID acp.SessionId) (*SessionData, error)

LoadSessionData 从文件加载会话数据

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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