{"slug": "n8n-style-tool-chains-for-ai-agents-custom-design-or-reinforced-by-what-works", "title": "N8n-style tool chains for AI agents – custom design, or reinforced by what works", "summary": "Stigmergy, a new open-source tool, provides agent loops with a memory of successful capability paths to eliminate redundant tool rediscovery on every run. The system, inspired by ant pheromone trails, observes agent loops, reinforces transitions that lead to accepted outcomes, and surfaces proven paths for similar future tasks without blocking the loop. Available as an npm monorepo with an Electron desktop app, Stigmergy complements progressive disclosure by acting as a non-blocking recall layer that degrades to a no-op when switched off.", "body_md": "Stigmergy gives an agent loop a memory of what already worked. It watches which capabilities a loop reaches for, learns the capability paths that lead to accepted outcomes, and surfaces a proven path the next time a similar task comes up, so the agent stops re-exploring the same ground every run. It runs beside your loop, never blocks it, and turns into a no-op when switched off.\n\nAgent loops rediscover their tools on every run. As the toolset grows (function-calling tools, skills, MCP servers, sub-agents), the model spends turns probing what exists and how to call it, and a flat catalog of everything bloats the prompt. The loop has no memory: a sequence of steps that solved a task last week is gone, so the same exploration cost is paid again. Progressive disclosure (load tools on demand) keeps the prompt small but does nothing to recall what succeeded before.\n\nStigmergy is a host-external substrate, inspired by how ants lay pheromone trails. It observes the loop and reinforces the transitions that get accepted, so it learns the paths that work for a kind of task. When a new task clearly matches a path it has already solved successfully, it surfaces that path as a small hint and can pre-activate exactly the tools the path needs, so the agent skips the rediscovery. When it does not recognize the task, it stays silent and your loop's own tool selection runs unchanged.\n\nIt complements progressive disclosure, it does not replace it: your retrieval stays the precise default, Stigmergy is the recall layer on top. It is non-blocking (a consult is an in-memory lookup under ten milliseconds, all embedding runs in the background), it degrades to a no-op when it is off or the daemon is unreachable, and it learns only from graded outcomes, so a flailing run is never reinforced.\n\n**Register once.** The host tells the substrate which capabilities exist, across all four kinds: tools, skills, MCP tools, and sub-agents, each with a stable id and a short description.**Per turn: consult, instrument, grade.** Before the model picks a step, the loop asks the substrate which proven path fits the task. As tools run, the loop reports`invoked`\n\nand`returned`\n\n. When the turn resolves, the loop grades it: accepted, iterated, or abandoned.**Pheromone on a path graph.** Accepted transitions deposit pheromone, weighted by quality and token efficiency and decayed over time; discarded or abandoned ones accrue negative evidence. Selection is deterministic given a seed (multiplicative desirability plus Thompson sampling over the decayed evidence), so the substrate never makes the loop guess.**Recall, not a second selector.** On a confident match (a learned, named path whose context fits) the substrate returns a sequence and the host pre-activates that path's capabilities plus a one-line hint. Otherwise it returns a neutral result and the host's own selection decides. It never reorders or hides your tools.**Local and off the hot path.** Semantic matching uses a local embedding model; capability and query embeddings are computed in a background worker, so a consult is a synchronous in-memory read.\n\nStigmergy is an npm-workspaces monorepo with an Electron desktop app (the Studio) and a set of thin-client packages for wiring it into your loop.\n\n```\ngit clone https://github.com/pssah4/stigmergy.git\ncd stigmergy\nnpm install\nnpm run build\n```\n\nRun the Studio (the desktop app that owns the database and the daemon, and walks you through setup):\n\n```\nnpm run dev -w @stigmergy/studio\n```\n\nIf the native database module reports a version mismatch on first launch, rebuild it for the desktop\nruntime once: `npm run rebuild:electron -w @stigmergy/studio`\n\n. The first-run wizard also points this out.\n\n**Start in the Studio.** On first launch a guided wizard takes you from nothing to a running setup: it\nchecks the native module, lets you pick a memory file, add an LLM provider (used only for naming learned\npaths, the embedding is a local on-device model), start the daemon, connect your agent loop, and switch\nStigmergy on. You can re-open the wizard any time from Settings.\n\n**Connect your loop.** The Studio's connect step gives you a copy-paste prompt for your coding agent (or\na snippet for a supported SDK) that wires three calls into your loop: consult before tool selection,\ninstrument tool execution, and grade the turn on resolution. Your loop holds only the thin client; the\ndaemon owns the model and the database.\n\nFor a supported SDK, install the matching adapter instead of hand-wiring:\n\n| Package | Use it for |\n|---|---|\n`@agentic-stigmergy/loop` |\nThe SDK-agnostic facade: `beginTurn` / instrument / grade |\n`@agentic-stigmergy/client` |\nThin client over the daemon's socket (your loop holds no engine) |\n`@agentic-stigmergy/core` |\nThe embedded engine, if you want it in-process instead of a daemon |\n`@stigmergy/integration-vercel-ai` , `-langchain` , `-openai-agents` |\nDrop-in SDK adapters |\n\n**Watch it learn.** The Studio's graph shows your capabilities as nodes and the learned paths as edges\nthat thicken as they are reinforced. Search and filter your saved paths, click one to highlight it in\nthe graph, or collapse the side panel to work in the graph alone.\n\nIf you want the engine in-process rather than the daemon, wire it directly:\n\n``` js\nimport { createEngine } from '@agentic-stigmergy/core'\nimport { createSqlJsStorage } from '@stigmergy/storage-sqljs'\nimport { TransformersEmbedding } from '@stigmergy/embedding-transformers'\n\nconst engine = await createEngine({\n  storage: await createSqlJsStorage(), // or a better-sqlite3 store for Node persistence\n  embedding: new TransformersEmbedding(), // local all-MiniLM-L6-v2 on onnxruntime-node\n})\n\nawait engine.registerCapability({ id: 'tool:summarize', type: 'tool', description: 'summarize long documents' })\n\nconst decision = await engine.consult({ task_id: 't1', context: 'summarize this report' })\n// decision.mode: 'ranked' (neutral), or 'sequence' / 'enforce' when a path is pinned.\n\nawait engine.emit({ type: 'task_started', taskId: 't1', context: 'summarize this report' })\nawait engine.emit({ type: 'capability_invoked', taskId: 't1', capabilityId: 'tool:summarize' })\nawait engine.emit({ type: 'capability_returned', taskId: 't1', capabilityId: 'tool:summarize', success: true })\nawait engine.emit({ type: 'response_delivered', taskId: 't1' })\nawait engine.emit({ type: 'task_accepted', taskId: 't1', tokenCost: 800 }) // or task_abandoned on failure\n\nawait engine.close()\n```\n\nOver many tasks the substrate reinforces transitions that get accepted, so later consults rank\npreviously successful paths higher. If you already know the path and the outcome, skip the per-step\nevents and call `engine.deposit({ task_id, context, path, outcome, token_cost })`\n\ndirectly. Pin a path to\nalways prefer, enforce, or sequence it: `engine.pinPath({ capability_sequence, behavior })`\n\n.\n\n| Package | Purpose |\n|---|---|\n`@agentic-stigmergy/core` |\nEngine, scoring and decay, outcome tracker, background embedder, ports |\n`@agentic-stigmergy/loop` |\nSDK-agnostic loop facade (beginTurn / instrument / grade), degrade-safe |\n`@agentic-stigmergy/client` |\nThin client over the daemon's Unix socket |\n`@stigmergy/storage-better-sqlite3` |\nNode storage adapter (WAL, native) |\n`@stigmergy/storage-sqljs` |\nSandbox storage adapter (WASM, in-memory) |\n`@stigmergy/embedding-transformers` |\nLocal embedding adapter (all-MiniLM-L6-v2 on onnxruntime-node) |\n\n```\nnpm run build       # tsc -b across the workspace\nnpm test            # vitest (offline, deterministic)\n```\n\nThe embedding adapter is verified against the real model behind an env flag, so the default suite stays\noffline: `STIGMERGY_EMBEDDING_IT=1 npm test`\n\ndownloads the model on first run.\n\nApache-2.0", "url": "https://wpnews.pro/news/n8n-style-tool-chains-for-ai-agents-custom-design-or-reinforced-by-what-works", "canonical_source": "https://github.com/pssah4/stigmergy", "published_at": "2026-06-05 09:19:59+00:00", "updated_at": "2026-06-05 09:51:12.101357+00:00", "lang": "en", "topics": ["ai-agents", "artificial-intelligence", "machine-learning", "ai-tools", "ai-research"], "entities": ["Stigmergy", "MCP"], "alternates": {"html": "https://wpnews.pro/news/n8n-style-tool-chains-for-ai-agents-custom-design-or-reinforced-by-what-works", "markdown": "https://wpnews.pro/news/n8n-style-tool-chains-for-ai-agents-custom-design-or-reinforced-by-what-works.md", "text": "https://wpnews.pro/news/n8n-style-tool-chains-for-ai-agents-custom-design-or-reinforced-by-what-works.txt", "jsonld": "https://wpnews.pro/news/n8n-style-tool-chains-for-ai-agents-custom-design-or-reinforced-by-what-works.jsonld"}}