compiler

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT Imports: 19 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
}

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 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 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