flow

package
v0.0.0-...-65173de Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: Apache-2.0 Imports: 6 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 (
	DefaultMaxRetryTimes = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Flow

type Flow struct {
	Name string

	Steps []Step
	// The default ClientImpl for the flow
	ClientImpl llm.Client
	// Variables are key-value pairs that will be available to all steps in the flow
	Variables map[string]any
}

func NewFlow

func NewFlow(client llm.Client, name string, steps ...Step) (*Flow, error)

func (*Flow) GetVariable

func (flow *Flow) GetVariable(key string) (any, bool)

GetVariable gets the value of a variable and returns whether it exists

func (*Flow) GetVariables

func (flow *Flow) GetVariables() map[string]any

RunWithVariables runs the flow with the provided variables. This is a convenience method for creating a flow context with variables and running the flow.

Parameters:

  • variables: Map of variable names to values to use in the flow context

Returns:

  • The updated flow context after flow execution
  • Any error encountered during flow execution

GetVariables returns all variables in the flow

func (*Flow) NewFlowContext

func (flow *Flow) NewFlowContext(flowContext string, memory any) *FlowContext

func (*Flow) Run

func (flow *Flow) Run(initialFlowContext FlowContext) (*FlowContext, error)

func (*Flow) RunWithInput

func (flow *Flow) RunWithInput(input string) (*FlowContext, error)

func (*Flow) RunWithInputAndVariables

func (flow *Flow) RunWithInputAndVariables(input string, variables map[string]any) (*FlowContext, error)

RunWithInputAndVariables runs the flow with the provided input text and variables. This is a convenience method for creating a flow context with text and variables and running the flow.

Parameters:

  • input: The input text to use in the flow context
  • variables: Map of variable names to values to use in the flow context

Returns:

  • The updated flow context after flow execution
  • Any error encountered during flow execution

func (*Flow) RunWithMemory

func (flow *Flow) RunWithMemory(memory ShortTermMemory) (*FlowContext, error)

RunWithMemory runs the flow with the provided memory object. This is a convenience method for creating a flow context with memory and running the flow.

Parameters:

  • memory: The memory object to use in the flow context

Returns:

  • The updated flow context after flow execution
  • Any error encountered during flow execution

func (*Flow) RunWithVariables

func (flow *Flow) RunWithVariables(variables map[string]any) (*FlowContext, error)

func (*Flow) SetVariable

func (flow *Flow) SetVariable(key string, value any)

SetVariable sets the value of a variable

type FlowContext

type FlowContext struct {
	Text      string
	Memory    ShortTermMemory
	Variables map[string]any
	Flow      *Flow
	ImageURLs []string
	Think     string // Stores thinking content extracted from <think> tags in model output
}

FlowContext is the flowContext for a flow. It will be passed to each flow step. The Text field provides the input and output string for a step. For example, before the step runs, the "Text" field is the input string (which might be formatted by the template formatter). After the step runs, the "Text" field is the output string. The Data field could be any data you want to pass between steps.

func NewFlowContext

func NewFlowContext(flowContext string, memory any) *FlowContext

func (*FlowContext) GetVariable

func (fc *FlowContext) GetVariable(name string) any

GetVariable gets the value of a variable. Returns nil if the variable doesn't exist

func (*FlowContext) GetVariableBool

func (fc *FlowContext) GetVariableBool(name string, defaultValue bool) bool

GetVariableBool gets the boolean value of a variable. Returns the defaultValue if the variable doesn't exist or is not a boolean

func (*FlowContext) GetVariableInt

func (fc *FlowContext) GetVariableInt(name string, defaultValue int) int

GetVariableInt gets the integer value of a variable. Returns the defaultValue if the variable doesn't exist or is not an integer

func (*FlowContext) GetVariableString

func (fc *FlowContext) GetVariableString(name string, defaultValue string) string

GetVariableString gets the string value of a variable. Returns the defaultValue if the variable doesn't exist or is not a string

func (*FlowContext) SetVariable

func (fc *FlowContext) SetVariable(name string, value any)

SetVariable sets the value of a variable

func (*FlowContext) UnmarshalJsonText

func (fc *FlowContext) UnmarshalJsonText(entity any) error

func (*FlowContext) WithVariable

func (fc *FlowContext) WithVariable(name string, value any) *FlowContext

WithVariable creates a copy of FlowContext with a new variable set The original FlowContext is not modified

type ShortTermMemory

type ShortTermMemory any

type Step

type Step struct {
	ClientImpl llm.Client

	Executor StepExecutor

	Validator StepValidator

	MaxRetryTimes int
	Name          string
	// contains filtered or unexported fields
}

func NewStep

func NewStep(executor StepExecutor, validator StepValidator, client llm.Client) *Step

func NewStepWithValidator

func NewStepWithValidator(stepConfig any, executor StepExecutor, validator StepValidator, client llm.Client, validateClient llm.Client) *Step

Create a new flow step with executor and validator. Parameters:

  • stepConfig: the configuration of the step. This parameter is used to pass parameters to the executor and validator. This can be a flexible type object which will be used by the executor and validator. We provide a default StepConfig in Anyi, see [LLMFlowStepConfig] for more details.
  • executor: the executor of the step. See StepExecutor for more details.
  • validator: the validator of the step. Set this parameter to nil if you don't want to validate the step output. See StepValidator for more details.
  • client: the default client of the step. If set to nil, the default client of the flow will be used.
  • validateClient: the client used to validate the step output. If set to nil, the default client of the step will be used. If the step doesn't have a default client, the default client of the flow will be used.

func (*Step) GetClient

func (step *Step) GetClient() llm.Client

GetClient function returns the client of the Step. If the clientImpl of the Step is not nil, it returns the clientImpl. Otherwise, it returns nil.

type StepExecutor

type StepExecutor interface {
	Init() error
	Run(flowContext FlowContext, Step *Step) (*FlowContext, error)
}

type StepValidator

type StepValidator interface {
	Init() error
	Validate(stepOutput string, Step *Step) bool
}

StepValidator is the interface for validators of step output. In a flow if a step validator is set, the output of the step will be checked against the validator's Validate method.

Jump to

Keyboard shortcuts

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