Learning Timeline
Key Insights
The Importance of Session ID
Every new conversation has a unique Session ID. If you click 'Reset' in the chat, the ID will change, and the Agent will treat it as a brand new conversation without its previous memory.
Context Window Tips
Increasing the 'Context Window Length' allows the Agent to remember longer conversations, but it will consume more 'tokens' for each API request.
Prompts
Memory Context Test
Target:
n8n Chat Trigger
When was Albert Einstein born?
How old would he be today?
Step by Step
How to Set Up an AI Agent Workflow in n8n
- Open your n8n dashboard and click to create a new workflow.
- Name your workflow by clicking the name section at the top left (e.g., 'Santa's helper AI agent').
- Click the 'Add a first step' button (+ icon) in the center of the canvas.
- Search for 'AI Agent' in the search bar and select that node.
- n8n will automatically insert two nodes: 'AI Agent' and 'Chat Trigger'.
- Click on the 'AI Agent' node to open the settings panel.
Connecting the Brain (LLM) to the AI Agent
- On the AI Agent node, locate the 'Chat Model' section.
- Click the input to add a new model and select 'Google Gemini Chat Model' (or other models like OpenAI/Claude).
- In the 'Credential for Google Gemini Chat API' section, select an existing account or click 'Create New Credential' to enter your API Key.
- Close the model settings panel to return to the main canvas.
- Test the connection by clicking the 'Chat' or 'Test Step' button and typing a simple message like 'Hi there'.
Adding Memory Functionality to the Agent
- Click on the 'AI Agent' node again.
- Find the 'Memory' section and click the '+' button to add memory.
- Select 'Window Buffer Memory' from the list of options.
- In the Window Buffer Memory settings, find the 'Context Window Length' field.
- Change the 'Context Window Length' value to '20' (or the number of messages you want the Agent to remember).
- Ensure 'Session ID' is left at its default setting (usually using the expression `{{ $json.sessionId }}`).
- Test the Agent again by asking a follow-up question (e.g., ask 'When was Einstein born?' and then 'How old would he be now?') to ensure the Agent remembers the context.