SOP Sessions

A SOPAgenticSession converts a request into a LightSOPLang plan, validates the commands, executes the dependency graph, and can replan when execution reports failures.

Plan and execution loop

flowchart TB
  P[Receive prompt and prepare optional context] --> G[LLMAgent generates a LightSOPLang plan]
  G --> V{Commands and topology valid?}
  V -->|no| G
  V -->|yes| X[Execute ready commands through the wrapped registry]
  X --> C{Awaiting input or failures?}
  C -->|awaiting input| W[Keep pending tool and return control to the caller]
  C -->|failures within attempt limit| G
  C -->|complete| R[Store plan, variables, answer, and active status]
  classDef session fill:#f5f1ff,stroke:#6657b8,color:#2d246b;
  classDef decision fill:#fff7e8,stroke:#b7791f,color:#633c00;
  classDef outcome fill:#eefbf4,stroke:#28875d,color:#174c38;
  class P,G,X session; class V,C decision; class W,R outcome;
SOP session planning cycle

How the cycle works

  1. Generate and validate the planThe session prepares optional context and asks LLMAgent for a LightSOPLang plan. Every command and dependency is validated before execution, and an invalid plan returns to generation within the configured attempt limit.
  2. Execute ready commandsCommands run when their dependencies are satisfied. A command that needs user input is stored as pendingTool, while recoverable failures return to bounded replanning.
  3. Store the outcomeSuccessful execution stores the plan, variables, answer, and session status. Reserved commands provide explicit final outcomes, while planOnly or generatePlanOnly stops after plan generation.

Session memory

Stored valuePurpose
historyPrompt, planning, execution, and interruption entries used for continuation and diagnostics.
currentPlanThe latest generated LightSOPLang source.
lastExecutionThe latest execution result, including variables and the derived final answer.
_lastFinalAnswerThe explicit final answer emitted by the reserved command.
lastRunFailuresFailures fed back into bounded replanning.
pendingToolA command paused for user input and resumed by a later prompt.
skillsDescriptionThe model-visible command descriptions, including reserved runtime commands.
commandsRegistry and planCommandsRegistryThe wrapped execution commands and the commands available while constructing the plan.
preparationContextText and preparationContextLinesContext collected before planning when preparation is configured.
options, maxPlanAttempts, and statusModel routing, plan-only behavior, retry bound, and lifecycle state.
systemPrompt and baseSystemPromptStable instructions used by plan generation and execution interpretation.

Continuation boundary

newPrompt() can resume a pending tool, treat the message as a fresh instruction, or continue after interruption. replaceSkillSurface() refreshes descriptions and commands without replacing the session object. getVariables() exposes the last plan, last answer, execution variables, and status.