aid

package
v1.4.4-alpha1202-diff-... Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MemoryOpAction = "operate_memory"
View Source
var MemoryOpSchemaOption = []aitool.ToolOption{
	aitool.WithStringParam("@action", aitool.WithParam_Const(MemoryOpAction)), aitool.WithStructArrayParam("memory_op",
		[]aitool.PropertyOption{
			aitool.WithParam_Description("persistent memory operation, you can use this to store some data in the memory, and it will be used in the next call"),
			aitool.WithParam_Required(true),
			aitool.WithParam_MinLength(0),
		},
		nil,
		aitool.WithStringParam("op", aitool.WithParam_Description("the operation type, can be 'set', 'delete'"), aitool.WithParam_EnumString("set", "delete"), aitool.WithParam_Required(true)),
		aitool.WithStringParam("key", aitool.WithParam_Description("the key of the persistent memory, if you set op to 'set', this is required"), aitool.WithParam_Required(true)),
		aitool.WithStringParam("value", aitool.WithParam_Description("the value of the persistent memory, if you set op to 'set', this is required"), aitool.WithParam_Required(false)),
	),
}
View Source
var TaskReviewSuggestions = []*ReviewSuggestion{
	{
		Value:            "deeply_think",
		Prompt:           "思考不够深入,根据当前上下文,为当前任务拆分更多子任务",
		PromptEnglish:    "Not deep enough, split more sub-tasks for the current task according to the current context",
		AllowExtraPrompt: true,
		ParamSchema:      schemaRePlanSuggestion,
	},
	{
		Value:            "inaccurate",
		Prompt:           "回答不够精准,存在未使用工具导致幻觉,或者工具参数不合适",
		PromptEnglish:    "The answer is not accurate enough, there is an illusion caused by not using the tool, or the tool parameters are not appropriate",
		AllowExtraPrompt: true,
	},
	{
		Value:         "continue",
		Prompt:        "继续执行任务",
		PromptEnglish: "Continue to execute the task",
	},
	{
		Value:            "adjust_plan",
		Prompt:           "任务需要调整,用户会输入更新后任务建议",
		PromptEnglish:    "The task needs to be adjusted, and the user will enter the updated task",
		AllowExtraPrompt: true,
		ParamSchema:      schemaRePlanSuggestion,
	},
}

TaskReviewSuggestions 是任务审查时的建议(内置一些常见选项)

View Source
var ToolUseReviewSuggestions = []*ToolUseReviewSuggestion{
	{
		Value:            "wrong_tool",
		Prompt:           "工具选择不当",
		PromptEnglish:    "Wrong tool used, need to change to a more appropriate tool",
		AllowExtraPrompt: true,
	},
	{
		Value:                   "wrong_params",
		Prompt:                  "参数不合理",
		PromptEnglish:           "Tool parameters are not used properly, need to adjust parameters",
		AllowExtraPrompt:        true,
		AllowParamsModification: true,
	},
	{
		Value:                   "direct_answer",
		Prompt:                  "要求AI直接回答",
		PromptEnglish:           "Tool parameters are not used properly, need to adjust parameters",
		AllowExtraPrompt:        true,
		AllowParamsModification: true,
	},
	{
		Value:         "continue",
		Prompt:        "同意工具使用",
		PromptEnglish: "Tool usage is correct, continue execution",
	},
}

ToolUseReviewSuggestions 是工具使用审查时的建议(内置一些常见选项)

Functions

func AttractionTool

func AttractionTool() *aitool.Tool

AttractionTool 创建景点推荐工具

func DFSOrderAiTask

func DFSOrderAiTask(root *AiTask) *linktable.LinkedList[*AiTask]

func DFSOrderAiTaskPostOrder

func DFSOrderAiTaskPostOrder(root *AiTask) *linktable.LinkedList[*AiTask]

DFSOrderAiTaskPostOrder 使用后序遍历(Post-order)来遍历 AiTask 树。 遍历顺序:先访问所有子任务,最后访问父任务。

func EchoTool

func EchoTool() *aitool.Tool

EchoTool 直接返回输入的工具

func ErrorTool

func ErrorTool() *aitool.Tool

func ExecuteAIForge

func ExecuteAIForge(ctx context.Context, forgeName string, params []*ypb.ExecParamItem, opts ...aicommon.ConfigOption) (*aicommon.Action, error)

func GetAllMockTools

func GetAllMockTools() []*aitool.Tool

提供所有Mock工具的集合

func IsAIDBuildInForgeExisted

func IsAIDBuildInForgeExisted(forgeName string) bool

func PrintTool

func PrintTool() *aitool.Tool

PrintTool 直接输出到标准输出的工具

func RegisterAIDBuildinForge

func RegisterAIDBuildinForge(forgeName string, fun AIDBuildinForgeExecutor) error

func RestaurantTool

func RestaurantTool() *aitool.Tool

RestaurantTool 创建餐厅搜索工具

func SelectSummary

func SelectSummary(task *AiTask, callResult *aitool.ToolResult) string

func TimeDelayTool

func TimeDelayTool() *aitool.Tool

TimeDelayedTool 模拟延时工具

func TimeEstimateTool

func TimeEstimateTool() *aitool.Tool

TimeEstimateTool 创建行程时间估算工具

func TransportTool

func TransportTool() *aitool.Tool

TransportTool 创建交通查询工具

func UnregisterAIDBuildinForge

func UnregisterAIDBuildinForge(forgeName string) error

func WeatherTool

func WeatherTool() *aitool.Tool

WeatherTool 创建天气查询工具

func WithAiForgeSearchTool

func WithAiForgeSearchTool() aicommon.ConfigOption

func WithAiToolsSearchTool

func WithAiToolsSearchTool() aicommon.ConfigOption

!!!!

func WithPlanMocker

func WithPlanMocker(i func(coordinator *Coordinator) *PlanResponse) aicommon.ConfigOption

func WithPromptContextProvider

func WithPromptContextProvider(provider *PromptContextProvider) aicommon.ConfigOption

func WithResultHandler

func WithResultHandler(h func(c *Coordinator)) aicommon.ConfigOption

cycle import issue

Types

type AIDBuildinForgeExecutor

type AIDBuildinForgeExecutor func(c context.Context, params []*ypb.ExecParamItem, opts ...aicommon.ConfigOption) (*aicommon.Action, error)

type AiTask

type AiTask struct {
	*Coordinator

	*aicommon.AIStatefulTaskBase
	Index      string    `json:"index"`
	Name       string    `json:"name"`
	Goal       string    `json:"goal"`
	ParentTask *AiTask   `json:"parent_task"`
	Subtasks   []*AiTask `json:"subtasks"`

	StatusSummary string `json:"status_summary"`
	TaskSummary   string `json:"task_summary"`
	ShortSummary  string `json:"short_summary"`
	LongSummary   string `json:"long_summary"`
	// contains filtered or unexported fields
}

func ExtractNextPlanTaskFromRawResponse

func ExtractNextPlanTaskFromRawResponse(c *Coordinator, rawResponse string) ([]*AiTask, error)

func ExtractTaskFromRawResponse

func ExtractTaskFromRawResponse(c *Coordinator, rawResponse string) (retTask *AiTask, err error)

ExtractTaskFromRawResponse 从原始响应中提取Task

func (*AiTask) AdjustPlan

func (t *AiTask) AdjustPlan(suggestion string) error

func (*AiTask) DeepThink

func (t *AiTask) DeepThink(suggestion string) error

func (*AiTask) GenerateDeepThinkPlanPrompt

func (t *AiTask) GenerateDeepThinkPlanPrompt(suggestion string) (string, error)

func (*AiTask) GenerateIndex

func (t *AiTask) GenerateIndex()

GenerateIndex 为任务树生成层级索引。 调用此方法的任务 (a) 所在树的根节点索引将被设为 "1"。 其子任务将相应地获得如 "1-1", "1-2" 等索引,孙任务如 "1-1-1" 等。

func (*AiTask) GenerateTaskSummaryPrompt

func (t *AiTask) GenerateTaskSummaryPrompt() (string, error)

func (*AiTask) GetEmitter

func (t *AiTask) GetEmitter() *aicommon.Emitter

func (*AiTask) GetFailCallCount

func (t *AiTask) GetFailCallCount() int

func (*AiTask) GetSuccessCallCount

func (t *AiTask) GetSuccessCallCount() int

func (*AiTask) GetSummary

func (t *AiTask) GetSummary() string

func (*AiTask) GetUserInput

func (t *AiTask) GetUserInput() string

func (*AiTask) MarshalJSON

func (t *AiTask) MarshalJSON() ([]byte, error)

MarshalJSON 实现自定义的JSON序列化,跳过AICallback字段

func (*AiTask) Progress

func (t *AiTask) Progress() string

func (*AiTask) ProgressWithDetail

func (t *AiTask) ProgressWithDetail() string

func (*AiTask) QuoteGoal

func (t *AiTask) QuoteGoal() string

func (*AiTask) QuoteName

func (t *AiTask) QuoteName() string

func (*AiTask) SetID

func (t *AiTask) SetID(id string)

func (*AiTask) SingleLineStatusSummary

func (t *AiTask) SingleLineStatusSummary() string

func (*AiTask) TaskContinueCount

func (t *AiTask) TaskContinueCount() int

TaskContinueCount 返回任务继续执行的次数(从 ReActLoop 获取迭代次数)

func (*AiTask) ToolCallCount

func (t *AiTask) ToolCallCount() int

ToolCallCount 返回工具调用次数

func (*AiTask) UnmarshalJSON

func (t *AiTask) UnmarshalJSON(data []byte) error

UnmarshalJSON 实现自定义的JSON反序列化,跳过AICallback字段

type Coordinator

type Coordinator struct {
	*aicommon.Config

	PlanMocker      func(config *Coordinator) *PlanResponse
	ContextProvider *PromptContextProvider

	ResultHandler func(cod *Coordinator)
	// contains filtered or unexported fields
}

func NewCoordinator

func NewCoordinator(userInput string, options ...aicommon.ConfigOption) (*Coordinator, error)

func NewCoordinatorContext

func NewCoordinatorContext(ctx context.Context, userInput string, options ...aicommon.ConfigOption) (*Coordinator, error)

NewCoordinatorContext 创建一个新的 Coordinator

func NewFastRecoverCoordinator

func NewFastRecoverCoordinator(uuid string, opt ...aicommon.ConfigOption) (*Coordinator, error)

func NewFastRecoverCoordinatorContext

func NewFastRecoverCoordinatorContext(ctx context.Context, uuid string, opt ...aicommon.ConfigOption) (*Coordinator, error)

func NewRecoveredCoordinator

func NewRecoveredCoordinator(
	ctx context.Context,
	pt *schema.AIAgentRuntime,
	options ...aicommon.ConfigOption,
) (*Coordinator, error)

func (*Coordinator) CallAITransaction

func (c *Coordinator) CallAITransaction(prompt string, postHandler func(response *aicommon.AIResponse) error, requestOpts ...aicommon.AIRequestOption) error

func (*Coordinator) CreateDatabaseSchema

func (c *Coordinator) CreateDatabaseSchema(input string) *schema.AIAgentRuntime

func (*Coordinator) CreateRequireUserInteract

func (c *Coordinator) CreateRequireUserInteract() (*aitool.Tool, error)

CreateRequireUserInteract 创建一个需要用户输入的提示工具 这个工具非常有意思,AI 如果调用这个工具,意味着,他觉得他受阻了,需要人的提示来帮助他继续完成任务 调用这个工具会强制让 AI 进入等待状态,直到用户输入提示

func (*Coordinator) EmitPopTask

func (c *Coordinator) EmitPopTask(task *AiTask)

func (*Coordinator) EmitPushTask

func (c *Coordinator) EmitPushTask(task *AiTask)

func (*Coordinator) EmitRequireReviewForPlan

func (c *Coordinator) EmitRequireReviewForPlan(rsp *PlanResponse, id string)

func (*Coordinator) EmitRequireReviewForTask

func (c *Coordinator) EmitRequireReviewForTask(task *AiTask, id string)

func (*Coordinator) EmitRequireUserInteractive

func (c *Coordinator) EmitRequireUserInteractive(i *RequireInteractiveRequest, id string)

func (*Coordinator) EmitUpdateTaskStatus

func (c *Coordinator) EmitUpdateTaskStatus(task *AiTask)

func (*Coordinator) EnableToolManagerAISearch

func (c *Coordinator) EnableToolManagerAISearch() error

func (*Coordinator) ExecuteLoopTask

func (c *Coordinator) ExecuteLoopTask(taskTypeName string, task aicommon.AIStatefulTask, options ...reactloops.ReActLoopOption) error

func (*Coordinator) GetAIConfig

func (c *Coordinator) GetAIConfig() *aicommon.Config

func (*Coordinator) GetContextProvider

func (c *Coordinator) GetContextProvider() *PromptContextProvider

func (*Coordinator) GetPromptContextProvider

func (c *Coordinator) GetPromptContextProvider() *PromptContextProvider

func (*Coordinator) HandleSearch

func (c *Coordinator) HandleSearch(query string, items *omap.OrderedMap[string, []string]) ([]*searchtools.KeywordSearchResult, error)

func (*Coordinator) ProcessExtendedActionCallback

func (c *Coordinator) ProcessExtendedActionCallback(resp string)

func (*Coordinator) RequireUserPrompt

func (c *Coordinator) RequireUserPrompt(prompt string, opts ...*RequireInteractiveRequestOption) (aitool.InvokeParams, error)

func (*Coordinator) RequireUserPromptWithEndpointResult

func (c *Coordinator) RequireUserPromptWithEndpointResult(prompt string, opts ...*RequireInteractiveRequestOption) (aitool.InvokeParams, *aicommon.Endpoint, error)

func (*Coordinator) RequireUserPromptWithEndpointResultEx

func (c *Coordinator) RequireUserPromptWithEndpointResultEx(ctx context.Context, prompt string, opts ...*RequireInteractiveRequestOption) (aitool.InvokeParams, *aicommon.Endpoint, error)

func (*Coordinator) Run

func (c *Coordinator) Run() error

type CoordinatorOption

type CoordinatorOption func(c *Coordinator)

CoordinatorOption 定义配置 Coordinator 的选项接口

func WithCoordinatorPlanMocker

func WithCoordinatorPlanMocker(i func(coordinator *Coordinator) *PlanResponse) CoordinatorOption

func WithCoordinatorResultHandler

func WithCoordinatorResultHandler(h func(c *Coordinator)) CoordinatorOption

type HandleToolUseNext

type HandleToolUseNext string

type InteractiveEventRecord

type InteractiveEventRecord struct {
	InteractiveEvent *schema.AiOutputEvent
	UserInput        aitool.InvokeParams
}

type PersistentDataRecord

type PersistentDataRecord struct {
	Variable bool
	Value    string
}

type PlanRecord

type PlanRecord struct {
	PlanRequest  *planRequest
	PlanResponse *PlanResponse
}

type PlanResponse

type PlanResponse struct {
	RootTask *AiTask `json:"root_task"`
}

func ExtractPlan

func ExtractPlan(c *Coordinator, rawResponse string) (*PlanResponse, error)

func (*PlanResponse) MergeSubtask

func (p *PlanResponse) MergeSubtask(parentIndex string, name string, goal string)

type PlanReviewSuggestion

type PlanReviewSuggestion struct {
	Id               string `json:"id"`
	Value            string `json:"value"`
	Prompt           string `json:"prompt"`
	PromptEnglish    string `json:"prompt_english"`
	AllowExtraPrompt bool   `json:"allow_extra_prompt"`

	PromptBuilder    func(plan *planRequest, rt *runtime) `json:"-"`
	ResponseCallback func(reader io.Reader)               `json:"-"`
	ParamSchema      string                               `json:"param_schema"`
}

type PromptContextProvider

type PromptContextProvider struct {
	// user first input
	Query string

	// persistent data
	PersistentData *omap.OrderedMap[string, *PersistentDataRecord]

	// task info
	CurrentTask *AiTask
	RootTask    *AiTask

	// todo
	PlanHistory []*PlanRecord

	// tools list
	DisableTools bool
	Tools        func() []*aitool.Tool

	// interactive history
	InteractiveHistory *omap.OrderedMap[string, *InteractiveEventRecord]
	// contains filtered or unexported fields
}

func GetDefaultContextProvider

func GetDefaultContextProvider() *PromptContextProvider

func (*PromptContextProvider) ApplyOp

func (m *PromptContextProvider) ApplyOp(memoryOpAction *aicommon.Action)

ApplyOp applies a list of operations to the memory.

func (*PromptContextProvider) Arch

func (m *PromptContextProvider) Arch() string

func (*PromptContextProvider) BindCoordinator

func (m *PromptContextProvider) BindCoordinator(c *Coordinator)

func (*PromptContextProvider) ClearRuntimeConfig

func (m *PromptContextProvider) ClearRuntimeConfig()

func (*PromptContextProvider) CopyReducibleMemory

func (m *PromptContextProvider) CopyReducibleMemory() *PromptContextProvider

func (*PromptContextProvider) CurrentTaskInfo

func (m *PromptContextProvider) CurrentTaskInfo() string

memory tools current task info

func (*PromptContextProvider) CurrentTaskTimeline

func (m *PromptContextProvider) CurrentTaskTimeline() string

func (*PromptContextProvider) CurrentTaskToolCallResults

func (m *PromptContextProvider) CurrentTaskToolCallResults() []*aitool.ToolResult

func (*PromptContextProvider) DeletePersistentData

func (m *PromptContextProvider) DeletePersistentData(key string)

func (*PromptContextProvider) GetInteractiveEvent

func (m *PromptContextProvider) GetInteractiveEvent(eventID string) (*InteractiveEventRecord, bool)

func (*PromptContextProvider) GetInteractiveEventLast

func (m *PromptContextProvider) GetInteractiveEventLast() (string, *InteractiveEventRecord, bool)

func (*PromptContextProvider) GetPersistentData

func (m *PromptContextProvider) GetPersistentData(key string) (string, bool)

func (*PromptContextProvider) GetTimelineInstance

func (m *PromptContextProvider) GetTimelineInstance() *aicommon.Timeline

func (*PromptContextProvider) Now

func (m *PromptContextProvider) Now() string

constants info memory api

func (*PromptContextProvider) OS

func (m *PromptContextProvider) OS() string

func (*PromptContextProvider) PersistentMemory

func (m *PromptContextProvider) PersistentMemory() string

func (*PromptContextProvider) PlanHelp

func (m *PromptContextProvider) PlanHelp() string

func (*PromptContextProvider) Progress

func (m *PromptContextProvider) Progress() string

func (*PromptContextProvider) PromptForToolCallResultsForLastN

func (m *PromptContextProvider) PromptForToolCallResultsForLastN(n int) string

func (*PromptContextProvider) PushPersistentData

func (m *PromptContextProvider) PushPersistentData(values ...string)

func (*PromptContextProvider) PushText

func (m *PromptContextProvider) PushText(id int64, i any)

func (*PromptContextProvider) PushToolCallResults

func (m *PromptContextProvider) PushToolCallResults(t *aitool.ToolResult)

tool results memory

func (*PromptContextProvider) PushUserInteraction

func (m *PromptContextProvider) PushUserInteraction(stage aicommon.UserInteractionStage, seq int64, question, userInput string)

func (*PromptContextProvider) SafeStoreInteractiveUserInput

func (m *PromptContextProvider) SafeStoreInteractiveUserInput(eventID string, invoke aitool.InvokeParams)

SafeStoreInteractiveUserInput safely stores interactive user input with better error handling

func (*PromptContextProvider) Schema

func (m *PromptContextProvider) Schema() map[string]string

func (*PromptContextProvider) SetPersistentData

func (m *PromptContextProvider) SetPersistentData(key string, value string)

func (*PromptContextProvider) SetTimelineInstance

func (m *PromptContextProvider) SetTimelineInstance(timeline *aicommon.Timeline)

func (*PromptContextProvider) SetTimelineLimit

func (m *PromptContextProvider) SetTimelineLimit(i int)

timeline limit set

func (*PromptContextProvider) SoftDeleteTimeline

func (m *PromptContextProvider) SoftDeleteTimeline(id ...int64)

func (*PromptContextProvider) StoreCliParameter

func (m *PromptContextProvider) StoreCliParameter(param []*ypb.ExecParamItem)

func (*PromptContextProvider) StoreCurrentTask

func (m *PromptContextProvider) StoreCurrentTask(task *AiTask)

func (*PromptContextProvider) StoreInteractiveEvent

func (m *PromptContextProvider) StoreInteractiveEvent(eventID string, e *schema.AiOutputEvent)

interactive history memory

func (*PromptContextProvider) StoreInteractiveUserInput

func (m *PromptContextProvider) StoreInteractiveUserInput(eventID string, invoke aitool.InvokeParams)

func (*PromptContextProvider) StoreQuery

func (m *PromptContextProvider) StoreQuery(query string)

user first input

func (*PromptContextProvider) StoreRootTask

func (m *PromptContextProvider) StoreRootTask(t *AiTask)

task info memory

func (*PromptContextProvider) StoreTools

func (m *PromptContextProvider) StoreTools(toolList func() []*aitool.Tool)

set tools list

func (*PromptContextProvider) StoreToolsKeywords

func (m *PromptContextProvider) StoreToolsKeywords(keywords func() []string)

set tools list

func (*PromptContextProvider) TaskMaxContinue

func (m *PromptContextProvider) TaskMaxContinue() int64

func (*PromptContextProvider) Timeline

func (m *PromptContextProvider) Timeline() string

func (*PromptContextProvider) TimelineDump

func (m *PromptContextProvider) TimelineDump() string

TimelineDump returns the timeline dump safely

func (*PromptContextProvider) TimelineWithout

func (m *PromptContextProvider) TimelineWithout(n ...any) string

func (*PromptContextProvider) ToolsKeywords

func (m *PromptContextProvider) ToolsKeywords() string

func (*PromptContextProvider) ToolsList

func (m *PromptContextProvider) ToolsList() string

type RequireInteractiveRequest

type RequireInteractiveRequest struct {
	Id      string                             `json:"id"`
	Prompt  string                             `json:"prompt"`
	Options []*RequireInteractiveRequestOption `json:"options"`
}

type RequireInteractiveRequestOption

type RequireInteractiveRequestOption struct {
	Index       int    `json:"index"`
	PromptTitle string `json:"prompt_title"`
	Prompt      string `json:"prompt"`
}

type ReviewSuggestion

type ReviewSuggestion struct {
	Value            string `json:"value"`
	Prompt           string `json:"prompt"`
	PromptEnglish    string `json:"prompt_english"`
	AllowExtraPrompt bool   `json:"allow_extra_prompt"`

	ResponseCallback func(reader io.Reader) `json:"-"`
	ParamSchema      string                 `json:"param_schema"`
}

type TaskProgress

type TaskProgress struct {
	TotalTasks     int    `json:"total_tasks"`     // 总任务数
	CompletedTasks int    `json:"completed_tasks"` // 已完成任务数
	CurrentTask    string `json:"current_task"`    // 当前执行的任务
	CurrentGoal    string `json:"current_goal"`    // 当前任务的目标
}

TaskProgress 记录任务执行的进度信息

type TaskResponseCallback

type TaskResponseCallback func(ctx *PromptContextProvider, details ...aispec.ChatDetail) (continueThinking bool, prompt string, err error)

TaskResponseCallback 定义Task执行过程中响应回调函数类型

type ToolUseReviewSuggestion

type ToolUseReviewSuggestion struct {
	Value                   string `json:"value"`
	Prompt                  string `json:"prompt"`
	PromptEnglish           string `json:"prompt_english"`
	AllowExtraPrompt        bool   `json:"allow_extra_prompt"`
	AllowParamsModification bool   `json:"allow_params_modification"`
}

Jump to

Keyboard shortcuts

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