AGENTS.md
packages/@n8n/agents/AGENTS.mdAGENTS.md
Quality
100/100
Scores the file, not the repository.Length
751 words
10 headings · 4 code blocksRepository
199k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# AGENTS.md23Conventions for the `@n8n/agents` package.45## Code Style67- **No `_` prefix on private properties** — use `private` access modifier8 without underscore. Write `private name: string`, not `private _name: string`.9- **Builder pattern with lazy build** — all public primitives use a fluent10 builder API. **User code never calls `.build()`**. Builders are passed11 directly to the consuming method (e.g. `agent.tool(myTool)`) which calls12 `.build()` internally. Agent has `generate()`/`stream()` directly on the13 class, which lazy-build via `ensureBuilt()` on first call. `build()` is14 `protected` on Agent to keep it out of the public API.15- **Zod for schemas** — all input/output schemas use Zod.1617## Package Structure1819```20src/21 index.ts # Public API barrel export22 types/ # Public TypeScript types23 index.ts # Re-exports consumable types24 telemetry.ts25 sdk/ # Types aligned with builders (agent, eval, guardrail, mcp, memory, message, provider, tool)26 runtime/ # Serializable runtime shapes (events, message lists)27 utils/ # JSON typing helpers re-exported with public types28 sdk/ # Fluent builders and SDK entry points29 agent.ts # Agent builder30 catalog.ts # Provider catalog fetch31 eval.ts # Evaluation primitives32 evaluate.ts # Evaluation runner over agents + dataset33 guardrail.ts # Guardrail builder34 mcp-client.ts # MCP client integration35 memory.ts # Memory builder36 message.ts # LLM/DB message helpers37 provider-tools.ts # Provider-defined tool factories38 telemetry.ts # Telemetry builder (OTel, redaction)39 tool.ts # Tool builder40 verify.ts # Verification utilities41 runtime/ # Internal — never exported42 agent-runtime.ts # Core agent execution engine (AI SDK)43 tool-adapter.ts # Tool execution, branded suspend detection44 stream.ts # Streaming helpers45 model-factory.ts # Model instantiation46 memory-store.ts # In-memory conversation and observation-log storage47 observation-log-observer.ts48 observation-log-reflector.ts49 observation-log-renderer.ts50 scoped-memory-task-runner.ts51 message-list.ts # Message list + serialization for agent loop52 messages.ts # Message normalization53 mcp-connection.ts # MCP connection lifecycle54 mcp-tool-resolver.ts55 run-state.ts # Run / checkpoint state56 event-bus.ts # Internal agent events57 runtime-helpers.ts58 title-generation.ts59 strip-orphaned-tool-messages.ts60 logger.ts61 storage/ # Shared memory backend base class (exported)62 base-memory.ts63 workspace/ # Workspace, sandbox, filesystem, built-in tools (exported)64 integrations/ # Optional integrations (exported where applicable)65 langsmith.ts # LangSmith telemetry adapter (peer `langsmith`)66 utils/ # Internal helpers (e.g. Zod utilities); not barrel-exported67examples/68 basic-agent.ts # Sample snippet; included in format/lint paths69docs/70 agent-runtime-architecture.md # In-package runtime notes71```7273The **`index.ts`** surface also exports `Workspace` / sandbox / filesystem types,74`InMemoryMemory`, `LangSmithTelemetry`, and `evals` alongside the core SDK builders.7576Optional **peer dependencies** (telemetry): `langsmith`, `@opentelemetry/sdk-trace-node`,77`@opentelemetry/sdk-trace-base`, `@opentelemetry/exporter-trace-otlp-http` — all78optional; install only when wiring that telemetry.7980## Credential Pattern8182Agents declare credential requirements via `.credential('name')`. The execution83engine resolves the name to an API key and injects it into the model config.84User code never touches raw API keys.8586```typescript87const agent = new Agent('assistant')88 .model('anthropic/claude-sonnet-4-5')89 .credential('anthropic')90 .instructions('You are helpful.');91```9293## Engine Injection (EngineAgent)9495The execution engine extends `Agent` and overrides `protected build()` to96inject infrastructure (checkpoint storage, credentials) before calling97`super.build()`. This is the pattern for all engine-level concerns:9899```typescript100class EngineAgent extends Agent {101 build() {102 this.checkpoint(store);103 const cred = this.declaredCredential;104 if (cred) this.resolvedApiKey = resolve(cred);105 return super.build();106 }107}108```109110111## Testing112113- Unit tests live in `src/__tests__/`, integration tests in `src/__tests__/integration/`114- Unit tests use Vitest (`pnpm test`)115- Integration tests use Vitest (`pnpm test:integration`) with real LLM calls116 - A `.env` file at the package root is loaded automatically by the vitest config.117 Always assume it exists when running integration tests. Never commit it.118 - Required keys:119 - `ANTHROPIC_API_KEY` — all integration tests120 - Tests skip automatically when the required API key is not set121- Run from the package directory: `cd packages/@n8n/agents && pnpm test`122123### Integration tests124125Integration tests make real LLM calls. CI replays recorded HTTP cassettes126instead, so every test must have a matching recording.127128**Workflow after changing or adding integration tests:**1291301. `pnpm test:integration <file>` — verify the test passes with a live API key1312. `pnpm test:integration:record <file>` — record HTTP cassettes1323. `pnpm test:integration:replay` — confirm the test passes from recordings133134**Rules:**135- No random IDs or current timestamps in HTTP requests — the replay matcher136 must be able to match recorded requests deterministically137- Run only the affected test files, not the full suite, unless changes affect all tests138139## Documentation140141- Spec-driven work in the wider repo may use `.agents/specs/` (see repo skill142 `.agents/skills/spec-driven-development`).143144## Building145146```bash147cd packages/@n8n/agents148pnpm build # rimraf dist && tsc -p tsconfig.build.json → dist/149pnpm typecheck # tsc --noEmit150pnpm test # vitest (unit)151```152153## PR naming convention154155The Agents feature is not generally available yet, so any PRs related to the Agents package should have (no-changelog) in the title to avoid generating a changelog entry.156
Also in n8n-io/n8n
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| n8n-io/n8n.agents/skills/AGENTS.md · 199k | AGENTS.md | setuparchagent-behaviour | 58/100 | 3 days ago | |
| n8n-io/n8n.github/CLAUDE.md · 199k | CLAUDE.md | styleagent-behaviour | 48/100 | 3 days ago | |
| n8n-io/n8nAGENTS.md · 199k | AGENTS.md | setupbuildtestlint-format+8 | 96/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/ai-workflow-builder.ee/AGENTS.md · 199k | AGENTS.md | agent-behaviour | 53/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/db/AGENTS.md · 199k | AGENTS.md | database | 39/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/engine/AGENTS.md · 199k | AGENTS.md | archdo-not | 59/100 | 3 days ago | |
| n8n-io/n8npackages/@n8n/instance-ai/CLAUDE.md · 199k | CLAUDE.md | buildteststyletesting-strategy+1 | 89/100 | 3 days ago | |
| n8n-io/n8npackages/cli/AGENTS.md · 199k | AGENTS.md | lint-format | 55/100 | 3 days ago | |
| n8n-io/n8npackages/cli/src/modules/n8n-packages/CLAUDE.md · 199k | CLAUDE.md | stylearchdependenciesmonorepo+2 | 69/100 | 3 days ago | |
| n8n-io/n8npackages/frontend/AGENTS.md · 199k | AGENTS.md | style | 40/100 | 3 days ago | |
| n8n-io/n8npackages/frontend/editor-ui/src/app/stores/workflowDocument/CLAUDE.md · 199k | CLAUDE.md | styleagent-behaviour | 58/100 | 3 days ago | |
| n8n-io/n8npackages/nodes-base/AGENTS.md · 199k | AGENTS.md | teststylearchtypes+5 | 89/100 | 3 days ago | |
| n8n-io/n8npackages/testing/playwright/AGENTS.md · 199k | AGENTS.md | setupbuildtestlint-format+8 | 96/100 | 3 days ago | |
| n8n-io/n8nscripts/instance-seeding/AGENTS.md · 199k | AGENTS.md | setupstyledo-not | 65/100 | 3 days ago |
Diff against .agents/skills/AGENTS.md Diff against .github/CLAUDE.md Diff against AGENTS.md Diff against packages/@n8n/ai-workflow-builder.ee/AGENTS.md Diff against packages/@n8n/db/AGENTS.md Diff against packages/@n8n/engine/AGENTS.md Diff against packages/@n8n/instance-ai/CLAUDE.md Diff against packages/cli/AGENTS.md Diff against packages/cli/src/modules/n8n-packages/CLAUDE.md Diff against packages/frontend/AGENTS.md Diff against packages/frontend/editor-ui/src/app/stores/workflowDocument/CLAUDE.md Diff against packages/nodes-base/AGENTS.md Diff against packages/testing/playwright/AGENTS.md Diff against scripts/instance-seeding/AGENTS.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago | |
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 3 days ago | |
| elastic/elasticsearchx-pack/plugin/inference/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+3 | 100/100 | 3 days ago | |
| bagisto/bagistoAGENTS.md · 28k | AGENTS.md | setupbuildteststyle+7 | 100/100 | 3 days ago |
