Add an LLM call
The quickstart's greet flow returned a hard-coded string. Real flows use LLMs. This tutorial adds a @flexible block to the greet flow: it calls a model with a goal and an input, and gets back a structured output the runtime type-checks. It assumes you've completed the quickstart and have greet.scaicore on disk.
1. Declare a model role#
LLM calls go through roles, not model names. A role is a slot the runtime can swap providers behind. Declare one in the @core block:
1 2 3 4 5 6 7 8 9 10 11 12 | |
primary is conventional for the main role; you can declare additional roles (reviewer, extractor, …) and reference them by name from @flexible blocks via the llm_role field.
2. Declare an output type#
Structured outputs need a type the compiler can verify against. Declare it at module scope:
1 2 3 4 5 6 | |
The runtime translates Greeting into a JSON schema and asks the provider to honor it.
3. Replace the @rigid body with @flexible#
The old greet flow:
1 2 3 4 5 | |
Becomes:
1 2 3 4 5 6 7 8 9 10 | |
Three things changed: the flow's return type is now Greeting, the work moved into a @flexible block that asks the model for a Greeting-shaped value, and a small @rigid returns it. The result = binding captures the @flexible block's output into the surrounding scope.
4. Check it#
scaicore check runs the full pipeline including type-check and verifier. It should pass:
1 | |
If you see E206 — undefined model you misspelled a role name. If you see E300 — type mismatch your output: doesn't line up with the flow's declared return type — they need to match.
5. Run it#
scaicore run will compile and execute, but the CLI host's default model provider is a stub that returns mock values. To run against a real provider you'll either:
- Embed the runtime in your own host and pass a real
ModelProviderimplementation, or - Configure the CLI host with provider credentials (see your model provider's docs for the role config).
Either way:
1 | |
A successful run prints the structured output, e.g.:
1 2 3 4 | |
What you gained#
Compared to the quickstart flow you now have: structured output the runtime type-checks against Greeting, a role-based model declaration that lets you swap providers without touching flow source, and (once a real provider is wired up) text generation that adapts to the input.
Next: Add a human approval step to require sign-off before the greeting is returned.