Documentation
¶
Index ¶
- func BuildRetryPrompt(code string, execError string, failedCondition string) string
- func BuildSystemPrompt(spec *Spec, language string) string
- func BuildUserPrompt(spec *Spec, args map[string]any) string
- func Execute(ctx context.Context, runner codeact.Runner, spec *Spec, model Model, ...) (*codeact.RunResult, error)
- func ExtractCode(response string) string
- func InferParamType(t reflect.Type) string
- func InferSignature(fn any, language ...string) string
- func SetupRunner(runner codeact.Runner, funcs []GoFuncSpec) error
- func ValidatePostConditions(ctx context.Context, runner codeact.Runner, resultJSON string, ...) (bool, string, error)
- type GoFuncSpec
- type Message
- type Model
- type ModelFunc
- type ParamSpec
- type Spec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildRetryPrompt ¶
BuildRetryPrompt constructs a retry prompt for the LLM after a failure.
func BuildSystemPrompt ¶
BuildSystemPrompt constructs the system prompt for the LLM.
func BuildUserPrompt ¶
BuildUserPrompt constructs the user prompt from spec parameters and argument values.
func Execute ¶
func Execute(ctx context.Context, runner codeact.Runner, spec *Spec, model Model, args map[string]any) (*codeact.RunResult, error)
Execute runs the full AI Function flow: prompt building, LLM call, code execution, post-condition validation, and retry. Callers must call SetupRunner before Execute if GoFuncs are used.
func ExtractCode ¶
ExtractCode extracts code from an LLM response, stripping markdown fences if present. Handles fences at any position in the text (e.g. preceded by explanation).
func InferParamType ¶
InferParamType maps a Go reflect.Type to a JSON Schema type string.
func InferSignature ¶
InferSignature returns a human-readable signature string for a Go function. An optional language ("javascript" or "python") maps Go types to target language types. With no language argument, Go type names are used as-is.
func SetupRunner ¶
func SetupRunner(runner codeact.Runner, funcs []GoFuncSpec) error
SetupRunner registers Go functions from the spec with the runner. The runner must implement RegisterAnyFunc(name string, fn any) error.
func ValidatePostConditions ¶
func ValidatePostConditions(ctx context.Context, runner codeact.Runner, resultJSON string, conditions []string) (bool, string, error)
ValidatePostConditions validates post-conditions by running them on the runner. The result JSON is injected as a `result` variable so post-condition expressions can reference it regardless of the original code's variable scoping. Returns (true, "", nil) on success, or (false, failureMessage, nil) on validation failure. Infrastructure errors are returned as the error value.
Types ¶
type GoFuncSpec ¶
type GoFuncSpec struct {
Name string
Fn any
Signature string // Human-readable signature for prompts
}
GoFuncSpec defines a Go function exposed to LLM-generated code.
type Model ¶
type Model interface {
Generate(ctx context.Context, systemPrompt string, messages []Message) (string, error)
}
Model is the interface adapters use to call the LLM for code generation.