# Templates Templates define the system prompt, stop sequences, and assistant message format for an agent. Templates can be applied via `AgentSpec` (YAML definitions) or passed directly in `run()` options. ## System prompt via run options The simplest way to set a system prompt is through the `system` field in run options: ```typescript import { Lm, Agent } from "@agent-smith/agent"; const lm = new Lm({ name: "llamacpp", serverUrl: "http://localhost:8080/v1", onToken: (t) => process.stdout.write(t), }); const agent = new Agent({ name: "my-agent", lm }); const prompt = `I am landing in Barcelona soon: I plan to reach my hotel and then go for outdoor sport. How are the conditions in the city?`; const result = await agent.run(prompt, { params: { model: "Qwen3-30B-A3B-Instruct-2507-UD-Q4_K_XL", temperature: 0.4, top_k: 40, top_p: 0.95, max_tokens: 16384, }, system: "You are an autonomous agent: feel free to use your tools.", }); ``` ## TemplateSpec via AgentSpec For reusable agent definitions, use `TemplateSpec` in a YAML-based `AgentSpec`: ```typescript import { Lm, Agent } from "@agent-smith/agent"; import { readFileSync } from "fs"; const lm = new Lm({ name: "llamacpp", serverUrl: "http://localhost:8080/v1", onToken: (t) => process.stdout.write(t), }); // Load agent spec from YAML const yamlContent = readFileSync("agents/chat.yml", "utf-8"); const agent = Agent.fromYaml({ lm }, yamlContent); const prompt = "Tell me about Barcelona weather"; const result = await agent.run(prompt, { params: { model: "Qwen3-30B-A3B-Instruct-2507-UD-Q4_K_XL", temperature: 0.4, max_tokens: 16384, }, }); ``` The YAML agent spec (`agents/chat.yml`) would look like: ```yaml name: chat prompt: "{prompt}" description: "A helpful chat agent" model: "Qwen3-30B-A3B-Instruct-2507-UD-Q4_K_XL" template: system: "You are a helpful assistant that uses tools when needed." stop: ["\n"] inferParams: temperature: 0.4 max_tokens: 16384 ``` ## Shots (few-shot examples) Include example conversation turns in your `AgentSpec` using the `shots` field: ```yaml name: chat prompt: "{prompt}" model: "Qwen3-30B" shots: - user: "What is AI?" assistant: "Artificial Intelligence..." - user: "How does it learn?" assistant: "Through training on data..." ``` These shots are prepended to the conversation history before each inference call. Next: supervised agent