mirror of
https://github.com/khoaliber/n8nworkflows.xyz.git
synced 2026-04-28 00:29:22 +00:00
creation
This commit is contained in:
@@ -0,0 +1,227 @@
|
||||
AI agent chat
|
||||
|
||||
https://n8nworkflows.xyz/workflows/ai-agent-chat-1954
|
||||
|
||||
|
||||
# AI agent chat
|
||||
|
||||
### 1. Workflow Overview
|
||||
|
||||
This workflow implements an intelligent AI conversational agent using OpenAI’s language models combined with SerpAPI for real-time information retrieval. It is designed for interactive chat scenarios where users send messages manually (via chat triggers), and the agent responds contextually, maintaining conversation memory.
|
||||
|
||||
The workflow is composed of four main logical blocks:
|
||||
|
||||
- **1.1 Input Reception:** Captures incoming chat messages via a manual chat trigger node.
|
||||
- **1.2 Memory Buffer:** Maintains a sliding window of conversation history to provide contextual awareness to the AI agent.
|
||||
- **1.3 AI Processing:** Uses OpenAI’s GPT-4o-mini language model to generate natural language responses.
|
||||
- **1.4 External Knowledge Integration:** Calls SerpAPI tool to augment AI responses with up-to-date search data.
|
||||
- **1.5 AI Agent Coordination:** Orchestrates inputs from the chat trigger, memory, language model, and external tool to generate final replies.
|
||||
|
||||
---
|
||||
|
||||
### 2. Block-by-Block Analysis
|
||||
|
||||
#### 2.1 Input Reception
|
||||
|
||||
- **Overview:**
|
||||
Captures chat messages initiated by a user or external system, triggering the workflow to start processing.
|
||||
|
||||
- **Nodes Involved:**
|
||||
- When chat message received
|
||||
|
||||
- **Node Details:**
|
||||
|
||||
- **When chat message received**
|
||||
- Type: `@n8n/n8n-nodes-langchain.chatTrigger`
|
||||
- Role: Webhook-based trigger node specialized for chat messages. Listens for incoming chat inputs to start the workflow.
|
||||
- Configuration: Default options, no filters or special parameters configured.
|
||||
- Key expressions/variables: None (standard chat trigger behavior).
|
||||
- Inputs: None (trigger node).
|
||||
- Outputs: Connected to the AI Agent node’s main input.
|
||||
- Version: 1.1 (requires n8n 1.50.0+ for compatibility).
|
||||
- Edge Cases:
|
||||
- Incoming message format error or missing data could cause failures.
|
||||
- Webhook connectivity or security misconfiguration may prevent triggering.
|
||||
|
||||
#### 2.2 Memory Buffer
|
||||
|
||||
- **Overview:**
|
||||
Maintains a sliding window memory buffer to provide conversational context continuity for the AI agent, simulating short-term memory in conversations.
|
||||
|
||||
- **Nodes Involved:**
|
||||
- Simple Memory
|
||||
|
||||
- **Node Details:**
|
||||
|
||||
- **Simple Memory**
|
||||
- Type: `@n8n/n8n-nodes-langchain.memoryBufferWindow`
|
||||
- Role: Implements a context window memory buffer to store recent chat history.
|
||||
- Configuration: Default parameters (window size and retention policies implicit).
|
||||
- Expressions/variables: None explicitly configured, memory is internally managed.
|
||||
- Inputs: None directly (receives context references from AI agent node).
|
||||
- Outputs: Connected to AI Agent node’s ai_memory input.
|
||||
- Version: 1.3 (requires n8n 1.50.0+).
|
||||
- Edge Cases:
|
||||
- Memory overflow if window size is too small or conversation too long may truncate important context.
|
||||
- Memory desynchronization if underlying data updates asynchronously.
|
||||
|
||||
#### 2.3 AI Processing
|
||||
|
||||
- **Overview:**
|
||||
Utilizes OpenAI’s GPT-4o-mini model to generate natural language responses based on input and memory context.
|
||||
|
||||
- **Nodes Involved:**
|
||||
- OpenAI Chat Model
|
||||
|
||||
- **Node Details:**
|
||||
|
||||
- **OpenAI Chat Model**
|
||||
- Type: `@n8n/n8n-nodes-langchain.lmChatOpenAi`
|
||||
- Role: Calls OpenAI API to generate chat completions using GPT-4o-mini.
|
||||
- Configuration: Model set explicitly to `gpt-4o-mini`. No additional options or custom parameters set.
|
||||
- Expressions/variables: No dynamic expressions; static model choice.
|
||||
- Inputs: None directly (integrated via AI Agent node).
|
||||
- Outputs: Connected to AI Agent node’s ai_languageModel input.
|
||||
- Credentials: Requires OpenAI API credentials configured (`OpenAi account`).
|
||||
- Version: 1.2 (requires n8n 1.50.0+).
|
||||
- Edge Cases:
|
||||
- API rate limits or authentication errors.
|
||||
- Model unavailability or deprecation.
|
||||
- Latency or timeout issues from OpenAI service.
|
||||
|
||||
#### 2.4 External Knowledge Integration
|
||||
|
||||
- **Overview:**
|
||||
Enables the AI Agent to query SerpAPI for real-time search results to enhance response accuracy and relevance.
|
||||
|
||||
- **Nodes Involved:**
|
||||
- SerpAPI
|
||||
|
||||
- **Node Details:**
|
||||
|
||||
- **SerpAPI**
|
||||
- Type: `@n8n/n8n-nodes-langchain.toolSerpApi`
|
||||
- Role: Provides external search results via SerpAPI integration.
|
||||
- Configuration: Default parameters, no search query overrides configured here (queries likely passed dynamically by AI Agent).
|
||||
- Inputs: None directly (integrated via AI Agent node).
|
||||
- Outputs: Connected to AI Agent node’s ai_tool input.
|
||||
- Credentials: Requires SerpAPI credentials configured (`SerpAPI account`).
|
||||
- Version: 1 (requires n8n 1.50.0+).
|
||||
- Edge Cases:
|
||||
- API key invalid or expired.
|
||||
- Quota limits or connectivity issues.
|
||||
- Incorrect search query formatting passed by AI agent.
|
||||
|
||||
#### 2.5 AI Agent Coordination
|
||||
|
||||
- **Overview:**
|
||||
Central orchestration node that integrates chat input, memory, language model, and external tool to generate context-aware AI chat responses.
|
||||
|
||||
- **Nodes Involved:**
|
||||
- AI Agent
|
||||
|
||||
- **Node Details:**
|
||||
|
||||
- **AI Agent**
|
||||
- Type: `@n8n/n8n-nodes-langchain.agent`
|
||||
- Role: Coordinates the conversational AI workflow by taking inputs from the chat trigger, memory buffer, language model, and SerpAPI tool to produce replies.
|
||||
- Configuration: Default options, no custom parameters. It internally manages the logic for when to call external tools or language models.
|
||||
- Expressions/variables: None explicitly configured.
|
||||
- Inputs:
|
||||
- Main input from “When chat message received” (chat messages).
|
||||
- ai_memory input from “Simple Memory”.
|
||||
- ai_languageModel input from “OpenAI Chat Model”.
|
||||
- ai_tool input from “SerpAPI”.
|
||||
- Outputs: Final chat response output back to the chat system (implicit in chat trigger integration).
|
||||
- Version: 1.8 (requires n8n 1.50.0+).
|
||||
- Edge Cases:
|
||||
- Coordination failure if any upstream node fails.
|
||||
- Misrouting of inputs or outputs.
|
||||
- Inability to parse or utilize external tool data correctly.
|
||||
|
||||
---
|
||||
|
||||
### 3. Summary Table
|
||||
|
||||
| Node Name | Node Type | Functional Role | Input Node(s) | Output Node(s) | Sticky Note |
|
||||
|-------------------------|---------------------------------------|-----------------------------|---------------------------|--------------------------|-----------------------------------------|
|
||||
| When chat message received | @n8n/n8n-nodes-langchain.chatTrigger | Input reception (chat trigger) | None | AI Agent | Requires n8n version 1.50.0 or later |
|
||||
| Simple Memory | @n8n/n8n-nodes-langchain.memoryBufferWindow | Conversation context memory | None | AI Agent (ai_memory) | |
|
||||
| OpenAI Chat Model | @n8n/n8n-nodes-langchain.lmChatOpenAi | AI language model for chat completion | None | AI Agent (ai_languageModel) | Requires OpenAI API credentials |
|
||||
| SerpAPI | @n8n/n8n-nodes-langchain.toolSerpApi | External search tool for knowledge | None | AI Agent (ai_tool) | Requires SerpAPI API credentials |
|
||||
| AI Agent | @n8n/n8n-nodes-langchain.agent | Orchestrates AI chat responses | When chat message received, Simple Memory, OpenAI Chat Model, SerpAPI | None | Central coordinator of the workflow |
|
||||
|
||||
---
|
||||
|
||||
### 4. Reproducing the Workflow from Scratch
|
||||
|
||||
1. **Create "When chat message received" node**
|
||||
- Type: `Chat Trigger` (`@n8n/n8n-nodes-langchain.chatTrigger`)
|
||||
- Position: Top-left (e.g., x: -180, y: -380)
|
||||
- Parameters: Default, no additional options required.
|
||||
- Webhook: Auto-generated or configured manually to receive chat messages.
|
||||
- Version: Use 1.1 or later.
|
||||
|
||||
2. **Create "Simple Memory" node**
|
||||
- Type: `Memory Buffer Window` (`@n8n/n8n-nodes-langchain.memoryBufferWindow`)
|
||||
- Position: Middle-left (e.g., x: 160, y: -160)
|
||||
- Parameters: Default settings (sliding window memory, no custom parameters).
|
||||
- Version: Use 1.3 or later.
|
||||
|
||||
3. **Create "OpenAI Chat Model" node**
|
||||
- Type: `OpenAI Chat Model` (`@n8n/n8n-nodes-langchain.lmChatOpenAi`)
|
||||
- Position: Center-left (e.g., x: 20, y: -160)
|
||||
- Parameters:
|
||||
- Model: Select `gpt-4o-mini` from the model list.
|
||||
- Options: Leave default.
|
||||
- Credentials: Attach valid OpenAI API credentials (set up via n8n credentials manager).
|
||||
- Version: Use 1.2 or later.
|
||||
|
||||
4. **Create "SerpAPI" node**
|
||||
- Type: `SerpAPI Tool` (`@n8n/n8n-nodes-langchain.toolSerpApi`)
|
||||
- Position: Middle-right (e.g., x: 300, y: -160)
|
||||
- Parameters: Default. Queries will be passed dynamically by AI Agent.
|
||||
- Credentials: Attach valid SerpAPI API credentials.
|
||||
- Version: Use 1 or later.
|
||||
|
||||
5. **Create "AI Agent" node**
|
||||
- Type: `Agent` (`@n8n/n8n-nodes-langchain.agent`)
|
||||
- Position: Center-top (e.g., x: 60, y: -380)
|
||||
- Parameters: Default options, no customization required.
|
||||
- Connect inputs as follows:
|
||||
- Main input from `"When chat message received"` node main output.
|
||||
- `ai_memory` input from `"Simple Memory"` node output.
|
||||
- `ai_languageModel` input from `"OpenAI Chat Model"` node output.
|
||||
- `ai_tool` input from `"SerpAPI"` node output.
|
||||
- Version: Use 1.8 or later.
|
||||
|
||||
6. **Connect the nodes**
|
||||
- Link `When chat message received` → `AI Agent` (main input)
|
||||
- Link `Simple Memory` → `AI Agent` (ai_memory input)
|
||||
- Link `OpenAI Chat Model` → `AI Agent` (ai_languageModel input)
|
||||
- Link `SerpAPI` → `AI Agent` (ai_tool input)
|
||||
|
||||
7. **Credentials Setup**
|
||||
- Configure OpenAI API credentials with valid API key.
|
||||
- Configure SerpAPI credentials with valid API key.
|
||||
|
||||
8. **Deploy and Test**
|
||||
- Ensure n8n version is 1.50.0 or later.
|
||||
- Deploy the workflow.
|
||||
- Trigger a chat message via the webhook or UI integration to test end-to-end functionality.
|
||||
|
||||
---
|
||||
|
||||
### 5. General Notes & Resources
|
||||
|
||||
| Note Content | Context or Link |
|
||||
|-----------------------------------------------------------------------------------------------|----------------------------------------------|
|
||||
| This workflow requires n8n version 1.50.0 or later to ensure compatibility with LangChain nodes. | Version requirement mentioned in the description. |
|
||||
| OpenAI API and SerpAPI credentials must be configured prior to running this workflow. | See n8n credentials manager documentation. |
|
||||
| The AI Agent node internally manages orchestration among memory, language model, and tools. | Useful for understanding data flow and debugging. |
|
||||
| For further examples and updates, visit n8n's official LangChain integration documentation. | https://docs.n8n.io/integrations/builtin/n8n-nodes-langchain/ |
|
||||
| The SerpAPI tool allows real-time web search to supplement AI responses with current info. | https://serpapi.com/ |
|
||||
|
||||
---
|
||||
|
||||
This document fully captures the structure, logic, and deployment details of the "AI agent chat" workflow, allowing advanced users or automation agents to understand, replicate, and maintain it effectively.
|
||||
Reference in New Issue
Block a user