LM lmscript.io Agentic
Multi-Agent Orchestration

Agentic Recipes & Team Workflows

LMScript treats AI coding agents as first-class stateful handles. Open sessions across Claude, Codex, Gemini, and Kimi with one unified API, preserve context across turns, and combine LLM reasoning with deterministic _lmcode_ verification.

1. The Unified agent_* Session API

multi_turn_agent.lms
# 1. Discover installed providers
println("Available providers: " + json_stringify(agent_providers()));

# 2. Open a persistent multi-turn session
architect = agent_open({
  provider: "claude",
  cwd: ".",
  model: "sonnet",
  permission: "plan"
});

require(architect != null, "Agent session unavailable");

# 3. Turn 1: initial analysis
t1 = agent_turn(architect, "List the 3 main sections of site/index.html.");
if (t1.status == "ok") {
  println("Turn 1 response:\n" + t1.reply);
}

# 4. Turn 2: automatically continues the same session_id!
t2 = agent_turn(architect, "Now summarize that in one sentence.");
println("Session ID: " + t2.session_id + " | Turns: " + str(agent_info(architect).turns));

agent_close(architect);

2. Provider Options & Return Envelope

FieldWhere UsedDescription
cwdagent_open / agent_promptWorking directory for the agent process.
modelagent_open / agent_promptModel identifier or alias (e.g., "sonnet", "opus", "gpt-5", "gemini-2.5-pro").
systemagent_open / agent_promptSystem instructions for embedded providers.
session_idagent_open / agent_prompt / resultResume a previously saved session ID across script runs.
timeout_msagent_turn / agent_promptPer-turn timeout in milliseconds.
res.status / res.replyReturn mapStatus ("ok" on success) and assistant response text.
res.usageReturn mapToken usage metrics { input_uncached, cache_read, cache_write, output, reasoning } when reported.

3. Eight Canonical Agentic Architectures

Pattern 01

Triage Router

A lightweight classifier agent inspects incoming bug reports or tasks and routes them to specialized backend, frontend, or infra agents.

Pattern 02

Sequential Crew

Three-stage pipeline: Planner produces a spec → Builder edits files → Verifier runs lmscript --check and tests.

Pattern 03

Hierarchical Manager

A lead agent decomposes an epic into work items, dispatches worker handles, reviews their diffs, and requests targeted fixes until green.

Pattern 04

Deterministic Tool Agent

Combines an agent turn with deterministic LMScript SQLite queries, template_extract parsing, and _lmcode_ host execution.

Pattern 05

Human-in-the-Loop Gate

Runs automated preview/lint checks (aws.demo()), writes an audit artifact, and selects an explicit resumepoint entry for a rerun before live deployment.

Pattern 06

Parallel Fan-Out & Judge

Uses parallel_map to query multiple models concurrently, then passes candidate solutions to a Judge agent that verifies and picks the best.

Pattern 07

Stateful Resumable Agent

Stores session_id in application-owned state and uses resumepoint to select an entry on rerun; the application must save and reload any other required state.

Pattern 08

Keyword Knowledge & RAG

Indexes project docs into a local SQLite table (sql_exec / sql_read) and injects exact relevant snippets into each agent turn.

4. Multi-Agent Teamfiles (.lmc)

Teamfiles (such as lmscriptio.lmc) declare named agent aliases, providers, and models that can be seeded and messaged via lmctl or LMScript's lm_* functions:

lmscriptio.lmc
_AGENT_ alias=Lead     provider=agy    model=gemini-4-argon-high
_AGENT_ alias=Reviewer provider=claude model=sonnet

5. Direct LLM Calls (llm_prompt) & Tool Loops

When you want lightweight API completions without spawning a full CLI coding agent, use llm_prompt and tool_specs / tool_call:

direct_llm.lms
resp = llm_prompt(PROPS.Model, "Give the default HTTPS port.", {system: "Reply with a one-line JSON object."});
if (resp.ok) {
  println(resp.text);
}