Skip to main content

AI agent that updates its own rules to modify behavior

Workflow preview

Workflow preview
100%
AI agent that updates its own rules to modify behavior preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Video walkthrough https://www.youtube.com/watch?v=OwIFK r NtQ Summary of agent This agent can write and rewrite its own rules, allowing you to mold its behavior. It receives rules from a database a...

Best for

  • Engineering automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.memorybufferwindow, @n8n/n8n-nodes-langchain.lmchatanthropic, n8n-nodes-base.postgres, n8n-nodes-base.merge, n8n-nodes-base.aggregate, n8n-nodes-base.postgrestool, @n8n/n8n-nodes-langchain.chattrigger

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by GiovanniSegar.

Original n8n.io source

1.1 Workflow description

Title
AI agent that updates its own rules to modify behavior
Workflow name
AI agent that updates its own rules to modify behavior

Video walkthrough

https://www.youtube.com/watch?v=OwIFK-r-NtQ

Summary of agent

This agent can write and rewrite its own rules, allowing you to mold its behavior. It receives rules from a database as system instructions and has tools to create, edit, or delete them. This is a great baseline for new agent builds.

You can tell it things like "Next time, use present tense when talking about this subject" and it will use a tool to save this as a rule, then receive that instruction in all future iterations.

How to start using it

Option 1: With a Postgres database (e.g., Supabase)

  1. Supabase Schema: Create a table (e.g., agent_rules) with the following columns:
    • id: bigint (Primary Key, auto-incrementing)
    • created_at: timestamp with time zone (Default: now())
    • rule_text: text
    • agent: text
  2. Workflow Updates:
    • Update the Postgres credentials in the "Get rules from database," "Insert rule into database," and "Execute query on rule database" nodes.
    • Update the agent value (currently 'TestAgent') in the "Get rules from database" and "Insert rule into database" nodes if you want a different agent name.
    • Update the Anthropic API credentials.

Option 2: With Google Sheets

  1. Google Sheet Setup: Create a Google Sheet with columns for rule_text and agent.
  2. Workflow Updates:
    • Example Google Sheets nodes are included. You will need to:
      • Connect your Google Sheets credentials.
      • Select your Google Sheet (with rule_text and agent columns) in all relevant Google Sheets nodes.
      • Replace the existing Postgres nodes ("Get rules from database", "Insert rule into database", "Execute query on rule database") with the configured Google Sheets nodes.
    • Update the agent value (currently 'TestAgent') in the Google Sheets nodes if you want a different agent name.
    • Update the Anthropic API credentials.
    • Agent Instructions: Update the agent's system message and remove the database schema section as it is no longer relevant

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Ultimate Assistant1

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.7

Block 2 - Chat History1

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 3 - Anthropic Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatAnthropic - lmChatAnthropic
Config choices
Version 1.2

Block 4 - Get rules from database

Type / Role
n8n-nodes-base.postgres - postgres
Config choices
Version 2.6

Block 5 - Merge

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.1

Block 6 - Aggregate

Type / Role
n8n-nodes-base.aggregate - aggregate
Config choices
Version 1

Block 7 - Insert rule into database

Type / Role
n8n-nodes-base.postgresTool - postgresTool
Config choices
Version 2.6

Block 8 - Execute query on rule database

Type / Role
n8n-nodes-base.postgresTool - postgresTool
Config choices
Version 2.6

Block 9 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 10 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 12 - Get rules from sheets

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.6

Block 13 - Add rule to sheet

Type / Role
n8n-nodes-base.googleSheetsTool - googleSheetsTool
Config choices
Version 4.6

Block 14 - Update rule in sheet

Type / Role
n8n-nodes-base.googleSheetsTool - googleSheetsTool
Config choices
Version 4.6

Block 15 - Delete rule in sheet

Type / Role
n8n-nodes-base.googleSheetsTool - googleSheetsTool
Config choices
Version 4.6

3. Summary Table

Workflow AI agent that updates its own rules to modify behavior
Complexity advanced
Nodes 15
Categories Engineering, AI Chatbot
Author GiovanniSegar
Published 05 Jun 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/4694/4694.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does AI agent that updates its own rules to modify behavior do?

Video walkthrough https://www.youtube.com/watch?v=OwIFK r NtQ Summary of agent This agent can write and rewrite its own rules, allowing you to mold its behavior. It receives rules from a database a...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, AI Chatbot use case.