LongCat
AI-powered chat completion using LongCat models with thinking capabilities and AI Agent integration
Overview
The LongCat node provides AI-powered chat completion using specialized LongCat models. It supports two main models: a standard chat model and an advanced thinking-capable chat model. This node is designed for scenarios where users want to integrate conversational AI into their workflows, such as customer support automation, interactive assistants, or AI agent integrations within n8n.
Key features include:
- Sending user messages to the LongCat API and receiving AI-generated responses.
- Optional conversation history to maintain context across multiple interactions.
- Advanced options like enabling "thinking" mode for deeper reasoning with the thinking-capable model.
- Integration support for AI agents with structured response formats and tool usage.
- Customizable system prompts to guide AI behavior.
- Control over generation parameters like temperature, max tokens, and top-p sampling.
Practical examples:
- Automating customer service chats by sending user queries and getting helpful replies.
- Building AI agents that can call external tools or APIs based on user input.
- Creating chatbots that remember conversation history and provide context-aware answers.
- Experimenting with creative or deterministic responses by adjusting randomness settings.
Properties
| Name | Meaning |
|---|---|
| Model | The LongCat model to use. Options: "LongCat-Flash-Chat" (standard chat model), "LongCat-Flash-Thinking" (chat model with thinking capabilities). |
| User Message | The message text sent from the user to LongCat. Can reference input data fields using expressions (e.g., {{ $json.message }}). |
| AI Agent Integration | Whether to enable enhanced compatibility with n8n AI Agent nodes, allowing structured responses and tool usage. |
| Conversation History | Optional JSON array of previous messages to provide context for the conversation. Should be a valid JSON string representing an array of messages. |
| Enable Thinking | Enables thinking mode for the "LongCat-Flash-Thinking" model, activating deeper reasoning capabilities. |
| Include Input Data | Whether to include the original input data in the output, useful for downstream processing or debugging. |
| Max Tokens | Maximum number of tokens to generate in the AI response (range 1 to 8192). |
| Response Format | When AI Agent Integration is enabled, controls the format of the response: "Text" (plain text), "JSON" (JSON formatted), or "Structured" (structured response for AI agents). |
| System Prompt | A prompt to set the AI's behavior or persona. If left empty, default behavior is used. |
| Temperature | Controls randomness of the output. Lower values produce more deterministic results; higher values increase creativity (range 0 to 2). |
| Thinking Budget | Maximum length of content allocated for thinking mode (minimum 1024 tokens), applicable only when thinking mode is enabled on the thinking-capable model. |
| Tool Usage Support | Enables support for tool calling in AI agent mode, allowing the AI to invoke external tools or packages during its response generation. |
| Top P | Controls diversity via nucleus sampling, influencing how many probable tokens are considered during generation (range 0 to 1). |
Output
The node outputs an array of items, each containing a json object with the following structure:
id: Unique identifier of the API response.model: The LongCat model used for generating the response.content: The AI-generated response content. Its format depends on the selected response format and AI agent mode:- Plain text string if AI agent mode is off or response format is "text".
- JSON string or parsed JSON object if response format is "json".
- Structured object with response and metadata if response format is "structured".
usage: Token usage statistics returned by the API.finishReason: Reason why the generation finished (e.g., stop token reached).timestamp: ISO timestamp of when the response was generated.aiAgentMode(optional): Boolean indicating if AI agent mode was enabled.responseFormat(optional): The response format used.toolUsage(optional): Boolean indicating if tool usage was enabled.metadata: Additional metadata including provider name ("LongCat"), model type, whether thinking mode was active, and node version.thinking(optional): Thinking content if thinking mode was enabled and returned by the API.toolCalls(optional): Details of any tool calls made by the AI agent.originalInput(optional): The original input JSON data if "Include Input Data" option was enabled.- Binary data is passed through unchanged if present in the input and included.
Dependencies
- Requires an API key credential for authenticating with the LongCat API endpoint (
https://api.longcat.chat/openai/v1/chat/completions). - Network access to the LongCat API service.
- Optional: Enabling AI Agent Integration may require additional configuration or permissions related to tool usage within n8n.
Troubleshooting
- Invalid API Key or Authentication Errors: Ensure the API key credential is correctly configured and has necessary permissions.
- Malformed Conversation History: The conversation history must be a valid JSON array string; otherwise, it will be ignored without error but context will be lost.
- Exceeding Token Limits: Setting
maxTokensorthinkingBudgetbeyond allowed limits (1–8192) may cause errors. Use values within specified ranges. - Response Parsing Errors: When using JSON or structured response formats, invalid JSON in the AI response may cause parsing issues. The node attempts to fallback by wrapping the response in a JSON object.
- Tool Usage Not Working: If tool usage is enabled but tools do not respond, verify that the environment supports tool calling and that the appropriate flags are set.
- Empty or Missing User Message: If the user message expression resolves to empty, the request may fail or return irrelevant responses. Ensure the input data contains expected fields.
Links and References
- LongCat API Documentation (hypothetical link based on API URL)
- n8n Documentation on Creating Nodes
- OpenAI Chat Completion API Reference (for conceptual similarity)