api.workflows

create()

api.workflows.create(definition) → Promise<Workflow>

Validiert die gesamte Definition und speichert sie. Alles, was überprüft werden kann, wird hier überprüft – wo Sie die Nachricht noch lesen.

POST /api/workflowsvalidated on savetools are serialised
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

const workflow = await api.workflows.create({
  name: "Triage",
  trigger: { type: "manual" },
  steps: [
    { id: "classify", type: "model.generate", config: { model: "gemini-3.5-flash",
        prompt: "Is this urgent? {{input.text}}", schema: { type: "object", properties: { urgent: { type: "boolean" } } } } },
    { id: "check",    type: "condition", config: { left: "{{steps.classify.output.urgent}}", operator: "eq", right: true } },
    { id: "approve",  type: "human", config: { title: "Send the alert?" } },
    { id: "alert",    type: "mail.send", config: { box: "ops@example.com", to: "team@example.com",
        subject: "Urgent", text: "{{input.text}}" } },
    { id: "file",     type: "storage.write", config: { storage: "…", action: "insert", collection: "tickets",
        documents: [{ text: "{{input.text}}" }] } },
  ],
  edges: [
    { from: "__trigger", to: "classify" },
    { from: "classify", to: "check" },
    { from: "check", to: "approve", branch: "true" },
    { from: "check", to: "file",    branch: "false" },
    { from: "approve", to: "alert" },
  ],
});
workflow = api.workflows.create({
    "name": "Triage",
    "trigger": {"type": "manual"},
    "steps": [
        {"id": "classify", "type": "model.generate", "config": {"model": "gemini-3.5-flash",
            "prompt": "Is this urgent? {{input.text}}",
            "schema": {"type": "object", "properties": {"urgent": {"type": "boolean"}}}}},
        {"id": "check", "type": "condition", "config": {"left": "{{steps.classify.output.urgent}}", "operator": "eq", "right": True}},
        {"id": "approve", "type": "human", "config": {"title": "Send the alert?"}},
        {"id": "alert", "type": "mail.send", "config": {"box": "ops@example.com", "to": "team@example.com",
            "subject": "Urgent", "text": "{{input.text}}"}},
        {"id": "file", "type": "storage.write", "config": {"storage": "…", "action": "insert", "collection": "tickets",
            "documents": [{"text": "{{input.text}}"}]}},
    ],
    "edges": [
        {"from": "__trigger", "to": "classify"},
        {"from": "classify", "to": "check"},
        {"from": "check", "to": "approve", "branch": "true"},
        {"from": "check", "to": "file", "branch": "false"},
        {"from": "approve", "to": "alert"},
    ],
})

Was überprüft wird, bevor es gespeichert wird

  • Jeder Schritt id ist einzigartig und gut geformt; es gibt höchstens 30.
  • Jeder Schritttyp existiert, und seine eigene erforderliche Konfiguration ist vorhanden.
  • Jeder {{steps.…}}-Referenzname bezeichnet einen Schritt, der existiert und der vorgelagert ist .
  • Der Graph hat genau eine Kante vom Trigger, keinen Zyklus und keinen unerreichbaren Schritt.
  • Eine Bedingung hat einen true und einen false Rand; ein Schalter hat einen pro Fall plus default; ein Zusammenführen hat mindestens zwei Eingänge.
  • Alles, was außerhalb des Kontos handelt, hat eine human Schritt vorwärts.
  • Ein agent.run nennt nur Werkzeuge, die existieren.
Eine baumelnde Vorlage ist die häufigste Ablehnung

{{steps.draft.output.text}} auf einem Schritt, der vor dem Draft läuft, wird hier gefangen anstatt einen leeren String zur Laufzeit zu erzeugen. Die Validierung ist streng, weil ein Workflow fehlschlägt, wo niemand zusieht.

Agenten-Tools sind für Sie serialisiert

{ id: "research", type: "agent.run", config: {
    model: "gemini-3.5-flash",
    tools: { search: api.tools.search, fetch: api.tools.fetch },   // the SDK serialises this
} }
# In Python, an agent.run step names its built-in tools; the server runs them
{"id": "research", "type": "agent.run", "config": {
    "model": "gemini-3.5-flash",
    "tools": ["search", "fetch"],
}}

Als Objekt geschrieben wird es zum Array, das die Plattform speichert. Bereits als Array geschrieben, wird es so gesendet, wie es ist – und ein unbekannter Toolname wird mit der Liste der existierenden verweigert.

Fehler

Alles oben kommt zurück als invalid_workflow (400), mit einer Nachricht, die den Schritt und das Problem. Es gibt einen Code, weil es eine Antwort: beheben Sie die Definition.