llmc

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package llmc provides a public API for the llm-compiler.

This package allows programmatic compilation of YAML workflow definitions into standalone Go binaries with embedded LLM inference capabilities.

Basic usage:

result, err := llmc.CompileFile("workflow.yaml", nil)
if err != nil {
    log.Fatal(err)
}
fmt.Println("Binary:", result.BinaryPath)

With options:

result, err := llmc.CompileFile("workflow.yaml", &llmc.CompileOptions{
    OutputDir:  "./dist",
    OutputName: "my-agent",
})

Programmatic workflow construction:

wf := llmc.NewWorkflow("my-workflow")
wf.AddStep(llmc.ShellStep("greet", "echo 'Hello'").WithOutput("greeting"))
wf.AddStep(llmc.LLMStep("respond", "Respond to: {{greeting}}"))

result, err := llmc.Compile([]*llmc.Workflow{wf}, nil)

Index

Constants

View Source
const (
	// Version is the current version of llm-compiler.
	Version = "0.1.0"

	// MinGoVersion is the minimum required Go version.
	MinGoVersion = "1.21"
)

Version information for the llm-compiler.

Variables

This section is empty.

Functions

func Validate

func Validate(wf *Workflow) error

Validate checks a workflow for errors without compiling it.

Types

type CompileOptions

type CompileOptions struct {
	// OutputDir is the directory where the binary will be placed.
	// Defaults to current directory if not specified.
	OutputDir string

	// OutputName overrides the output binary name.
	// If empty, uses the input filename (without extension) for CompileFile,
	// or the workflow name for Compile.
	OutputName string

	// SkipBuild generates the Go source file but skips compilation to binary.
	// The source file will be saved to OutputDir.
	SkipBuild bool

	// KeepSource saves the generated .go file alongside the binary.
	// Useful for debugging or inspecting the generated code.
	// By default, only the binary is output.
	KeepSource bool

	// Verbose enables detailed output during compilation.
	Verbose bool
}

CompileOptions configures the compilation process.

func ApplyOptions

func ApplyOptions(opts ...Option) *CompileOptions

ApplyOptions applies functional options to CompileOptions.

func DefaultOptions

func DefaultOptions() *CompileOptions

DefaultOptions returns a new CompileOptions with default values.

type CompileResult

type CompileResult struct {
	// SourcePath is the path to the generated Go source file.
	SourcePath string

	// BinaryPath is the path to the compiled binary.
	// Empty if SkipBuild was true.
	BinaryPath string

	// Workflows contains the compiled workflow definitions.
	Workflows []*Workflow
}

CompileResult contains the results of a successful compilation.

func Compile

func Compile(workflows []*Workflow, opts *CompileOptions) (*CompileResult, error)

Compile compiles workflow definitions into a standalone binary.

Use this for programmatically constructed workflows. For YAML files, use CompileFile instead.

Example:

wf := llmc.NewWorkflow("my-workflow")
wf.AddStep(llmc.ShellStep("greet", "echo 'Hello'"))

result, err := llmc.Compile([]*llmc.Workflow{wf}, nil)

func CompileFile

func CompileFile(inputPath string, opts *CompileOptions) (*CompileResult, error)

CompileFile compiles a YAML workflow file into a standalone binary.

The input file can contain single or multiple workflow definitions separated by YAML document markers (---).

Example:

result, err := llmc.CompileFile("workflow.yaml", &llmc.CompileOptions{
    OutputDir: "./build",
})

func CompileFileWith

func CompileFileWith(inputPath string, opts ...Option) (*CompileResult, error)

CompileFileWith compiles a workflow file with functional options.

Example:

result, err := llmc.CompileFileWith("workflow.yaml",
    llmc.WithOutputDir("./dist"),
    llmc.WithVerbose(),
)

func CompileWith

func CompileWith(workflows []*Workflow, opts ...Option) (*CompileResult, error)

CompileWith compiles workflows with functional options.

type Option

type Option func(*CompileOptions)

Option is a functional option for configuring compilation.

func WithKeepSource

func WithKeepSource() Option

WithKeepSource saves the generated .go file alongside the binary.

func WithOutputDir

func WithOutputDir(dir string) Option

WithOutputDir sets the output directory.

func WithOutputName

func WithOutputName(name string) Option

WithOutputName sets the output binary name.

func WithSkipBuild

func WithSkipBuild() Option

WithSkipBuild skips the build step, only generating source.

func WithVerbose

func WithVerbose() Option

WithVerbose enables verbose output.

type Step

type Step struct {
	// Name is the unique identifier for this step within the workflow.
	Name string

	// Type specifies how this step executes (shell, llm, local_llm).
	Type StepType

	// Command is the shell command to execute (for StepTypeShell).
	Command string

	// Prompt is the LLM prompt template (for StepTypeLLM, StepTypeLocalLLM).
	Prompt string

	// Model specifies which LLM model to use.
	Model string

	// MaxTokens limits the LLM response length.
	MaxTokens int

	// Output is the variable name to store this step's result.
	// Can be referenced in subsequent steps via {{output_name}}.
	Output string

	// If is a conditional expression. Step only runs if it evaluates to true.
	// Supports template substitution: "{{mode}} == 'production'"
	If string

	// WaitFor specifies another workflow step to wait for before executing.
	// Format: "workflowName.stepName"
	WaitFor string

	// WaitTimeout is the timeout in seconds when waiting for another step.
	// 0 means wait indefinitely.
	WaitTimeout int
}

Step represents a single step in a workflow.

type StepBuilder

type StepBuilder struct {
	// contains filtered or unexported fields
}

StepBuilder provides a fluent API for constructing steps.

func LLMStep

func LLMStep(name, prompt string) *StepBuilder

LLMStep creates a new remote LLM step.

func LocalLLMStep

func LocalLLMStep(name, prompt string) *StepBuilder

LocalLLMStep creates a new local LLM step (llama.cpp).

func ShellStep

func ShellStep(name, command string) *StepBuilder

ShellStep creates a new shell step.

func (*StepBuilder) Build

func (b *StepBuilder) Build() *Step

Build returns the constructed Step.

func (*StepBuilder) WaitFor

func (b *StepBuilder) WaitFor(stepRef string) *StepBuilder

WaitFor sets a step dependency to wait for.

func (*StepBuilder) WithCondition

func (b *StepBuilder) WithCondition(condition string) *StepBuilder

WithCondition sets a conditional expression for the step.

func (*StepBuilder) WithMaxTokens

func (b *StepBuilder) WithMaxTokens(tokens int) *StepBuilder

WithMaxTokens sets the maximum tokens for LLM response.

func (*StepBuilder) WithModel

func (b *StepBuilder) WithModel(model string) *StepBuilder

WithModel sets the LLM model to use.

func (*StepBuilder) WithOutput

func (b *StepBuilder) WithOutput(output string) *StepBuilder

WithOutput sets the output variable name for the step.

func (*StepBuilder) WithTimeout

func (b *StepBuilder) WithTimeout(seconds int) *StepBuilder

WithTimeout sets the wait timeout in seconds.

type StepType

type StepType string

StepType represents the type of a workflow step.

const (
	// StepTypeShell executes a shell command.
	StepTypeShell StepType = "shell"

	// StepTypeLLM calls a remote LLM API (e.g., OpenAI).
	StepTypeLLM StepType = "llm"

	// StepTypeLocalLLM runs inference locally via llama.cpp.
	StepTypeLocalLLM StepType = "local_llm"
)

type Workflow

type Workflow struct {
	// Name is the unique identifier for this workflow.
	Name string

	// Steps contains the ordered list of workflow steps.
	Steps []*Step
}

Workflow represents a compiled workflow with its steps.

func LoadWorkflows

func LoadWorkflows(inputPath string) ([]*Workflow, error)

LoadWorkflows loads and parses workflow definitions from a YAML file without compiling them. Useful for inspection or modification before compilation.

Example:

workflows, err := llmc.LoadWorkflows("workflow.yaml")
for _, wf := range workflows {
    fmt.Printf("Workflow: %s (%d steps)\n", wf.Name, len(wf.Steps))
}

func NewWorkflow

func NewWorkflow(name string) *Workflow

NewWorkflow creates a new workflow with the given name.

func (*Workflow) AddStep

func (w *Workflow) AddStep(step *Step) *Workflow

AddStep appends a step to the workflow.

Jump to

Keyboard shortcuts

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