Dify Email Agent Setup Guide
Dify Email Agent Setup Guide
The document recommends using an OpenAPI 3.0 compliant JSON schema, which includes defining fields like action (as strings with enumerations for 'send_email', 'get_unread_emails', 'read_email'), and params (an object containing fields like recipient_id, subject, message, and optional email_id). These elements specify types, descriptions, and are required fields for actions .
Ensuring compatibility with an OpenAI-API is crucial as it allows seamless integration of the LLM model with Dify's ecosystem. It ensures the system can fully utilize API endpoints for model utilization, promoting interoperability and effective model-based operations within custom applications and agents .
Before starting the integration, ensure that Dify is installed and running, you have access to a local or remote LLM endpoint, and the model 'llm_zh_v_1_3_1' is accessible from your endpoint .
When adding the 'llm_zh_v_1_3_1' model, you configure the model type and name, and you can leave the API Key blank if unnecessary. The endpoint URL and context size are required, while other settings can be customized as needed according to specific requirements .
Error handling is managed by defining response schemas for 200, 400, and 500 status codes in the email action paths. A successful operation returns a 200, 'Bad Request' returns a 400, and 'Internal Server Error' returns a 500, with descriptions and content for each response type .
Setting up the Email Sending Agent involves navigating to the 'Tool' tab in Dify, clicking the 'Customer' tab, and then 'Create Customer Tool'. Set the Name field for the agent and configure the scheme with server URL and paths for actions like 'send_email', 'get_unread_emails', and 'read_email', conforming to a JSON structure, then save the configuration .
To configure the 'llm_zh_v_1_3_1' model, navigate to the Model Provider tab in Dify settings, install the OpenAI-Compatible option if not already done, and click 'Add Model'. Configure the model type as LLM, the model name as 'llm_zh_v_1_3_1', leave the API Key blank if not required, set the API endpoint URL to http://<your-server-ip>:5001/openai/v1, and set the model context size to 4096 .
First-time Google Authorization is necessary to grant the application permissions to access Gmail functionalities. This process is crucial for obtaining and securing access and refresh tokens, enabling subsequent email-related actions, vital for operational continuity of the Email Sending Agent .
To create the app, locate the 'Create App' box and select 'Create from blank'. Choose 'Workflow', enter the app name and icon, set parameters for the START block, add a block for LLM selection, select 'llm_zh_v_1_3_1' as the model, then add another block for the 'Email Sender Agent' and choose 'executeGmailAction'. Link these blocks and add any necessary additional blocks like if/else before finalizing with an End block .
Testing and running involve ensuring the local LLM server and MCP Server are operational. Start the MCP Server with the command: 'uvicorn main:app --host 0.0.0.0 --port 8000'. For first-time usage, authorize Google access via a web browser, which saves the tokens to token.json. Finally, test the workflow to confirm email functionalities .