Skip to content

FlowControl

theirish81 edited this page Dec 31, 2025 · 2 revisions

Flow Control

Plans do not simply execute top down. The plan writer can define preconditions and limitations. Reading about variables before this chapter is recommended.

dependsOn

A session can depend on:

  • one or more other sessions: In this case, the Frags scheduler will make sure that the dependent sessions are executed before the current session. If a dependent session fails, the current session will not be executed.
  • a specific condition: if, at the moment of the evaluation, a specific condition is not met, then the session is deemed as not applicable and will not be executed.

In this example, the session medication_explanation will only be executed if the session medication_extraction has been executed and the context variable medications is not empty.

Yaml

medication_explanation:
  prompt: explain the medications
  context: true
  dependsOn:
    - session: medication_extraction
      expression: len(context.medications) > 0

Go

frags.Sessions{
		"s1": frags.Session{
			Prompt:          "explain the medications",
			DependsOn: frags.Dependencies{
				{
					Session:    ptr("medication_extraction"),
					Expression: ptr("len(context.medications) > 0"),
				},
			},
		},
	}

iterateOn

Sometimes you want to be able to run a session against a list of values, possibly produced by a previous session. This allows the LLM to maximally focus on one item at a time, improving the accuracy of the response. For this purpose, the iterateOn attribute can be used.

Notes:

  • Frags is only capable of iterating over lists.
  • The session output needs to be bound to an array, and the prompt should be explicit about generating only one item at a time.

In this simple example, the session analyze_competitor will be executed against each item of the array competitors produced by the session competition. In the template, the expression {{ .it }} refers to the current item being processed. In this case it is a string so it's good as is, but in case of a complex object, it can be navigated using the dot notation.

Yaml

sessions:
  competition:
    prompt: find the main competitors of Acme Inc.
  analyze_competitor:
    prompt: Analyze the company {{ .it }}
    dependsOn:
      - session: competition
    iterateOn: context.competitors
schema:
  type: object
  required:
    - competitors
    - competitors_analyzed
  properties:
    competitors:
      type: array
      x-session: competition
      items:
        type: string
    competitors_analyzed:
      type: array
      x-session: analyze_competitor
      items:
        type: object
        required:
          - name
          - description
        properties:
          name:
            type: string
          description:
            type: string
            description: The company's competitive advantage.

Attempts

An optional command you can set at session level. It determines how many times the runner should attempt to run a session if it fails.

Clone this wiki locally