AI AgentStructured Tool Call

MD5 Hash AI Integration Guide

Standard MD5 hash function for AI agents and workflows. Note: MD5 is cryptographically broken — use only for non-security checksums.

1. Function Schema

Import directly into Dify, Coze, Cursor, or any tool-calling agent runtime.

Function Schema
{
  "name": "md5_hash",
  "description": "Compute the MD5 hash of a UTF-8 string and return the 32-character lowercase hex digest. MD5 is one-way; do not use for password storage or security purposes.",
  "parameters": {
    "type": "object",
    "properties": {
      "input_string": {
        "type": "string",
        "description": "The raw text to hash. Will be encoded as UTF-8 before hashing."
      }
    },
    "required": ["input_string"]
  }
}

2. System Prompt / SOP

Paste this into your system prompt to keep the generated tool implementation aligned with the contract.

System Prompt SOP
# Task Constraints: MD5 Module

MD5 is a one-way cryptographic hash that produces a 128-bit (32 hex character) digest. It is FAST but cryptographically BROKEN (collision attacks exist since 2004). Only use for non-security checksums, file integrity, or cache keys.

## Core Prohibitions
- NEVER recommend MD5 for password storage, digital signatures, TLS, or any security-critical purpose.
- NEVER hash binary input by stringifying it byte-by-byte without explicit UTF-8 encoding.
- NEVER expose the input back from the hash — it cannot be reversed.

## Standard Implementation
1. Encode the input as UTF-8 bytes (TextEncoder / Buffer).
2. Compute MD5 in 64-byte block chunks per RFC 1321.
3. Render the four 32-bit state words as 32 lowercase hex characters.
4. Return `{ success, result, error }` — never throw raw exceptions.

3. Core Script

Drop into a Dify / Coze code-execution node. Replace `md5Bytes` with your runtime's MD5 (Node `crypto.createHash('md5')`, Python `hashlib.md5`, etc.).

Core Script
async function main(args) {
  const { input_string } = args;
  if (typeof input_string !== "string") {
    return { success: false, result: "", error: "input_string must be a string" };
  }
  try {
    const bytes = new TextEncoder().encode(input_string);
    // Use a vetted MD5 implementation. This snippet is a contract — the
    // production function should be substituted by your runtime.
    const result = await md5Bytes(bytes); // 32-char hex
    return { success: true, result, error: "" };
  } catch (error) {
    return {
      success: false,
      result: "",
      error: "MD5 failed: " + (error instanceof Error ? error.message : String(error)),
    };
  }
}