Chat with Gemini AI Agent via Local Command Line Interface (CLI) - n8n Workflow

Use this powerful n8n workflow to create an AI Agent that leverages the Google Gemini Chat Model and executes commands locally via SSH using a custom n8n node tool.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Technical users and developers running self-hosted n8n installations.

  • Teams requiring AI Agents to interact with local system files, databases, or proprietary tools.

  • Automation specialists looking for advanced n8n workflow examples integrating LangChain agents with custom scripting.

  • Users who need to manage their Gemini interactions through a secure, self-hosted n8n node structure.

Overview

This sophisticated n8n workflow demonstrates how to build a powerful AI Agent capable of interacting with your local server environment. By integrating the Google Gemini Chat Model with a custom tool that uses SSH, the agent can execute commands (like calling the gemini CLI) directly on the host machine.

This setup is critical for bridging the gap between cloud LLMs and local resources, allowing the agent to perform actions or fetch information that a standard external API cannot access. This n8n workflow leverages sub-workflows as custom tools, a key feature in building complex n8n templates. The resulting n8n Agent is highly extensible, allowing you to add more local CLI tools as needed. This approach maximizes the utility of your self-hosted n8n instance.

How it Works

This n8n workflow operates in two linked parts: the Main Agent Workflow and the Sub-workflow Tool (which must be saved separately).


  1. Chat Initiation: The process starts with the When chat message received n8n trigger, which receives input from a user chat interface and establishes a streaming connection.

  2. Agent Processing: The input is fed into the AI Agent n8n node. This agent is configured with a system prompt that mandates the use of the 'Gemini CLI' tool before responding.

  3. LLM & Memory: The Google Gemini Chat Model provides the reasoning capabilities, while the Simple Memory n8n node maintains conversation context.

  4. Tool Call: When the agent decides to use the CLI, it triggers the Call 'Gemini CLI' n8n node, passing the user's prompt to the separate sub-workflow.

  5. Sub-workflow Execution (SSH): The sub-workflow begins with the When Executed by Another Workflow n8n trigger. It receives the prompt.

  6. Local Command Execution: The Execute a command n8n node securely connects via SSH to the target host and runs the command gemini "{{ $json.prompt }}". This uses the locally installed Gemini CLI to generate the AI response.

  7. Response Return: The Edit Fields n8n node formats the CLI output (stdout) into an answer field. This response is then returned through the tool call back to the main AI Agent n8n workflow, which delivers the final response to the user.

Installation Guide

To deploy this advanced n8n workflow template, follow these steps:


  1. Import: Import this JSON into your self-hosted n8n instance.

  2. Prerequisites: Ensure your n8n host or a reachable server has NodeJS >= 20.x, the Gemini CLI installed (npm install -g @google/gemini-cli), and that n8n has SSH access configured.

  3. Separate the Sub-workflow: The nodes labeled 'Sub-workflow' (from When Executed by Another Workflow to Edit Fields) must be copied and saved as a new, separate n8n workflow.

  4. Configure SSH Credentials: In the new sub-workflow, update the Execute a command n8n node with your specific SSH host credentials (Hostname, User, Key or Password).

  5. Link the Tool: Return to the main n8n workflow. In the Call 'Gemini CLI' n8n node, select the new sub-workflow you just created from the dropdown list. This links the custom tool.

  6. Activate: Save and activate both the main n8n workflow and the sub-workflow. The When chat message received n8n trigger is now ready to handle interactions.

Node Details

When chat message received (Langchain ChatTrigger): This is the primary n8n trigger for the agent. It sets up a webhook to receive chat input and is configured for streaming responses.
AI Agent (Langchain Agent): The central orchestration n8n node. It manages the conversational flow and determines whether to use the internal LLM or the external 'Gemini CLI' n8n tool, based on the systemMessage prompt instructing its mandatory use.
Google Gemini Chat Model (Langchain LLM): Provides the large language model capabilities that the agent uses for reasoning and generating final output.
Call 'Gemini CLI' (Langchain ToolWorkflow): A specialized n8n node that acts as a bridge. It calls the secondary, linked n8n workflow to execute the CLI command, effectively making external scripts into native agent tools. It passes the prompt data.
When Executed by Another Workflow (Trigger): The specific n8n trigger used in the sub-workflow to accept execution and input data when called by the Call 'Gemini CLI' n8n node.
Execute a command (SSH n8n node): The core action component of the sub-workflow. It runs the shell command gemini "{{ $json.prompt }}" remotely via SSH, utilizing the power of the local Gemini CLI installation.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by

I am a Technical Operations Manager who bridges the gap between complex code and business revenue. With over 15 years of experience, I don't just build websites; I build digital ecosystems that sell. I specialize in taking ownership of the entire technical and marketing stack for SMEs—handling everything from Server Configuration and Python automation to Google Ads and SEO strategy. Core Value: I help business owners stop worrying about their technology so they can focus on their customers.

Featured*