agents

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetaKeyCurrentModels     = "currentModels"
	MetaKeyAvailableModels   = "availableModels"
	MetaKeyCurrentModelUsage = "currentModelUsage"
	MetaKeySkills            = "skills"
)
View Source
const ChatFlowName = "Chat"
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 }}

## 其它信息
- 当前时间: {{ .Time }}
`))

AgentSystemPromptTpl Agent 系统提示模版

Functions

func AnalystSystemPrompt

func AnalystSystemPrompt(sl *skills.SkillLoader) func(context.Context, any) (string, error)

AnalystSystemPrompt 分析师系统提示

func GetMetaAvailableModelsValue

func GetMetaAvailableModelsValue(meta any) []models.ModelConfig

GetMetaAvailableModelsValue 从 _meta 中获取可用模型列表

func GetMetaCurrentModelUsageValue

func GetMetaCurrentModelUsageValue(meta any) ai.GenerationUsage

GetMetaCurrentModelUsageValue 从 _meta 中获取当前模型用量

func GetMetaCurrentModelsValue

func GetMetaCurrentModelsValue(meta any) models.Models

GetMetaCurrentModelsValue 从 _meta 中获取当前使用的模型

func GetMetaSkillsValue

func GetMetaSkillsValue(meta any) []skills.SkillMeta

GetMetaSkillsValue 从 _meta 中获取技能列表

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, usage ai.GenerationUsage)

SetMetaCurrentModelUsage 往 _meta 设置当前模型用量

func ShortTermTrendForecastPrompt

func ShortTermTrendForecastPrompt(question string) string

ShortTermTrendForecastPrompt 短期趋势预测 Prompt

Types

type ACPAgentSideConnection

type ACPAgentSideConnection interface {
	SessionUpdate(ctx context.Context, req acp.SessionNotification) error
	Done() <-chan struct{}
}

ACPAgentSideConnection ACP Agent 侧连接

type AgentSystemPromptData

type AgentSystemPromptData struct {
	// 能力概述
	Overview string
	// 目标
	Goal string
	// 工作流程
	Workflow []string
	// 要求
	Requirements []string
	// 技能列表
	Skills []skills.SkillMeta
	// 额外信息
	Extra 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) Connect

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

Connect 连接

func (*NFAAgent) InitGenkit

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

InitGenkit 初始化 genkit

func (*NFAAgent) Initialize

Initialize 初始化连接

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) SetSessionMode

SetSessionMode 设置会话模式

type Options

type Options struct {
	Logger         logr.Logger
	Localizer      *i18n.Localizer
	ModelProviders []models.ModelProvider
	DataProviders  DataProviders
	DefaultModels  models.Models
	DataRoot       string
}

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