العودة إلى الأخبار
إصدارEmail + Workflows11 دقائق قراءة

Draft, review and send professional emails with Gemini 4 Argon.

Build an IaGenify workflow that turns an incoming request into a polished reply, pauses for a human edit, sends only after approval, and keeps a trace of every step.

geminiargonemailworkflowssdktutorial

This tutorial builds a working email desk, not a one-shot prompt. A sample customer message enters an IaGenify workflow; Gemini 4 Argon prepares a professional reply; the workflow pauses while a person edits it; then IaGenify Mail sends the approved version and the run records each step. The runnable Node.js example lets a visitor edit the subject and body in the terminal, approve the send or cancel the run, and inspect or retry a failed step.

The visitor experience

The visitor starts with a sample email about an order, selects a tone in the prompt, and runs the manual workflow. The example prints the draft subject and body, then asks for edits and an explicit send approval. Approving resumes the paused run and sends the edited text; declining cancels it and sends nothing. The run data shows the model draft, human approval and mail delivery result.

Create the draft, approval and send steps

The workflow below uses a manual trigger so a visitor can run it with sample data before connecting a real mailbox. A structured model response gives the interface separate subject and body fields. The human step is a required gate before mail.send; the edited values passed to run.resume become the actual send content.

import { IaGenify } from "iagenify";
import { createInterface } from "node:readline/promises";
import { stdin, stdout } from "node:process";

const api = new IaGenify({ apiKey: process.env.IAGENIFY_API_KEY });
const rl = createInterface({ input: stdin, output: stdout });

const workflow = await api.workflows.create({
  name: "Professional reply with review",
  trigger: { type: "manual" },
  steps: [
    {
      id: "draft",
      type: "model.generate",
      config: {
        model: "gemini-4-argon",
        schema: {
          type: "object",
          properties: {
            subject: { type: "string" },
            text: { type: "string" },
          },
          required: ["subject", "text"],
        },
        inputs: [{ type: "text", content: "Write a concise, professional reply. Use this style: {{input.tone}}. Use the sender's language. Do not invent order status, policy or dates.\nIncoming message from {{input.from.address}}:\nSubject: {{input.subject}}\n{{input.text}}" }],
      },
    },
    { id: "approval", type: "human", config: { title: "Review and edit the reply before sending" } },
    {
      id: "send",
      type: "mail.send",
      config: {
        box: "[email protected]",
        to: "{{input.from.address}}",
        subject: "{{steps.approval.output.subject}}",
        text: "{{steps.approval.output.text}}",
      },
    },
  ],
  edges: [
    { from: "__trigger", to: "draft", branch: "next" },
    { from: "draft", to: "approval", branch: "next" },
    { from: "approval", to: "send", branch: "next" },
  ],
});

Run it, edit the draft and approve the send

const run = await workflow.run({
  input: {
    from: { address: process.env.DEMO_RECIPIENT || "[email protected]" },
    tone: (await rl.question("Reply style [warm, concise, formal]: ")).trim() || "warm",
    subject: "When will my order ship?",
    text: "Hello, could you tell me when order 4821 is expected to ship?",
  },
});

await run.wait(); // pauses at the human approval step

const draftStep = run.data.steps.find((step) => step.id === "draft");
const draft = draftStep.output.outputs[0].content;
console.log("\nDraft subject:", draft.subject);
console.log("\nDraft reply:\n" + draft.text);

const subjectEdit = await rl.question("\nNew subject (Enter keeps draft): ");
const bodyEdit = await rl.question("New reply (Enter keeps draft): ");
const editedSubject = subjectEdit.trim() || draft.subject;
const editedBody = bodyEdit.trim() || draft.text;
const approve = await rl.question("Send this reply? [y/N] ");

if (approve.trim().toLowerCase() === "y") {
  await run.resume("approval", { subject: editedSubject, text: editedBody });
  await run.wait({ until: ["succeeded", "failed", "cancelled"] });
} else {
  await run.cancel();
}

console.log(run.data.status, run.data.steps);
rl.close();

Connect a real IaGenify mailbox

After the manual demo works, the visitor can connect an IaGenify mailbox and change the trigger to an incoming-message trigger, with optional sender and subject filters. The workflow still pauses at the same review step. Sending a reply must remain behind that human approval step; the workflow engine rejects a mail.send step that has no human approval upstream.

Make the workflow useful for a support team

Before approving a real send, set DEMO_RECIPIENT to an address you control and set box to a real IaGenify mailbox in your account. Readers can extend the example with team-specific response rules, a connected knowledge store or branches that route billing, delivery and product questions to different queues. Argon drafts from the evidence supplied; the workflow and the reviewer determine what gets sent.

Let the model prepare the reply; let the workflow make review and delivery visible.

Model and developer references

الأسئلة الشائعة

Does the example send a message without review?

No. The mail.send step follows a human approval step, and the workflow is designed to pause until a person resumes it with the edited subject and body.

Can I try it without configuring a mailbox first?

Yes. Start with the manual trigger and sample email. Configure an IaGenify mailbox before trying the real mail trigger and send step.

What happens if sending fails?

The run records the failed step. The visitor can inspect the run and retry from the failed step after correcting the cause.

Can Argon send the email directly as an agent tool?

The workflow uses the dedicated mail.send step after human approval; sending is not exposed as a direct agent tool.

العودة إلى الأخبار