Documentation
¶
Index ¶
- func ConvertReActLoopFactoryToActionFactory(name string, factory LoopFactory) func(r aicommon.AIInvokeRuntime) (*LoopAction, error)
- func RegisterAction(action *LoopAction)
- func RegisterLoopFactory(name string, creator LoopFactory, opts ...LoopMetadataOption) error
- type ActionReflection
- type ContextProviderFunc
- type EnvironmentalImpact
- type FeedbackProviderFunc
- type LoopAITagField
- type LoopAction
- type LoopActionFactory
- type LoopActionHandlerFunc
- type LoopActionHandlerOperator
- func (l *LoopActionHandlerOperator) Continue()
- func (l *LoopActionHandlerOperator) DisallowNextLoopExit()
- func (l *LoopActionHandlerOperator) Exit()
- func (l *LoopActionHandlerOperator) Fail(i any)
- func (l *LoopActionHandlerOperator) Feedback(i any)
- func (r *LoopActionHandlerOperator) GetContext() context.Context
- func (l *LoopActionHandlerOperator) GetDisallowLoopExit() bool
- func (l *LoopActionHandlerOperator) GetFeedback() *bytes.Buffer
- func (l *LoopActionHandlerOperator) GetReflectionData() map[string]interface{}
- func (l *LoopActionHandlerOperator) GetReflectionLevel() ReflectionLevel
- func (l *LoopActionHandlerOperator) GetTask() aicommon.AIStatefulTask
- func (l *LoopActionHandlerOperator) IsContinued() bool
- func (l *LoopActionHandlerOperator) IsTerminated() (bool, error)
- func (l *LoopActionHandlerOperator) MarkSilence(i ...bool)
- func (l *LoopActionHandlerOperator) SetReflectionData(key string, value interface{})
- func (l *LoopActionHandlerOperator) SetReflectionLevel(level ReflectionLevel)
- type LoopActionVerifierFunc
- type LoopFactory
- type LoopMetadata
- type LoopMetadataOption
- type LoopStreamField
- type ReActLoop
- func (r *ReActLoop) DisallowAskForClarification()
- func (r *ReActLoop) Execute(taskId string, ctx context.Context, userInput string) error
- func (r *ReActLoop) ExecuteWithExistedTask(task aicommon.AIStatefulTask) error
- func (r *ReActLoop) FinishAsyncTask(t aicommon.AIStatefulTask, err error)
- func (r *ReActLoop) Get(i string) string
- func (r *ReActLoop) GetActionHandler(actionName string) (*LoopAction, error)
- func (r *ReActLoop) GetAllActionNames() []string
- func (r *ReActLoop) GetAllActions() []*LoopAction
- func (r *ReActLoop) GetConfig() aicommon.AICallerConfigIf
- func (r *ReActLoop) GetCurrentMemoriesContent() string
- func (r *ReActLoop) GetCurrentTask() aicommon.AIStatefulTask
- func (r *ReActLoop) GetEmitter() *aicommon.Emitter
- func (r *ReActLoop) GetEnableSelfReflection() bool
- func (r *ReActLoop) GetInt(k string) int
- func (r *ReActLoop) GetInvoker() aicommon.AIInvokeRuntime
- func (r *ReActLoop) GetMemoryTriage() aicommon.MemoryTriage
- func (r *ReActLoop) GetReflectionHistory() []*ActionReflection
- func (r *ReActLoop) GetStringSlice(i string) []string
- func (r *ReActLoop) GetVariable(i string) any
- func (r *ReActLoop) NoActions() bool
- func (r *ReActLoop) OnAsyncTaskFinished(f func(task aicommon.AIStatefulTask))
- func (r *ReActLoop) OnAsyncTaskTrigger(f func(ins *LoopAction, task aicommon.AIStatefulTask))
- func (r *ReActLoop) OnTaskCreated(f func(task aicommon.AIStatefulTask))
- func (r *ReActLoop) PushMemory(result *aicommon.SearchMemoryResult)
- func (r *ReActLoop) RemoveAction(actionType string)
- func (r *ReActLoop) Set(i string, result any)
- func (r *ReActLoop) SetCurrentTask(t aicommon.AIStatefulTask)
- type ReActLoopCoreGenerateCode
- type ReActLoopOption
- func WithAITagField(tagName, variableName string) ReActLoopOption
- func WithAITagFieldWithAINodeId(tagName, variableName, nodeId string, contentType ...string) ReActLoopOption
- func WithActionFactoryFromLoop(name string) ReActLoopOption
- func WithAllowAIForge(b ...bool) ReActLoopOption
- func WithAllowAIForgeGetter(allowAIForge func() bool) ReActLoopOption
- func WithAllowPlanAndExec(b ...bool) ReActLoopOption
- func WithAllowPlanAndExecGetter(allowPlanAndExec func() bool) ReActLoopOption
- func WithAllowRAG(b ...bool) ReActLoopOption
- func WithAllowRAGGetter(allowRAG func() bool) ReActLoopOption
- func WithAllowToolCall(b ...bool) ReActLoopOption
- func WithAllowToolCallGetter(allowToolCall func() bool) ReActLoopOption
- func WithAllowUserInteract(b ...bool) ReActLoopOption
- func WithEnableSelfReflection(enable ...bool) ReActLoopOption
- func WithInitTask(initHandler func(loop *ReActLoop, task aicommon.AIStatefulTask) error) ReActLoopOption
- func WithLoopPromptGenerator(generator ReActLoopCoreGenerateCode) ReActLoopOption
- func WithMaxIterations(maxIterations int) ReActLoopOption
- func WithMemoryPool(pool *omap.OrderedMap[string, *aicommon.MemoryEntity]) ReActLoopOption
- func WithMemorySizeLimit(sizeLimit int) ReActLoopOption
- func WithMemoryTriage(triage aicommon.MemoryTriage) ReActLoopOption
- func WithOnAsyncTaskFinished(fn func(task aicommon.AIStatefulTask)) ReActLoopOption
- func WithOnAsyncTaskTrigger(fn func(i *LoopAction, task aicommon.AIStatefulTask)) ReActLoopOption
- func WithOnPostIteraction(...) ReActLoopOption
- func WithOnTaskCreated(fn func(task aicommon.AIStatefulTask)) ReActLoopOption
- func WithPersistentContextProvider(provider ContextProviderFunc) ReActLoopOption
- func WithPersistentInstruction(instruction string) ReActLoopOption
- func WithReactiveDataBuilder(provider FeedbackProviderFunc) ReActLoopOption
- func WithReflectionOutputExample(example string) ReActLoopOption
- func WithReflectionOutputExampleContextProvider(provider ContextProviderFunc) ReActLoopOption
- func WithRegisterLoopAction(actionName string, desc string, opts []aitool.ToolOption, ...) ReActLoopOption
- func WithRegisterLoopActionWithStreamField(actionName string, desc string, opts []aitool.ToolOption, ...) ReActLoopOption
- func WithToolsGetter(getter func() []*aitool.Tool) ReActLoopOption
- func WithUserInteractGetter(allowUserInteract func() bool) ReActLoopOption
- type ReflectionLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertReActLoopFactoryToActionFactory ¶
func ConvertReActLoopFactoryToActionFactory( name string, factory LoopFactory, ) func(r aicommon.AIInvokeRuntime) (*LoopAction, error)
func RegisterAction ¶
func RegisterAction(action *LoopAction)
func RegisterLoopFactory ¶
func RegisterLoopFactory( name string, creator LoopFactory, opts ...LoopMetadataOption, ) error
Types ¶
type ActionReflection ¶
type ActionReflection struct {
// 基本信息
ActionType string `json:"action_type"`
ActionParams map[string]interface{} `json:"action_params"`
ExecutionTime time.Duration `json:"execution_time"`
IterationNum int `json:"iteration_num"`
Success bool `json:"success"`
ErrorMessage string `json:"error_message,omitempty"`
// 环境影响
EnvironmentalImpact *EnvironmentalImpact `json:"environmental_impact,omitempty"`
// 学习内容
LearningInsights []string `json:"learning_insights,omitempty"`
FutureSuggestions []string `json:"future_suggestions,omitempty"`
ImpactAssessment string `json:"impact_assessment,omitempty"`
EffectivenessRating string `json:"effectiveness_rating,omitempty"`
ReflectionLevel string `json:"reflection_level"`
ReflectionTimestamp time.Time `json:"reflection_timestamp"`
}
ActionReflection 存储单次行动的反思结果
func (*ActionReflection) Dump ¶
func (r *ActionReflection) Dump(nonce string) string
Dump 生成适合放入 Prompt 的格式化字符串(使用 nonce 保护)
func (*ActionReflection) ToMemoryContent ¶
func (r *ActionReflection) ToMemoryContent() string
ToMemoryContent 转换为适合保存到 aimem 的内容格式
type ContextProviderFunc ¶
type EnvironmentalImpact ¶
type EnvironmentalImpact struct {
StateChanges []string `json:"state_changes"`
ResourceUsage map[string]interface{} `json:"resource_usage"`
SideEffects []string `json:"side_effects"`
PositiveEffects []string `json:"positive_effects"`
NegativeEffects []string `json:"negative_effects"`
}
EnvironmentalImpact 环境影响分析
type FeedbackProviderFunc ¶
type LoopAITagField ¶
type LoopAction ¶
type LoopAction struct {
// plan 与 forge executor 会允许支持异步执行,异步情况下仍然允许对话和其他功能
AsyncMode bool
ActionType string `json:"type"`
Description string `json:"description"`
Options []aitool.ToolOption
ActionVerifier LoopActionVerifierFunc
ActionHandler LoopActionHandlerFunc
StreamFields []*LoopStreamField
AITagStreamFields []*LoopAITagField
}
func GetLoopAction ¶
func GetLoopAction(name string) (*LoopAction, bool)
type LoopActionFactory ¶
type LoopActionFactory func(r aicommon.AIInvokeRuntime) (*LoopAction, error)
type LoopActionHandlerFunc ¶
type LoopActionHandlerFunc func(loop *ReActLoop, action *aicommon.Action, operator *LoopActionHandlerOperator)
type LoopActionHandlerOperator ¶
type LoopActionHandlerOperator struct {
// contains filtered or unexported fields
}
func (*LoopActionHandlerOperator) Continue ¶
func (l *LoopActionHandlerOperator) Continue()
func (*LoopActionHandlerOperator) DisallowNextLoopExit ¶
func (l *LoopActionHandlerOperator) DisallowNextLoopExit()
func (*LoopActionHandlerOperator) Exit ¶
func (l *LoopActionHandlerOperator) Exit()
func (*LoopActionHandlerOperator) Fail ¶
func (l *LoopActionHandlerOperator) Fail(i any)
func (*LoopActionHandlerOperator) Feedback ¶
func (l *LoopActionHandlerOperator) Feedback(i any)
func (*LoopActionHandlerOperator) GetContext ¶
func (r *LoopActionHandlerOperator) GetContext() context.Context
func (*LoopActionHandlerOperator) GetDisallowLoopExit ¶
func (l *LoopActionHandlerOperator) GetDisallowLoopExit() bool
func (*LoopActionHandlerOperator) GetFeedback ¶
func (l *LoopActionHandlerOperator) GetFeedback() *bytes.Buffer
func (*LoopActionHandlerOperator) GetReflectionData ¶
func (l *LoopActionHandlerOperator) GetReflectionData() map[string]interface{}
GetReflectionData 获取自定义反思数据
func (*LoopActionHandlerOperator) GetReflectionLevel ¶
func (l *LoopActionHandlerOperator) GetReflectionLevel() ReflectionLevel
GetReflectionLevel 获取当前设置的反思级别
func (*LoopActionHandlerOperator) GetTask ¶
func (l *LoopActionHandlerOperator) GetTask() aicommon.AIStatefulTask
func (*LoopActionHandlerOperator) IsContinued ¶
func (l *LoopActionHandlerOperator) IsContinued() bool
func (*LoopActionHandlerOperator) IsTerminated ¶
func (l *LoopActionHandlerOperator) IsTerminated() (bool, error)
func (*LoopActionHandlerOperator) MarkSilence ¶
func (l *LoopActionHandlerOperator) MarkSilence(i ...bool)
func (*LoopActionHandlerOperator) SetReflectionData ¶
func (l *LoopActionHandlerOperator) SetReflectionData(key string, value interface{})
SetReflectionData 设置自定义反思数据 action 可以添加额外的上下文信息用于反思分析
func (*LoopActionHandlerOperator) SetReflectionLevel ¶
func (l *LoopActionHandlerOperator) SetReflectionLevel(level ReflectionLevel)
SetReflectionLevel 设置该 action 执行后的反思级别 action 可以在执行过程中根据实际情况动态设置反思级别
type LoopActionVerifierFunc ¶
type LoopFactory ¶
type LoopFactory func(r aicommon.AIInvokeRuntime, opts ...ReActLoopOption) (*ReActLoop, error)
func GetLoopFactory ¶
func GetLoopFactory(name string) (LoopFactory, bool)
type LoopMetadata ¶
type LoopMetadata struct {
Name string // loop name
Description string // describes what this loop does
OutputExamplePrompt string // example output for reflection_output_example.txt
UsagePrompt string // usage description for x-@action-rules in schema
}
LoopMetadata stores metadata about a loop for AI understanding
func GetAllLoopMetadata ¶
func GetAllLoopMetadata() []*LoopMetadata
GetAllLoopMetadata returns all registered loop metadata
func GetLoopMetadata ¶
func GetLoopMetadata(name string) (*LoopMetadata, bool)
GetLoopMetadata retrieves metadata for a registered loop
type LoopMetadataOption ¶
type LoopMetadataOption func(*LoopMetadata)
LoopMetadataOption configures LoopMetadata
func WithLoopDescription ¶
func WithLoopDescription(desc string) LoopMetadataOption
WithLoopDescription sets the description of what this loop does
func WithLoopOutputExample ¶
func WithLoopOutputExample(example string) LoopMetadataOption
WithLoopOutputExample sets the example output prompt for reflection
func WithLoopUsagePrompt ¶
func WithLoopUsagePrompt(usage string) LoopMetadataOption
WithLoopUsagePrompt sets the usage description for schema
type LoopStreamField ¶
type ReActLoop ¶
type ReActLoop struct {
// contains filtered or unexported fields
}
func CreateLoopByName ¶
func CreateLoopByName(name string, invoker aicommon.AIInvokeRuntime, opts ...ReActLoopOption) (*ReActLoop, error)
func NewReActLoop ¶
func NewReActLoop(name string, invoker aicommon.AIInvokeRuntime, options ...ReActLoopOption) (*ReActLoop, error)
func (*ReActLoop) DisallowAskForClarification ¶
func (r *ReActLoop) DisallowAskForClarification()
func (*ReActLoop) ExecuteWithExistedTask ¶
func (r *ReActLoop) ExecuteWithExistedTask(task aicommon.AIStatefulTask) error
func (*ReActLoop) FinishAsyncTask ¶
func (r *ReActLoop) FinishAsyncTask(t aicommon.AIStatefulTask, err error)
func (*ReActLoop) GetActionHandler ¶
func (r *ReActLoop) GetActionHandler(actionName string) (*LoopAction, error)
func (*ReActLoop) GetAllActionNames ¶
func (*ReActLoop) GetAllActions ¶
func (r *ReActLoop) GetAllActions() []*LoopAction
func (*ReActLoop) GetConfig ¶
func (r *ReActLoop) GetConfig() aicommon.AICallerConfigIf
func (*ReActLoop) GetCurrentMemoriesContent ¶
func (*ReActLoop) GetCurrentTask ¶
func (r *ReActLoop) GetCurrentTask() aicommon.AIStatefulTask
func (*ReActLoop) GetEmitter ¶
func (*ReActLoop) GetEnableSelfReflection ¶
func (*ReActLoop) GetInvoker ¶
func (r *ReActLoop) GetInvoker() aicommon.AIInvokeRuntime
func (*ReActLoop) GetMemoryTriage ¶
func (r *ReActLoop) GetMemoryTriage() aicommon.MemoryTriage
func (*ReActLoop) GetReflectionHistory ¶
func (r *ReActLoop) GetReflectionHistory() []*ActionReflection
GetReflectionHistory 获取历史反思记录
func (*ReActLoop) GetStringSlice ¶
func (*ReActLoop) GetVariable ¶
func (*ReActLoop) OnAsyncTaskFinished ¶
func (r *ReActLoop) OnAsyncTaskFinished(f func(task aicommon.AIStatefulTask))
func (*ReActLoop) OnAsyncTaskTrigger ¶
func (r *ReActLoop) OnAsyncTaskTrigger(f func(ins *LoopAction, task aicommon.AIStatefulTask))
func (*ReActLoop) OnTaskCreated ¶
func (r *ReActLoop) OnTaskCreated(f func(task aicommon.AIStatefulTask))
func (*ReActLoop) PushMemory ¶
func (r *ReActLoop) PushMemory(result *aicommon.SearchMemoryResult)
func (*ReActLoop) RemoveAction ¶
func (*ReActLoop) SetCurrentTask ¶
func (r *ReActLoop) SetCurrentTask(t aicommon.AIStatefulTask)
type ReActLoopOption ¶
type ReActLoopOption func(r *ReActLoop)
func WithAITagField ¶
func WithAITagField(tagName, variableName string) ReActLoopOption
WithAITagField 行为变化!!!:现在VariableName 不仅仅是在loop中get数据的key,也是tag set到action的field的key
func WithAITagFieldWithAINodeId ¶
func WithAITagFieldWithAINodeId(tagName, variableName, nodeId string, contentType ...string) ReActLoopOption
func WithActionFactoryFromLoop ¶
func WithActionFactoryFromLoop(name string) ReActLoopOption
func WithAllowAIForge ¶
func WithAllowAIForge(b ...bool) ReActLoopOption
func WithAllowAIForgeGetter ¶
func WithAllowAIForgeGetter(allowAIForge func() bool) ReActLoopOption
func WithAllowPlanAndExec ¶
func WithAllowPlanAndExec(b ...bool) ReActLoopOption
func WithAllowPlanAndExecGetter ¶
func WithAllowPlanAndExecGetter(allowPlanAndExec func() bool) ReActLoopOption
func WithAllowRAG ¶
func WithAllowRAG(b ...bool) ReActLoopOption
func WithAllowRAGGetter ¶
func WithAllowRAGGetter(allowRAG func() bool) ReActLoopOption
func WithAllowToolCall ¶
func WithAllowToolCall(b ...bool) ReActLoopOption
func WithAllowToolCallGetter ¶
func WithAllowToolCallGetter(allowToolCall func() bool) ReActLoopOption
func WithAllowUserInteract ¶
func WithAllowUserInteract(b ...bool) ReActLoopOption
func WithEnableSelfReflection ¶
func WithEnableSelfReflection(enable ...bool) ReActLoopOption
WithEnableSelfReflection 启用自我反思功能 启用后,每次 action 执行后会根据策略进行自我反思分析 action 可以通过 operator.SetReflectionLevel() 自定义反思级别
func WithInitTask ¶
func WithInitTask(initHandler func(loop *ReActLoop, task aicommon.AIStatefulTask) error) ReActLoopOption
func WithLoopPromptGenerator ¶
func WithLoopPromptGenerator(generator ReActLoopCoreGenerateCode) ReActLoopOption
func WithMaxIterations ¶
func WithMaxIterations(maxIterations int) ReActLoopOption
func WithMemoryPool ¶
func WithMemoryPool(pool *omap.OrderedMap[string, *aicommon.MemoryEntity]) ReActLoopOption
func WithMemorySizeLimit ¶
func WithMemorySizeLimit(sizeLimit int) ReActLoopOption
func WithMemoryTriage ¶
func WithMemoryTriage(triage aicommon.MemoryTriage) ReActLoopOption
func WithOnAsyncTaskFinished ¶
func WithOnAsyncTaskFinished(fn func(task aicommon.AIStatefulTask)) ReActLoopOption
func WithOnAsyncTaskTrigger ¶
func WithOnAsyncTaskTrigger(fn func(i *LoopAction, task aicommon.AIStatefulTask)) ReActLoopOption
func WithOnPostIteraction ¶
func WithOnPostIteraction(fn func(loop *ReActLoop, iteration int, task aicommon.AIStatefulTask, isDone bool, reason any)) ReActLoopOption
WithOnPostIteraction sets a callback function that is called after each iteration of the ReAct loop.
func WithOnTaskCreated ¶
func WithOnTaskCreated(fn func(task aicommon.AIStatefulTask)) ReActLoopOption
func WithPersistentContextProvider ¶
func WithPersistentContextProvider(provider ContextProviderFunc) ReActLoopOption
func WithPersistentInstruction ¶
func WithPersistentInstruction(instruction string) ReActLoopOption
func WithReactiveDataBuilder ¶
func WithReactiveDataBuilder(provider FeedbackProviderFunc) ReActLoopOption
func WithReflectionOutputExample ¶
func WithReflectionOutputExample(example string) ReActLoopOption
func WithReflectionOutputExampleContextProvider ¶
func WithReflectionOutputExampleContextProvider(provider ContextProviderFunc) ReActLoopOption
func WithRegisterLoopAction ¶
func WithRegisterLoopAction(actionName string, desc string, opts []aitool.ToolOption, verifier LoopActionVerifierFunc, handler LoopActionHandlerFunc) ReActLoopOption
func WithRegisterLoopActionWithStreamField ¶
func WithRegisterLoopActionWithStreamField(actionName string, desc string, opts []aitool.ToolOption, fields []*LoopStreamField, verifier LoopActionVerifierFunc, handler LoopActionHandlerFunc) ReActLoopOption
func WithToolsGetter ¶
func WithToolsGetter(getter func() []*aitool.Tool) ReActLoopOption
func WithUserInteractGetter ¶
func WithUserInteractGetter(allowUserInteract func() bool) ReActLoopOption
type ReflectionLevel ¶
type ReflectionLevel int
ReflectionLevel 定义反思的深度级别
const ( // ReflectionLevel_None 不进行反思 ReflectionLevel_None ReflectionLevel = iota // ReflectionLevel_Minimal 最小反思:仅记录执行结果 ReflectionLevel_Minimal // ReflectionLevel_Standard 标准反思:评估基本影响 ReflectionLevel_Standard // ReflectionLevel_Deep 深度反思:详细分析环境变化和影响 ReflectionLevel_Deep // ReflectionLevel_Critical 关键反思:失败场景的深度根因分析 ReflectionLevel_Critical )
func (ReflectionLevel) String ¶
func (r ReflectionLevel) String() string
String returns the string representation of ReflectionLevel