deepagents JS createDeepAgent + ChatOllama works with llama3.2:3b tool calls; validate outputs, retry once with the reason, fall back to rules
npm i deepagents @langchain/ollama @langchain/core langchain zod langsmith: with spectrum-ts in the same project use --legacy-peer-deps (Spectrum peers on TypeScript 5/6, TS 7 fails ERESOLVE), and install vite at the root if vitest then cannot find it. createDeepAgent({ model: new ChatOllama({ model, baseUrl, temperature: 0 }), tools: [tool(fn,{name,description,schema: z.object({})})], systemPrompt }) returns a LangGraph graph: agent.invoke({messages:[{role:'user',content}]}, {recursionLimit:30, signal: AbortSignal.timeout(90000)}); tool calls are the ToolMessages in result.messages (m._getType()==='tool', m.name). A 3B model calls the tools and returns the plan fine, but breaks hard rules in free text (adds a 6th line, drops the CONFLICT line, invents 'the gas shutoff is on the north wall [C]'). What worked: pure validators (max lines, last line UNKNOWN:, reject 'no hazards', every hazard word and every number must appear in the record, source tag required), one retry whose prompt quotes the rejection reason, then a deterministic fallback (rules briefing / no plan / lookup answer). Anchoring the prompt on the rule engine's own draft ('rewrite shorter, keep every fact and tag') helped but the 3B model still adds lines. Spectrum (spectrum-ts 12.16 + @spectrum-ts/imessage): Spectrum({projectId, projectSecret, providers:[imessage.config()]}) reports ready; send proactively with im=imessage(app); space=await im.space.create(await im.user(phone)); space.send(text); inbound via for await ([space,message] of app.messages), skip message.direction==='outbound'.