flows

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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const SummarizeFlowName = "Summarize"

SummarizeFlowName 总结流名

Variables

View Source
var TopicRoutingPromptTpl = template.Must(template.New("TopicRoutingPrompt").
	Parse(`根据对话判断 user 当前是否延续之前话题以及当前讨论的话题类型

## 输出格式
输出为 JSON 格式,包含以下字段
- **continue** (bool) 是否继续之前的话题,当前问题是否是之前正在讨论话题的延续、简单追问、补充说明等。
  澄清几种易混淆情况:
  - 话题类型改变时不属于继续
  - 话题类型没有改变但是讨论的对象发生了改变也不属于继续
- **topic** (string) 当前讨论的话题,可选以下值
  - ` + "`" + `Query` + "`" + `: 信息查询,单纯查询股票价格、资讯等信息,不需要分析
  - ` + "`" + `StockAnalysis` + "`" + `: 个股分析,针对单个股票的技术面、基本面等进行分析
  - ` + "`" + `PortfolioAnalysis` + "`" + `: 投资组合分析,针对投资组合进行分析
  - ` + "`" + `ShortTermTrendForecast` + "`" + `: 短期趋势预测,根据技术面分析、基本面分析、市场资讯、情绪等预测股票近期(一个月内)涨跌趋势
  - ` + "`" + `Basic` + "`" + `: 基础咨询,对一般性的基本的金融知识的咨询
  - ` + "`" + `Comprehensive` + "`" + `: 综合问题,较复杂的综合性问题,需要结合多种分析模式才能解答的问题
  - ` + "`" + `Others` + "`" + `: 其它。不符合以上类型的其它类型话题

## 对话
以下是需要判断话题的对话过程:
` + "```" + `
{{- range .Messages }}
{{- if .Text }}
{{ .Role }}:
{{ .Text }}
{{- end }}

{{- end }}
` + "```" + `
`))

TopicRoutingPromptTpl 话题分类 Prompt 模版

Functions

func DefineCallSubAgentTool

func DefineCallSubAgentTool(g *genkit.Genkit, name string, agents []AgentOptions) ai.ToolRef

DefineCallSubAgentTool 注册调用子 Agent 工具

func NewTopicRoutingFlow

func NewTopicRoutingFlow(g *genkit.Genkit) core.Func[TopicRoutingInput, TopicRoutingOutput]

NewTopicRoutingFlow 创建话题分类流程

func TopicRoutingPrompt

func TopicRoutingPrompt(in TopicRoutingInput) (string, error)

TopicRoutingPrompt 话题分类

Types

type AgentOptions

type AgentOptions struct {
	Name        string `json:"name"`
	Description string `json:"description"`

	SystemPrompt ai.PromptFn  `json:"-"`
	Tools        []ai.ToolRef `json:"-"`
}

AgentOptions Agent 选项

type CallSubAgentInput

type CallSubAgentInput struct {
	Name   string `json:"name"`
	Prompt string `json:"prompt"`
}

CallSubAgentInput 调用子 Agent 输入

type CallSubAgentOutput

type CallSubAgentOutput struct {
	Messages []*ai.Message `json:"messages"`
	Error    string        `json:"error,omitempty"`
}

CallSubAgentOutput 调用子 Agent 输出

type ChatFlow

type ChatFlow = *core.Flow[ChatInput, ChatOutput, struct{}]

ChatFlow 对话流程

func DefineMultiAgentsChatFlow

func DefineMultiAgentsChatFlow(
	g *genkit.Genkit,
	name string,
	mainAgent AgentOptions,
	subAgents []AgentOptions,
) ChatFlow

DefineMultiAgentsChatFlow 定义多 Agent 对话流程

func DefineSimpleChatFlow

func DefineSimpleChatFlow(g *genkit.Genkit, name string, genOpts GenerateOptionsFn) ChatFlow

DefineSimpleChatFlow 定义简单对话流程

type ChatInput

type ChatInput struct {
	Prompt  string        `json:"prompt"`
	History []*ai.Message `json:"history,omitempty"`
}

ChatInput 对话输入

type ChatOutput

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

ChatOutput 对话输出

type GenerateOptionsFn

type GenerateOptionsFn func() []ai.GenerateOption

GenerateOptionsFn 获取生成选项的方法

func FixedGenerateOptions

func FixedGenerateOptions(opts ...ai.GenerateOption) GenerateOptionsFn

FixedGenerateOptions 固定的生成选项

type SummarizeFlow

type SummarizeFlow = *core.Flow[SummarizeInput, SummarizeOutput, struct{}]

func DefineSummarizeFlow

func DefineSummarizeFlow(g *genkit.Genkit) SummarizeFlow

DefineSummarizeFlow 定义总结工作流

type SummarizeInput

type SummarizeInput struct {
	History []*ai.Message `json:"history,omitempty"`
}

SummarizeInput 总结输入

type SummarizeOutput

type SummarizeOutput struct {
	Title              string `json:"title"`
	Description        string `json:"description"`
	ProcessOverview    string `json:"processOverview"`
	MethodologySummary string `json:"methodologySummary,omitempty"`
}

SummarizeOutput 总结输出

type ToolCallError

type ToolCallError struct {
	Err string `json:"error"`
}

ToolCallError 工具调用错误

func (ToolCallError) Error

func (e ToolCallError) Error() string

Error 返回错误描述

type Topic

type Topic string

Topic 话题

const (
	TopicContinue               Topic = "Continue"
	TopicQuery                  Topic = "Query"
	TopicStockAnalysis          Topic = "StockAnalysis"
	TopicPortfolioAnalysis      Topic = "PortfolioAnalysis"
	TopicShortTermTrendForecast Topic = "ShortTermTrendForecast"
	TopicBasic                  Topic = "Basic"
	TopicComprehensive          Topic = "Comprehensive"
	TopicOthers                 Topic = "Others"
)

type TopicRoutingFlow

type TopicRoutingFlow = *core.Flow[TopicRoutingInput, TopicRoutingOutput, struct{}]

TopicRoutingFlow 话题路由流程

func DefineTopicRoutingFlow

func DefineTopicRoutingFlow(g *genkit.Genkit) TopicRoutingFlow

DefineTopicRoutingFlow 定义话题分类流程

type TopicRoutingInput

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

TopicRoutingInput 话题分类输入

type TopicRoutingOutput

type TopicRoutingOutput struct {
	Continue bool  `json:"continue"`
	Topic    Topic `json:"topic,omitempty"`
}

TopicRoutingOutput 话题分类输出

Jump to

Keyboard shortcuts

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