micro/go-micro · error

LLM step requires a flow model (set Provider/APIKey)

Error message

LLM step requires a flow model (set Provider/APIKey)

What it means

The LLM step helper needs a configured language model on the flow's dependencies. Before executing the prompt it resolves the deps from the context; if there are no deps or the deps carry a nil model, the step fails immediately with this error. It exists so a missing model config surfaces as a clear message instead of a nil-pointer panic deep inside the model call.

Source

Thrown at flow/steps.go:315

	return func(ctx context.Context, in State) (State, error) {
		reply, err := a2a.NewClient(url).Send(ctx, in.String())
		if err != nil {
			return in, err
		}
		in.Data = []byte(reply)
		return in, nil
	}
}

// LLM returns a StepFunc that runs one augmented-LLM turn: it renders the
// prompt template against the current state (.Data, .Stage), lets the
// model call the flow's services as tools, and stores the reply as the
// new Data.
func LLM(prompt string) StepFunc {
	return func(ctx context.Context, in State) (State, error) {
		d := depsFrom(ctx)
		if d == nil || d.model == nil {
			return in, fmt.Errorf("LLM step requires a flow model (set Provider/APIKey)")
		}
		text := prompt
		if tmpl, err := template.New("step").Parse(prompt); err == nil {
			var buf bytes.Buffer
			if tmpl.Execute(&buf, map[string]string{"Data": in.String(), "Stage": in.Stage}) == nil {
				text = buf.String()
			}
		}
		var tools []ai.Tool
		if d.tools != nil {
			tools, _ = d.tools.Discover()
		}
		resp, err := d.model.Generate(ctx, &ai.Request{Prompt: text, Tools: tools})
		if err != nil {
			return in, err
		}
		reply := resp.Answer
		if reply == "" {

View on GitHub (pinned to 24529f1404)

Solutions

  1. Configure the flow's model: pass Provider and APIKey options when constructing the flow so d.model is non-nil.
  2. Ensure the relevant API key env var (e.g. OPENAI_API_KEY or the provider's equivalent) is set in the runtime environment.
  3. If invoking LLM steps directly in tests, attach flow deps with a model to the context instead of passing a bare context.Background().
  4. Replace the LLM step with a plain Run function if no model is intended for this flow.

Example fix

// before
f := flow.New(flow.Steps(flow.LLM("Summarize: {{.Data}}")))

// after
f := flow.New(
  flow.Provider("openai"),
  flow.APIKey(os.Getenv("OPENAI_API_KEY")),
  flow.Steps(flow.LLM("Summarize: {{.Data}}")),
)
Defensive patterns

Strategy: validation

Validate before calling

if flowDepsFrom(ctx) == nil || flowDepsFrom(ctx).model == nil {
    return errors.New("flow model not configured: set Provider/APIKey before using LLM steps")
}

Type guard

func hasFlowModel(ctx context.Context) bool {
    d := depsFrom(ctx)
    return d != nil && d.model != nil
}

Try / catch

state, err := step(ctx, in)
if err != nil {
    if strings.Contains(err.Error(), "requires a flow model") {
        // configure model and retry, or skip LLM step
    }
    return err
}

Prevention

When it happens

Trigger: Calling flow.LLM(prompt) as a StepFunc when the flow was built without Provider/APIKey options, or when the context passed to the step carries no flow deps (d == nil), e.g. invoking the step function directly outside a configured Flow run.

Common situations: Developers add an LLM step to a flow but forget to configure the model options (Provider/APIKey) on the flow; or they test the step function standalone with a plain context.Context that never had deps attached; or the provider env credentials are missing so the model was never constructed.

Related errors


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/34ccaaaa17fe330d. Report an issue: GitHub.