Tool agent
The model reads files with the embedded read-only tools; one agent_prompt call runs the whole tool conversation and reports which tools ran.
The agent's spec carries a tools map: root, write and web. With no write or web grant the model can call list_files and read_file inside the root and nothing else. The host sends the tool declarations to the model, runs each tool call it asks for, keeps the conversation, and stops when the model answers in text or after max_steps. Every tool result, including a refused or invalid call, goes back to the model as data. The script gets the final reply plus tool_calls, a list of the tools that ran with an ok flag each, and the same list in the session journal that lm_session_get reads. The recipe stops with an error if the model answered without calling a tool.
What it maps to
Tools: the embedded built-in tools, granted through the tools map of the agent spec instead of a hand-written loop. Permissions: the script grants root, write and web; the model cannot widen them. Short-term memory: the host keeps the conversation inside the session. See the concept map.
Script: tool-agent.lms
# Tool agent: the model reads files with the embedded read-only tools; one agent_prompt call runs the whole tool conversation.
import "agentic.lms";
write_file("notes.txt", "Release 0.3 ships the agentic recipes.\nRelease 0.4 adds embeddings.\n");
question = ARGV.get(0, "Which release adds embeddings? Check notes.txt.");
analyst = with_tools(agent("file analyst", "answer questions about files in the current directory"), {root: ".", write: false, web: false});
r = turn(analyst, question, {max_steps: 6, max_tokens: BUDGET, retries: 2});
if (r.dry_run) { exit(0); }
for (c in r.tool_calls) { warning(f"[tool] {c.name} ok={c.ok}"); }
require(len(r.tool_calls) > 0, "the model answered without reading the file");
println(trim(r.reply));
It imports the shared helpers from examples/agentic.lms, shown on the recipe index.
Run it
export OLLAMA_API_KEY=...
LLM_MODEL=ollama-cloud/deepseek-v4.1-flash lmscript examples/tool-agent.lms
Output (offline mock)
The site check runs this recipe against examples/mock-model.lms, a deterministic stand-in for the model, and compares this output.
Release 0.4 adds embeddings (notes.txt, line 2).
Live run
Recorded on 2026-11-04 with ollama-cloud/deepseek-v4.1-flash. One agent_prompt call ran 2 steps and used 1,381 tokens. The model called list_files and then read_file on notes.txt; the standard error trace showed [tool] list_files ok=true and [tool] read_file ok=true.
Release 0.4 adds embeddings.
Previous: Hierarchical manager · Next: Human checkpoint
Try it: download examples/tool-agent.lms and examples/agentic.lms into an examples/ directory, export the key for your provider, then run the command above. No extra tools are needed: the file tools are built into lmscript.