Documentation
¶
Index ¶
- func Must(name string, handlers ...minds.ThreadHandler) *mustHandler
- func PolicyValidator(llm minds.ContentGenerator, name, systemPrompt string, ...) *policyValidator
- func Sequential(name string, handlers ...minds.ThreadHandler) *sequential
- func Summerize(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 HandlerOption
- type PolicyResultFunc
- type ValidationResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Must ¶
func Must(name string, handlers ...minds.ThreadHandler) *mustHandler
Must creates a handler that ensures all provided handlers succeed in parallel. If any handler fails, the others are canceled, and the first error is returned.
func PolicyValidator ¶
func PolicyValidator(llm minds.ContentGenerator, name, systemPrompt string, resultFn PolicyResultFunc) *policyValidator
PolicyValidator 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 Sequential ¶
func Sequential(name string, handlers ...minds.ThreadHandler) *sequential
Sequential creates a ThreadHandler that executes a series of handlers in sequence. If any handler returns an error, the sequence stops, and the error is returned. You can add handlers to the sequence after construction using AddHandler or AddHandlers. Optionally, you can specify a handler as middleware with the `Use` method.
Example:
this := DoThisHandler()
that := DoThatHandler()
llm := LLMHandler()
// Sequentially run `this` -> `llm` -> `that` handlers
seq := Sequential("example", this, llm, that)
finalThread, err := seq.HandleThread(initialThread, nil)
if err != nil {
log.Fatalf("Error handling thread: %v", err)
}
fmt.Println("Final thread:", finalThread.Messaages.Last().Content)
func Summerize ¶
func Summerize(provider minds.ContentGenerator, systemMsg string) *summarize
Summerize creates a new summarizer handler with the given LLM provider and system message. The summarizer will prompt the LLM provider to summarize the conversation so far and append the summary to the system message.
The summary is stored in the handler and will be used for further summaries.
The summarizer will not modify the thread context. It will duplicate the thread context, setting the first message to the original system message appended with the current summary.
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 HandlerOption ¶
type HandlerOption struct {
// contains filtered or unexported fields
}
type PolicyResultFunc ¶
type PolicyResultFunc func(ctx context.Context, tc minds.ThreadContext, res ValidationResult) 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 ValidationResult ¶
type ValidationResult 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"`
}
ValidationResult represents the outcome of a policy validation.