Documentation
¶
Index ¶
- func BuildGenerateOptions(opts ...GenerationOption) []core.GenerateOption
- func GenerateStruct[T any](ctx context.Context, gen core.TextGenerator, sysPrompt string, userReq string) (T, error)
- func GetGenkit(ctx context.Context) *genkit.Genkit
- func InitMiddlewarePlugin(ctx context.Context, g *genkit.Genkit) error
- func NewGenkitAction(ctx context.Context, modelName string) (core.Action, error)
- func NewGenkitAdapter(model ai.Model, gk *genkit.Genkit) core.TextGenerator
- func WithCustomMiddleware(mw ...ai.Middleware) core.GenerateOption
- func WithFallback(modelRefs []ai.ModelRef) core.GenerateOption
- func WithFilesystem(rootDir string, allowWrite bool) core.GenerateOption
- func WithMiddleware(cfg *MiddlewareConfig) core.GenerateOption
- func WithRetry(maxRetries int) core.GenerateOption
- func WithRetryAndBackoff(maxRetries, initialDelayMs, maxDelayMs int) core.GenerateOption
- func WithToolApproval(allowedTools []string) core.GenerateOption
- type DatalogValidator
- type Example
- type FlowRegistry
- type GenerationOption
- func WithDatalogValidator(...) GenerationOption
- func WithFallbackMiddleware(models ...ai.ModelRef) GenerationOption
- func WithFilesystemMiddleware(rootDir string, allowWrite bool) GenerationOption
- func WithGenerationConfig(cfg *core.GenerationConfig) GenerationOption
- func WithLogging(logger core.Logger) GenerationOption
- func WithRetryMiddleware(maxRetries int) GenerationOption
- func WithTelemetry(...) GenerationOption
- func WithToolApprovalMiddleware(allowedTools ...string) GenerationOption
- type GenerationSettings
- type LLMAction
- func (a *LLMAction) Complete(ctx context.Context, prompt string) (string, error)
- func (a *LLMAction) Execute(ctx context.Context, input core.Envelope) (core.Envelope, error)
- func (a *LLMAction) Generate(ctx context.Context, prompt string, opts ...core.GenerateOption) (*core.LLMResponse, error)
- func (a *LLMAction) Metadata() core.ActionMetadata
- func (a *LLMAction) Stream(ctx context.Context, prompt string) (<-chan string, error)
- type LoggingMiddleware
- type MiddlewareConfig
- type OODAExecutor
- func (e *OODAExecutor) Execute(ctx context.Context, input *OODAFlowInput) (*OODAFlowOutput, error)
- func (e *OODAExecutor) WithMaxRetries(maxRetries int) *OODAExecutor
- func (e *OODAExecutor) WithMiddleware(mw ...ai.Middleware) *OODAExecutor
- func (e *OODAExecutor) WithTimeout(timeout time.Duration) *OODAExecutor
- type OODAExecutorConfig
- type OODAFlow
- type OODAFlowConfig
- type OODAFlowInput
- type OODAFlowOutput
- type OODAFlowWithMiddleware
- type OODAGenkitBridge
- type TelemetryMiddleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildGenerateOptions ¶
func BuildGenerateOptions(opts ...GenerationOption) []core.GenerateOption
BuildGenerateOptions converts GenerationSettings to core.GenerateOption slice.
func GenerateStruct ¶
func GetGenkit ¶
GetGenkit returns the global Genkit instance, initializing it if necessary. This allows other packages to register models/tools.
func InitMiddlewarePlugin ¶
InitMiddlewarePlugin registers the middleware plugin with the Genkit instance. This enables middleware to be visible in the Dev UI.
func NewGenkitAction ¶
NewGenkitAction creates a new core.Action backed by a Genkit model. It ensures the Genkit runtime is initialized and looks up the model by name.
func NewGenkitAdapter ¶
NewGenkitAdapter creates a new adapter from a pre-initialized Genkit model.
Parameters:
- model: The Genkit model instance.
- gk: The Genkit runtime instance.
Returns:
- A core.TextGenerator implementation.
func WithCustomMiddleware ¶
func WithCustomMiddleware(mw ...ai.Middleware) core.GenerateOption
WithCustomMiddleware adds arbitrary genkit middleware to the generation.
func WithFallback ¶
func WithFallback(modelRefs []ai.ModelRef) core.GenerateOption
WithFallback enables model fallback when the primary model fails.
func WithFilesystem ¶
func WithFilesystem(rootDir string, allowWrite bool) core.GenerateOption
WithFilesystem enables scoped file system access for the model.
func WithMiddleware ¶
func WithMiddleware(cfg *MiddlewareConfig) core.GenerateOption
WithMiddleware is a GenerateOption that injects genkit middleware into generation.
func WithRetry ¶
func WithRetry(maxRetries int) core.GenerateOption
WithRetry enables automatic retry with the specified configuration.
func WithRetryAndBackoff ¶
func WithRetryAndBackoff(maxRetries, initialDelayMs, maxDelayMs int) core.GenerateOption
WithRetryAndBackoff enables retry with custom backoff parameters.
func WithToolApproval ¶
func WithToolApproval(allowedTools []string) core.GenerateOption
WithToolApproval requires explicit approval for all tool calls.
Types ¶
type DatalogValidator ¶
type DatalogValidator struct {
// Validator is called before and after generation to enforce Datalog rules.
Validator func(ctx context.Context, phase string, req *ai.ModelRequest, resp *ai.ModelResponse) error
}
DatalogValidator is a custom middleware that validates generation input/output using Datalog rules before and after model calls.
func (*DatalogValidator) Name ¶
func (d *DatalogValidator) Name() string
type Example ¶
type Example struct{}
Example: Complete generation with all middleware
func (*Example) GenerateWithFullMiddleware ¶
func (e *Example) GenerateWithFullMiddleware( ctx context.Context, gen core.TextGenerator, prompt string, ) (*core.LLMResponse, error)
GenerateWithFullMiddleware demonstrates using all middleware features.
type FlowRegistry ¶
type FlowRegistry struct {
// contains filtered or unexported fields
}
func NewFlowRegistry ¶
func NewFlowRegistry(g *genkit.Genkit) *FlowRegistry
func (*FlowRegistry) Register ¶
func (r *FlowRegistry) Register(name string, flow *OODAFlow)
func (*FlowRegistry) RegisterAndDefine ¶
func (r *FlowRegistry) RegisterAndDefine(name string, flow *OODAFlow)
func (*FlowRegistry) Run ¶
func (r *FlowRegistry) Run(ctx context.Context, name string, input *OODAFlowInput) (*OODAFlowOutput, error)
type GenerationOption ¶
type GenerationOption func(*GenerationSettings)
GenerationOption is a functional option for configuring generation with middleware.
func WithDatalogValidator ¶
func WithDatalogValidator(validator func(ctx context.Context, phase string, req *ai.ModelRequest, resp *ai.ModelResponse) error) GenerationOption
WithDatalogValidator adds Datalog validation middleware.
func WithFallbackMiddleware ¶
func WithFallbackMiddleware(models ...ai.ModelRef) GenerationOption
WithFallbackMiddleware enables fallback to alternative models.
func WithFilesystemMiddleware ¶
func WithFilesystemMiddleware(rootDir string, allowWrite bool) GenerationOption
WithFilesystemMiddleware enables scoped filesystem access.
func WithGenerationConfig ¶
func WithGenerationConfig(cfg *core.GenerationConfig) GenerationOption
WithGenerationConfig sets the base generation config.
func WithLogging ¶
func WithLogging(logger core.Logger) GenerationOption
WithLogging adds logging middleware.
func WithRetryMiddleware ¶
func WithRetryMiddleware(maxRetries int) GenerationOption
WithRetryMiddleware enables retry middleware with default settings.
func WithTelemetry ¶
func WithTelemetry(onGenerate func(ctx context.Context, duration time.Duration, model string, inputTokens, outputTokens int)) GenerationOption
WithTelemetry adds telemetry collection middleware.
func WithToolApprovalMiddleware ¶
func WithToolApprovalMiddleware(allowedTools ...string) GenerationOption
WithToolApprovalMiddleware requires approval for tool execution.
type GenerationSettings ¶
type GenerationSettings struct {
Config *core.GenerationConfig
Middleware *MiddlewareConfig
}
GenerationSettings holds all generation configuration including middleware.
type LLMAction ¶
type LLMAction struct {
// contains filtered or unexported fields
}
LLMAction is a concrete implementation of core.Action that wraps a core.TextGenerator. It adapts the specific TextGenerator interface to the universal core.Action envelope interface.
func NewLLMAction ¶
func NewLLMAction(name string, generator core.TextGenerator) (*LLMAction, error)
NewLLMAction creates a new LLMAction instance.
Parameters:
- name: A unique name for this action (used in observability and policies).
- generator: The TextGenerator implementation to wrap.
Returns:
- A pointer to the initialized LLMAction.
- An error if the generator is nil.
func (*LLMAction) Execute ¶
Execute performs the text generation. It expects the input Envelope's Payload to be a string (the prompt). It returns a new Envelope containing the generated text as the Payload.
Parameters:
- ctx: The execution context.
- input: The input envelope containing the prompt string.
Returns:
- A result envelope with the generated text, or an error.
func (*LLMAction) Generate ¶
func (a *LLMAction) Generate(ctx context.Context, prompt string, opts ...core.GenerateOption) (*core.LLMResponse, error)
Generate implements core.TextGenerator.
func (*LLMAction) Metadata ¶
func (a *LLMAction) Metadata() core.ActionMetadata
Metadata returns the static metadata for this action.
type LoggingMiddleware ¶
LoggingMiddleware is a custom middleware that logs generation details.
func (*LoggingMiddleware) Name ¶
func (l *LoggingMiddleware) Name() string
type MiddlewareConfig ¶
type MiddlewareConfig struct {
// Retry configures automatic retry with exponential backoff.
Retry *middleware.Retry
// Fallback configures alternative model fallback on failure.
Fallback *middleware.Fallback
// ToolApproval requires explicit approval for tool execution.
ToolApproval *middleware.ToolApproval
// Filesystem enables scoped file system access for the model.
Filesystem *middleware.Filesystem
// CustomMiddlewares allows injecting arbitrary middleware.
CustomMiddlewares []ai.Middleware
}
MiddlewareConfig holds genkit middleware settings for a generation call. Use this with GenerateOption to configure per-call middleware.
func ComposeMiddleware ¶
func ComposeMiddleware(opts ...GenerationOption) (*MiddlewareConfig, error)
ComposeMiddleware creates a single MiddlewareConfig from multiple options. This is useful when you want to build middleware incrementally.
type OODAExecutor ¶
type OODAExecutor struct {
// contains filtered or unexported fields
}
func NewOODAExecutor ¶
func NewOODAExecutor(cfg *OODAExecutorConfig) *OODAExecutor
func (*OODAExecutor) Execute ¶
func (e *OODAExecutor) Execute(ctx context.Context, input *OODAFlowInput) (*OODAFlowOutput, error)
func (*OODAExecutor) WithMaxRetries ¶
func (e *OODAExecutor) WithMaxRetries(maxRetries int) *OODAExecutor
func (*OODAExecutor) WithMiddleware ¶
func (e *OODAExecutor) WithMiddleware(mw ...ai.Middleware) *OODAExecutor
func (*OODAExecutor) WithTimeout ¶
func (e *OODAExecutor) WithTimeout(timeout time.Duration) *OODAExecutor
type OODAExecutorConfig ¶
type OODAExecutorConfig struct {
MaxRetries int
Timeout time.Duration
Middleware []ai.Middleware
KnowledgeStore ports.KnowledgeStore
TransientStore ports.TransientStore
}
type OODAFlow ¶
type OODAFlow struct {
// contains filtered or unexported fields
}
func NewOODAFlow ¶
func NewOODAFlow(cfg *OODAFlowConfig) *OODAFlow
func (*OODAFlow) DefineStreamingFlow ¶
func (*OODAFlow) Run ¶
func (f *OODAFlow) Run(ctx context.Context, input *OODAFlowInput) (*OODAFlowOutput, error)
type OODAFlowConfig ¶
type OODAFlowConfig struct {
Memory ooda.Memory
Brain ooda.Brain
Executor ooda.Executor
Dispatcher *ooda.Dispatcher
KnowledgeStore ports.KnowledgeStore
TransientStore ports.TransientStore
MaxRetries int
Timeout time.Duration
GenerateOptions []core.GenerateOption
}
type OODAFlowInput ¶
type OODAFlowOutput ¶
type OODAFlowWithMiddleware ¶
type OODAFlowWithMiddleware struct {
*OODAFlow
// contains filtered or unexported fields
}
func NewOODAFlowWithGenkit ¶
func NewOODAFlowWithGenkit(cfg *OODAFlowConfig, g *genkit.Genkit) *OODAFlowWithMiddleware
func (*OODAFlowWithMiddleware) Run ¶
func (f *OODAFlowWithMiddleware) Run(ctx context.Context, input *OODAFlowInput) (*OODAFlowOutput, error)
type OODAGenkitBridge ¶
type OODAGenkitBridge struct {
// contains filtered or unexported fields
}
func NewOODAGenkitBridge ¶
func NewOODAGenkitBridge(g *genkit.Genkit, cfg *OODAFlowConfig) *OODAGenkitBridge
func (*OODAGenkitBridge) DefineOODAFlow ¶
func (b *OODAGenkitBridge) DefineOODAFlow(name string)
func (*OODAGenkitBridge) DefineOODAStreamingFlow ¶
func (b *OODAGenkitBridge) DefineOODAStreamingFlow(name string)
func (*OODAGenkitBridge) RunOODA ¶
func (b *OODAGenkitBridge) RunOODA(ctx context.Context, input *OODAFlowInput) (*OODAFlowOutput, error)
type TelemetryMiddleware ¶
type TelemetryMiddleware struct {
OnGenerate func(ctx context.Context, duration time.Duration, model string, inputTokens, outputTokens int)
}
TelemetryMiddleware is a custom middleware that records generation metrics.
func (*TelemetryMiddleware) Name ¶
func (t *TelemetryMiddleware) Name() string