{"slug": "how-we-built-a-smart-ai-writing-agent-for-blog-articles", "title": "How we built a smart AI writing agent for blog articles", "summary": "The team behind Larry, an AI writing agent for legal experts, built a tool that treats articles like code by using surgical edits instead of full rewrites. The agent uses three tools—read_article, replace_in_field, and web_search—in an interview-first loop to capture a lawyer's expertise and enforce quality with a validation gate. This approach prevents voice drift and hallucinations by preserving 95% of the document unchanged.", "body_md": "Most \"AI writer\" products do the same thing: prompt → blob of text → paste. It works for a demo and falls apart in production, because the value isn't the prose; it's the **domain expert's judgment**, and a one-shot generation has nowhere to put it.\n\nWe build [Larry](https://larry-agent.com/en), a tool that turns a lawyer's expertise into articles that get cited by Google, ChatGPT and Gemini. Here's the actual shape of our writing agent: three tools, an interview-first loop, and two patterns worth stealing for any \"AI for experts\" product.\n\nThe instinct is: user asks for a change → send the whole article back to the model → get a whole new article. This is bad because every regeneration drifts. The intro you liked changes. The one accurate statistic gets \"improved\" into a hallucination. You lose the expert's voice on every pass.\n\nThe fix is to treat the article like **code**: give the agent an editing tool that makes *surgical* changes to a document that already exists, not a firehose that rewrites it.\n\n`blog_posts`\n\nrow; the conversation and every tool call are persisted so the agent is stateful across turns.No agent framework. Just a `while`\n\nloop that calls the model, runs any tool calls, feeds the results back, and repeats until the model stops asking for tools.\n\nThat's the entire toolbox. Resist adding more.\n\n``` js\nconst tools = [\n  {\n    name: 'read_article',\n    description: 'Read the current article (title, content, FAQ, tags, SEO metas) and author info.',\n    parameters: {},\n  },\n  {\n    name: 'replace_in_field',\n    description: 'Replace text in a specific field of the article.',\n    parameters: {\n      field: ['title', 'content', 'faq', 'tags', 'excerpt',\n              'meta_title', 'meta_description', 'example_validation'],\n      old_string: 'Exact text to replace. Empty = replace the whole field.',\n      new_string: 'The new value.',\n    },\n  },\n  {\n    name: 'web_search',\n    description: 'Search the web for current facts. Returns a source URL + snippet.',\n    parameters: { query: 'string' },\n  },\n];\n```\n\n`replace_in_field`\n\nis the important one. `old_string`\n\nmust match **exactly one occurrence** in the target field, the same contract as the `Edit`\n\ntool in a coding agent. The agent reads the article, finds the sentence to fix, and patches only that sentence. Everything else is byte-for-byte preserved. Voice and facts stop drifting because 95% of the document is never re-touched.\n\nThe system prompt enforces a strict sequence, and the golden rule is: **never run a step that needs an answer without stopping for it.**\n\n`replace_in_field`\n\n.Step 2 is where the product lives. Anyone can generate a generic article about a legal topic. The moat is the lawyer's own example: the exception, the mistake clients always make, the thing a Google search gets wrong. So the agent's first job isn't to write; it's to *interview*. Here's the shape of that prompt:\n\n```\nYou are capturing a lawyer's expertise on a specific topic.\nAsk 2–3 precise questions, ONE exchange at a time.\nYou MUST ask for one concrete, anonymized real case or anecdote\nthat illustrates the topic. Wait for the answer before proposing a plan.\n```\n\n**1. A validation gate the model can't fake.**\n\nOur quality bar requires a real anonymized example in the body. We enforce it with a boolean field, `example_validation`\n\n, that's *also a tool target*. The rule: the agent may only set it to `true`\n\n**after** re-reading the article with `read_article`\n\nand confirming the example is actually present. The model can't self-certify from memory; it has to go look. It's a cheap way to turn a soft \"please include an example\" into a hard state transition.\n\n**2. External URLs come from search only.**\n\nThe single biggest hallucination risk in legal content is invented case law and fake source links. The guardrail is a hard rule: every external URL in the article must come from a real `web_search`\n\nresult, never from the model's memory. Research isn't optional polish; it's the only sanctioned source of links. (We also forbid citing specific law firms, for the same trust reason.)\n\nThere's also a silent self-critique pass after each edit: the agent re-checks its own output against the quality rules (direct-answer intro, question-form headings, short paragraphs, the example, the call-to-action) and patches the gaps *before* handing back, without narrating any of it to the user. The lawyer sees \"done,\" not a checklist.\n\nThe model is a commodity you swap with an env var. The product is everything around it: **capture the expert's judgment through an interview, edit the document with surgical patches instead of regenerating it, and gate quality with tools the model can't bluff past.**\n\nIf you want to see the finished version aimed at lawyers, it's at [larry-agent.com](https://larry-agent.com/en). Curious what other expert domains this shape would fit. What would you point it at?", "url": "https://wpnews.pro/news/how-we-built-a-smart-ai-writing-agent-for-blog-articles", "canonical_source": "https://dev.to/larry_agent/how-we-built-a-smart-ai-writing-agent-for-blog-articles-5dma", "published_at": "2026-07-07 17:47:30+00:00", "updated_at": "2026-07-07 18:28:42.271266+00:00", "lang": "en", "topics": ["artificial-intelligence", "generative-ai", "ai-agents", "natural-language-processing", "developer-tools"], "entities": ["Larry", "Google", "ChatGPT", "Gemini"], "alternates": {"html": "https://wpnews.pro/news/how-we-built-a-smart-ai-writing-agent-for-blog-articles", "markdown": "https://wpnews.pro/news/how-we-built-a-smart-ai-writing-agent-for-blog-articles.md", "text": "https://wpnews.pro/news/how-we-built-a-smart-ai-writing-agent-for-blog-articles.txt", "jsonld": "https://wpnews.pro/news/how-we-built-a-smart-ai-writing-agent-for-blog-articles.jsonld"}}