compiler

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWorkflowContext

func NewWorkflowContext(ctx context.Context, input any) context.Context

NewWorkflowContext creates a new workflow context embedded in Go context

Types

type Agent

type Agent struct {
	Node *ast.AgentNode
	// contains filtered or unexported fields
}

Agent represents a compiled agent bound with a thinker state machine.

func (*Agent) Prompt

func (agt *Agent) Prompt(ctx context.Context, input any, opt ...chatter.Opt) (any, error)

Prompt executes the agent with given input and returns the output

type AgentStep

type AgentStep struct {
	Agent      *Agent
	OutputName string
	Retry      *Retry
}

AgentStep is a simple agent execution step

func (*AgentStep) GetOutputName

func (step *AgentStep) GetOutputName() string

GetOutputName returns the name to store output under

func (*AgentStep) Prompt

func (step *AgentStep) Prompt(ctx context.Context, opt ...chatter.Opt) error

Prompt executes the agent

type Compiler

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

Compiler compiles AST to executable workflow

func New

func New(llm chatter.Chatter) (*Compiler, error)

New creates a new compiler

func (*Compiler) Compile

func (c *Compiler) Compile(ctx context.Context, tree *ast.AST) (*Workflow, error)

Compile validates AST and compiles to executable workflow

type ForeachStep

type ForeachStep struct {
	UsesAgent  *Agent      // Optional: agent to generate array
	Selector   cel.Program // Optional: CEL program to extract array
	Job        *Job        // Job to execute for each item (resolved)
	JobName    string      // Job name for resolution
	OutputName string
	Retry      *Retry
	Formatter  Formatter // Output serialization format
}

ForeachStep executes a job for each item in an array

func (*ForeachStep) GetOutputName

func (step *ForeachStep) GetOutputName() string

GetOutputName returns the name to store output under

func (*ForeachStep) Prompt

func (step *ForeachStep) Prompt(ctx context.Context, opt ...chatter.Opt) error

Prompt executes the foreach step

type Formatter added in v0.1.11

type Formatter interface {
	// Format converts array of results into serialized output.
	// Input: results from foreach iterations ([]any)
	// Output: serialized data (any) - typically string or []any
	Format(results []any) (any, error)
}

Formatter serializes foreach results into output format. This is a CODEC for result serialization, NOT a reduce function.

Use cases:

  • JSON: Structured arrays for downstream processing
  • JSONL: Streaming-friendly newline-delimited JSON
  • Text: Human-readable concatenation with custom delimiters

func NewFormatter added in v0.1.11

func NewFormatter(format *ast.FormatNode) (Formatter, error)

NewFormatter creates formatter based on AST format node. Returns appropriate formatter or error for unknown types.

type JSONFormatter added in v0.1.11

type JSONFormatter struct{}

JSONFormatter returns results as JSON array (default). Output: Go slice ([]any) that will be JSON-encoded downstream.

func NewJSONFormatter added in v0.1.11

func NewJSONFormatter() *JSONFormatter

NewJSONFormatter creates a JSON array formatter

func (*JSONFormatter) Format added in v0.1.11

func (f *JSONFormatter) Format(results []any) (any, error)

Format returns results as-is (already a Go array). Downstream JSON encoding will serialize it as [...].

type JSONLFormatter added in v0.1.11

type JSONLFormatter struct{}

JSONLFormatter returns results as newline-delimited JSON. Each result on separate line, suitable for streaming.

func NewJSONLFormatter added in v0.1.11

func NewJSONLFormatter() *JSONLFormatter

NewJSONLFormatter creates a JSONL formatter

func (*JSONLFormatter) Format added in v0.1.11

func (f *JSONLFormatter) Format(results []any) (any, error)

Format converts results to JSONL string. Each result encoded as JSON on separate line.

type Job

type Job struct {
	Name  string
	Steps []Step
}

Job represents a compiled job with executable steps

func (*Job) Prompt

func (job *Job) Prompt(ctx context.Context, input any, opt ...chatter.Opt) (any, error)

type Retry

type Retry struct {
	Attempts int
	Delay    int
	Yield    *Agent
}

type RouterStep

type RouterStep struct {
	Agent      *Agent
	OutputName string
	RouteNodes []ast.RouteNode // For reference
	Conditions []cel.Program   // Compiled CEL expressions
	Routes     map[string]*Job // Resolved job references
	DefaultJob string          // Default job name
	Default    *Job            // Resolved default job
	Retry      *Retry
}

RouterStep is a conditional routing step

func (*RouterStep) GetOutputName

func (step *RouterStep) GetOutputName() string

GetOutputName returns the name to store output under

func (*RouterStep) Prompt

func (step *RouterStep) Prompt(ctx context.Context, opt ...chatter.Opt) error

Prompt executes the router: runs agent, evaluates conditions, routes to appropriate job

type RunStep

type RunStep struct {
	Command    string // Compiled template for the command
	Shell      string // Shell to use (sh, bash, zsh, etc.)
	OutputName string
	Retry      *Retry
}

RunStep executes a shell command

func (*RunStep) GetOutputName

func (step *RunStep) GetOutputName() string

GetOutputName returns the name to store output under

func (*RunStep) Prompt

func (step *RunStep) Prompt(ctx context.Context, opt ...chatter.Opt) error

Prompt executes the shell command

type Server

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

active MCP server session

type Step

type Step interface {
	Prompt(ctx context.Context, opt ...chatter.Opt) error
	GetOutputName() string
}

Step is an interface for executable steps

type TextFormatter added in v0.1.11

type TextFormatter struct {
	Delimiter string
}

TextFormatter concatenates results with configurable delimiter. Useful for human-readable summaries or simple text aggregation.

func NewTextFormatter added in v0.1.11

func NewTextFormatter(delimiter string) *TextFormatter

NewTextFormatter creates a text formatter with custom delimiter

func (*TextFormatter) Format added in v0.1.11

func (f *TextFormatter) Format(results []any) (any, error)

Format converts results to delimited text string. Non-string results are JSON-encoded first.

type Workflow

type Workflow struct {
	Name       string
	About      string
	Entrypoint string // Optional: default job name, or "main" if empty
	Schema     ast.SchemaNode
	Jobs       map[string]*Job
}

Workflow represents a compiled, executable workflow

type WorkflowContext

type WorkflowContext struct {
	// Input is the original workflow input
	Input any

	// State is a shared key-value store for workflow data
	State map[string]any

	// Steps holds named outputs from previous steps
	Steps map[string]any

	// Current is the most recent step output (for chaining)
	Current any
}

WorkflowContext holds the execution state for a workflow

func GetWorkflowContext

func GetWorkflowContext(ctx context.Context) *WorkflowContext

GetWorkflowContext extracts the workflow context from Go context

func (*WorkflowContext) Get

func (c *WorkflowContext) Get(key string) (any, bool)

Get retrieves a value from the workflow state

func (*WorkflowContext) GetStepOutput

func (c *WorkflowContext) GetStepOutput(name string) (any, bool)

GetStepOutput retrieves the output of a named step

func (*WorkflowContext) Set

func (c *WorkflowContext) Set(key string, value any)

Set stores a value in the workflow state

func (*WorkflowContext) SetStepOutput

func (c *WorkflowContext) SetStepOutput(name string, output any)

SetStepOutput stores the output of a named step

func (*WorkflowContext) ToMap

func (c *WorkflowContext) ToMap() map[string]any

ToMap returns the full context as a map for template rendering

Jump to

Keyboard shortcuts

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