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
# 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
| Field | Where Used | Description |
|---|---|---|
cwd | agent_open / agent_prompt | Working directory for the agent process. |
model | agent_open / agent_prompt | Model identifier or alias (e.g., "sonnet", "opus", "gpt-5", "gemini-2.5-pro"). |
system | agent_open / agent_prompt | System instructions for embedded providers. |
session_id | agent_open / agent_prompt / result | Resume a previously saved session ID across script runs. |
timeout_ms | agent_turn / agent_prompt | Per-turn timeout in milliseconds. |
res.status / res.reply | Return map | Status ("ok" on success) and assistant response text. |
res.usage | Return map | Token usage metrics { input_uncached, cache_read, cache_write, output, reasoning } when reported. |
3. Eight Canonical Agentic Architectures
Triage Router
A lightweight classifier agent inspects incoming bug reports or tasks and routes them to specialized backend, frontend, or infra agents.
Sequential Crew
Three-stage pipeline: Planner produces a spec → Builder edits files → Verifier runs lmscript --check and tests.
Hierarchical Manager
A lead agent decomposes an epic into work items, dispatches worker handles, reviews their diffs, and requests targeted fixes until green.
Deterministic Tool Agent
Combines an agent turn with deterministic LMScript SQLite queries, template_extract parsing, and _lmcode_ host execution.
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.
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.
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.
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:
_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:
resp = llm_prompt(PROPS.Model, "Give the default HTTPS port.", {system: "Reply with a one-line JSON object."});
if (resp.ok) {
println(resp.text);
}