Documentation
¶
Index ¶
- func DefaultAggregator(results []HandlerResult) (minds.ThreadContext, error)
- func NewSequence(name string, handlers ...minds.ThreadHandler) *sequence
- func Noop() *noop
- func Summarize(provider minds.ContentGenerator, systemMsg string) *summarize
- func WithDescription(description string) func(*HandlerOption)
- func WithName(name string) func(*HandlerOption)
- func WithPrompt(prompt minds.Prompt) func(*HandlerOption)
- type BoolResp
- type ConditionFunc
- type First
- type For
- type ForConditionFn
- type HandlerOption
- type HandlerResult
- type If
- type LLMCondition
- type MetadataEquals
- type Must
- type Policy
- type PolicyResult
- type PolicyResultFunc
- type Range
- type ResultAggregator
- type Switch
- type SwitchCase
- type SwitchCondition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAggregator ¶ added in v0.0.5
func DefaultAggregator(results []HandlerResult) (minds.ThreadContext, error)
DefaultAggregator combines results by merging contexts in order. Merging is done by starting with the first successful context and merging all subsequent successful contexts into it. If no successful contexts are found, an error is returned.
Metadata merging is done with the minds.KeepNew strategy, which overwrites existing values with new values. Messages are appended in order.
Parameters:
- results: List of handler results to aggregate
Returns:
- A single thread context that combines all successful results
func NewSequence ¶ added in v0.0.6
func NewSequence(name string, handlers ...minds.ThreadHandler) *sequence
NewSequence creates a new Sequence handler with the given name and handlers. The sequence executes handlers in order, stopping on the first error.
Example:
validate := NewValidationHandler()
process := NewProcessingHandler()
// Create a sequence with retry middleware
seq := NewSequence("main", validate, process)
seq.Use(RetryMiddleware())
// Or create a variation with different middleware
timeoutSeq := seq.With(TimeoutMiddleware())
result, err := seq.HandleThread(tc, nil)
func Noop ¶ added in v0.0.6
func Noop() *noop
Noop creates a new no-operation handler that simply returns the thread context unchanged. It's useful as a default handler in Switch or If handlers when no action is desired for the default case.
Example:
// Use as default in Switch
sw := Switch("type-switch", Noop(), cases...)
// Use as default in If
ih := If("type-check", condition, trueHandler, Noop())
func Summarize ¶ added in v0.0.4
func Summarize(provider minds.ContentGenerator, systemMsg string) *summarize
Summarize creates a handler that maintains a running summary of thread messages.
The handler prompts an LLM to generate a concise summary of all messages in the thread, focusing on key information. The summary is appended to the system message in XML tags and persists across handler invocations.
Parameters:
- provider: LLM content generator for creating summaries.
- systemMsg: Initial system message to prepend to summaries.
Returns:
- A handler that maintains thread summaries via LLM generation.
Note: The original thread context is not modified; a new context with the updated system message is created.
func WithDescription ¶
func WithDescription(description string) func(*HandlerOption)
func WithName ¶
func WithName(name string) func(*HandlerOption)
func WithPrompt ¶
func WithPrompt(prompt minds.Prompt) func(*HandlerOption)
Types ¶
type BoolResp ¶ added in v0.0.6
type BoolResp struct {
Bool bool `json:"bool"`
}
BoolResp represents the expected JSON response format from the LLM.
type ConditionFunc ¶ added in v0.0.7
type ConditionFunc func(tc minds.ThreadContext) (bool, error)
func (ConditionFunc) Evaluate ¶ added in v0.0.7
func (f ConditionFunc) Evaluate(tc minds.ThreadContext) (bool, error)
type First ¶ added in v0.0.3
type First struct {
// contains filtered or unexported fields
}
First represents a handler that executes multiple handlers in parallel and returns on first success. Each handler runs in its own goroutine, and execution of remaining handlers is canceled once a successful result is obtained.
func NewFirst ¶ added in v0.0.6
func NewFirst(name string, handlers ...minds.ThreadHandler) *First
NewFirst creates a handler that runs multiple handlers in parallel and returns on first success. If all handlers fail, an error containing all handler errors is returned. If no handlers are provided, the thread context is passed to the next handler unmodified.
Parameters:
- name: Identifier for this parallel handler group
- handlers: Variadic list of handlers to execute in parallel
Returns:
- A First handler configured with the provided handlers
Example:
first := handlers.NewFirst("validation",
validateA,
validateB,
validateC,
)
func (*First) HandleThread ¶ added in v0.0.6
func (f *First) HandleThread(tc minds.ThreadContext, next minds.ThreadHandler) (minds.ThreadContext, error)
HandleThread executes the First handler by running child handlers in parallel and returning on first success.
func (*First) Use ¶ added in v0.0.6
func (f *First) Use(middleware ...minds.Middleware)
Use applies middleware to the First handler, wrapping its child handlers.
func (*First) With ¶ added in v0.0.6
func (f *First) With(middleware ...minds.Middleware) minds.ThreadHandler
With returns a new First handler with the provided middleware applied.
type For ¶ added in v0.0.3
type For struct {
// contains filtered or unexported fields
}
For represents a handler that repeats processing based on iterations and conditions. It supports both fixed iteration counts and conditional execution through a continuation function.
func NewFor ¶ added in v0.0.6
func NewFor(name string, iterations int, handler minds.ThreadHandler, fn ForConditionFn) *For
NewFor creates a handler that repeats processing based on iterations and conditions.
A continuation function can optionally control the loop based on the ThreadContext and iteration count. The handler runs either until the iteration count is reached, the continuation function returns false, or infinitely if iterations is 0.
Parameters:
- name: Identifier for this loop handler
- iterations: Number of iterations (0 for infinite)
- handler: The handler to repeat
- fn: Optional function controlling loop continuation
Returns:
- A handler that implements controlled repetition of processing
Example:
loop := NewFor("validation", 3, validateHandler, func(tc ThreadContext, i int) bool {
return tc.ShouldContinue()
})
func (*For) HandleThread ¶ added in v0.0.6
func (f *For) HandleThread(tc minds.ThreadContext, next minds.ThreadHandler) (minds.ThreadContext, error)
HandleThread implements the ThreadHandler interface
func (*For) Use ¶ added in v0.0.6
func (f *For) Use(middleware ...minds.Middleware)
Use adds middleware to the handler
func (*For) With ¶ added in v0.0.6
func (f *For) With(middleware ...minds.Middleware) minds.ThreadHandler
With returns a new handler with the provided middleware
type ForConditionFn ¶ added in v0.0.3
type ForConditionFn func(tc minds.ThreadContext, iteration int) bool
ForConditionFn defines a function type that controls loop continuation based on the current thread context and iteration count.
type HandlerOption ¶
type HandlerOption struct {
// contains filtered or unexported fields
}
type HandlerResult ¶ added in v0.0.5
type HandlerResult struct {
Handler minds.ThreadHandler
Context minds.ThreadContext
Error error
}
HandlerResult represents the result of executing a single handler
type If ¶ added in v0.0.6
type If struct {
// contains filtered or unexported fields
}
If represents a conditional handler that executes one of two handlers based on a condition evaluation. It's a simplified version of Switch for binary conditions.
func NewIf ¶ added in v0.0.6
func NewIf(name string, condition SwitchCondition, trueHandler minds.ThreadHandler, fallbackHandler minds.ThreadHandler) *If
NewIf creates a new If handler that executes trueHandler when the condition evaluates to true, otherwise executes fallbackHandler if provided.
Parameters:
- name: Identifier for this conditional handler
- condition: The condition to evaluate
- trueHandler: Handler to execute when condition is true
- fallbackHandler: Optional handler to execute when condition is false
Returns:
- A handler that implements conditional execution based on the provided condition
Example:
metadata := MetadataEquals{Key: "type", Value: "question"}
questionHandler := SomeQuestionHandler()
defaultHandler := DefaultHandler()
ih := NewIf("type-check", metadata, questionHandler, defaultHandler)
func (*If) HandleThread ¶ added in v0.0.6
func (h *If) HandleThread(tc minds.ThreadContext, next minds.ThreadHandler) (minds.ThreadContext, error)
HandleThread implements the ThreadHandler interface
func (*If) Use ¶ added in v0.0.6
func (h *If) Use(middleware ...minds.Middleware)
Use adds middleware to the handler
func (*If) With ¶ added in v0.0.6
func (h *If) With(middleware ...minds.Middleware) minds.ThreadHandler
With returns a new handler with the provided middleware
type LLMCondition ¶ added in v0.0.4
type LLMCondition struct {
Generator minds.ContentGenerator
Prompt string
}
LLMCondition evaluates a condition using an LLM response.
func (LLMCondition) Evaluate ¶ added in v0.0.4
func (l LLMCondition) Evaluate(tc minds.ThreadContext) (bool, error)
Evaluate sends a prompt to the LLM and expects a boolean response.
type MetadataEquals ¶ added in v0.0.4
type MetadataEquals struct {
Key string
Value interface{}
}
MetadataEquals checks if a metadata key equals a specific value.
func (MetadataEquals) Evaluate ¶ added in v0.0.4
func (m MetadataEquals) Evaluate(tc minds.ThreadContext) (bool, error)
Evaluate checks if the metadata value for the specified key equals the target value.
type Must ¶
type Must struct {
// contains filtered or unexported fields
}
Must represents a handler that runs multiple handlers in parallel requiring all to succeed
func NewMust ¶ added in v0.0.6
func NewMust(name string, agg ResultAggregator, handlers ...minds.ThreadHandler) *Must
NewMust creates a handler that runs multiple handlers in parallel with all-success semantics.
All handlers execute concurrently and must complete successfully. If any handler fails, remaining handlers are canceled and the first error encountered is returned. The timing of which error is returned is nondeterministic due to parallel execution.
Parameters:
- name: Identifier for this parallel handler group
- agg: ResultAggregator function to combine successful results
- handlers: Variadic list of handlers that must all succeed
Returns:
- A handler that implements parallel execution with all-success semantics
Example:
must := handlers.NewMust("validation",
handlers.DefaultAggregator,
validateA,
validateB,
validateC,
)
func (*Must) HandleThread ¶ added in v0.0.6
func (m *Must) HandleThread(tc minds.ThreadContext, next minds.ThreadHandler) (minds.ThreadContext, error)
HandleThread executes all child handlers in parallel, requiring all to succeed.
func (*Must) Use ¶ added in v0.0.6
func (m *Must) Use(middleware ...minds.Middleware)
Use applies middleware to the Must handler, wrapping its child handlers.
type Policy ¶ added in v0.0.3
type Policy struct {
// contains filtered or unexported fields
}
Policy performs policy validation on thread content using a content generator (LLM).
func NewPolicy ¶ added in v0.0.6
func NewPolicy(llm minds.ContentGenerator, name, systemPrompt string, resultFn PolicyResultFunc) *Policy
NewPolicy creates a new policy validator handler.
The handler uses an LLM to validate thread content against a given policy. A system prompt is used to guide the validation process, and the result is processed by the optional result function. If the result function is nil, the handler defaults to checking the `Valid` field of the validation result.
Parameters:
- llm: A content generator for generating validation responses.
- name: The name of the policy validator.
- systemPrompt: A prompt describing the policy validation rules.
- resultFn: (Optional) Function to process validation results.
Returns:
- A thread handler that validates thread content against a policy.
func (*Policy) HandleThread ¶ added in v0.0.6
func (h *Policy) HandleThread(tc minds.ThreadContext, next minds.ThreadHandler) (minds.ThreadContext, error)
validate implements the core policy validation logic
type PolicyResult ¶ added in v0.0.3
type PolicyResult struct {
Valid bool `json:"valid" description:"Whether the content passes policy validation"`
Reason string `json:"reason" description:"Explanation for the validation result"`
Violation string `json:"violation" description:"Description of the specific violation if any"`
}
PolicyResult represents the outcome of a policy validation.
type PolicyResultFunc ¶
type PolicyResultFunc func(ctx context.Context, tc minds.ThreadContext, res PolicyResult) error
PolicyResultFunc defines a function to handle the result of a policy validation. It takes a context, thread context, and validation result, and returns an error if the validation fails or cannot be processed.
type Range ¶ added in v0.0.2
type Range struct {
// contains filtered or unexported fields
}
Range executes a handler multiple times with different values. For each value in the provided list, the handler executes with the value stored in the thread context's metadata under the key "range_value". The handler supports middleware that will be applied to each iteration.
func NewRange ¶ added in v0.0.6
func NewRange(name string, handler minds.ThreadHandler, values ...any) *Range
NewRange creates a handler that processes a thread with a series of values.
Parameters:
- name: Identifier for this range handler
- handler: The handler to execute for each value
- values: Values to iterate over
Returns:
- A Range handler that processes the thread once for each value
Example:
rng := NewRange("process",
processHandler,
"value1", "value2", "value3",
)
func (*Range) HandleThread ¶ added in v0.0.6
func (r *Range) HandleThread(tc minds.ThreadContext, next minds.ThreadHandler) (minds.ThreadContext, error)
HandleThread implements the ThreadHandler interface
func (*Range) Use ¶ added in v0.0.6
func (r *Range) Use(middleware ...minds.Middleware)
Use adds middleware to the handler
func (*Range) With ¶ added in v0.0.6
func (r *Range) With(middleware ...minds.Middleware) minds.ThreadHandler
With returns a new handler with the provided middleware
type ResultAggregator ¶ added in v0.0.5
type ResultAggregator func([]HandlerResult) (minds.ThreadContext, error)
ResultAggregator defines a function type for combining multiple handler results
type Switch ¶ added in v0.0.4
type Switch struct {
// contains filtered or unexported fields
}
Switch executes the first matching case's handler, or the default handler if no cases match.
func NewSwitch ¶ added in v0.0.6
func NewSwitch(name string, defaultHandler minds.ThreadHandler, cases ...SwitchCase) *Switch
NewSwitch creates a new Switch handler that executes the first matching case's handler. If no cases match, it executes the default handler. The name parameter is used for debugging and logging purposes.
The SwitchCase struct pairs a `SwitchCondition` interface with a handler. When the condition evaluates to true, the corresponding handler is executed.
Example:
// The MetadataEquals condition checks if the metadata key "type" equals "question"
metadata := MetadataEquals{Key: "type", Value: "question"}
questionHandler := SomeQuestionHandler()
defaultHandler := DefaultHandler()
sw := Switch("type-switch",
defaultHandler,
SwitchCase{metadata, questionHandler},
)
func (*Switch) HandleThread ¶ added in v0.0.6
func (s *Switch) HandleThread(tc minds.ThreadContext, next minds.ThreadHandler) (minds.ThreadContext, error)
HandleThread processes the thread context, executing the first matching case's handler.
func (*Switch) String ¶ added in v0.0.6
String returns a string representation of the Switch handler.
func (*Switch) Use ¶ added in v0.0.6
func (s *Switch) Use(middleware ...minds.Middleware)
Use applies middleware to the Switch handler.
type SwitchCase ¶ added in v0.0.4
type SwitchCase struct {
Condition SwitchCondition
Handler minds.ThreadHandler
}
SwitchCase pairs a condition with a handler. When the condition evaluates to true, the corresponding handler is executed.
type SwitchCondition ¶ added in v0.0.4
type SwitchCondition interface {
// Evaluate examines the thread context and returns true if the condition is met.
// It returns an error if the evaluation fails.
Evaluate(tc minds.ThreadContext) (bool, error)
}
SwitchCondition represents a condition that can be evaluated against a thread context. Implementations of this interface are used by the Switch handler to determine which case should be executed.