Flows
Was ist ein Flow?
Abschnitt betitelt „Was ist ein Flow?“Ein Flow ist ein in YAML definierter Orchestrierungsgraph, der beschreibt, wie Nachrichten und Daten durch Ihren digitalen Worker laufen. Flows werden in .ygtc-Dateien gespeichert und definieren:
- Nodes - Einzelne Verarbeitungsschritte (WASM-Komponenten)
- Edges - Verbindungen zwischen Nodes
- Triggers - Was den Flow startet
- Conditions - Verzweigungslogik
Grundstruktur eines Flows
Abschnitt betitelt „Grundstruktur eines Flows“name: hello_worldversion: "1.0"description: A simple greeting flow
# Define the nodes (processing steps)nodes: - id: greet type: reply config: message: "Hello! How can I help you today?"
# Define what triggers this flowtriggers: - type: message pattern: "hello|hi|hey" target: greetFlow-Komponenten
Abschnitt betitelt „Flow-Komponenten“Nodes sind die Bausteine eines Flows. Jede Node repräsentiert eine WASM-Komponente, die Daten verarbeitet:
nodes: - id: unique_node_id type: node_type # Component type config: # Component-specific configuration key: value next: next_node_id # Optional: next node to executeHäufige Node-Typen
Abschnitt betitelt „Häufige Node-Typen“| Typ | Zweck |
|---|---|
reply | Eine Nachricht an den Benutzer zurücksenden |
llm | Ein LLM aufrufen (OpenAI usw.) |
template | Ein Handlebars-Template rendern |
script | Ein Rhai-Skript ausführen |
branch | Bedingte Verzweigung |
http | HTTP-Anfragen ausführen |
state | Session-Zustand verwalten |
Edges verbinden Nodes miteinander. Sie können implizit (über next) oder explizit sein:
nodes: - id: start type: template config: template: "Processing your request..." next: process
- id: process type: llm config: model: "gpt-4" prompt: "{{message}}" next: respond
- id: respond type: reply config: message: "{{llm_response}}"Trigger
Abschnitt betitelt „Trigger“Trigger definieren, was einen Flow startet:
triggers: # Message pattern trigger - type: message pattern: "order|purchase|buy" target: handle_order
# Default trigger (catch-all) - type: default target: fallback_handler
# Event trigger - type: event event_type: "user.created" target: welcome_userBedingte Verzweigung
Abschnitt betitelt „Bedingte Verzweigung“Verwenden Sie branch-Nodes für bedingte Logik:
nodes: - id: check_intent type: branch config: conditions: - expression: "intent == 'greeting'" next: greet_user - expression: "intent == 'help'" next: show_help - expression: "intent == 'order'" next: process_order default: fallback
- id: greet_user type: reply config: message: "Hello! Nice to meet you!"
- id: show_help type: reply config: message: "Here's what I can help you with..."
- id: fallback type: reply config: message: "I'm not sure I understand. Can you rephrase?"Mit Zustand arbeiten
Abschnitt betitelt „Mit Zustand arbeiten“Flows können Session-Zustand lesen und schreiben:
nodes: - id: save_name type: state config: action: set key: "user_name" value: "{{extracted_name}}" next: confirm
- id: get_name type: state config: action: get key: "user_name" output: "stored_name" next: greet_by_nameLLM-Integration
Abschnitt betitelt „LLM-Integration“Integrieren Sie LLMs für KI-gestützte Antworten:
nodes: - id: analyze type: llm config: model: "gpt-4" system_prompt: | You are a helpful customer service agent. Extract the user's intent and any relevant entities. prompt: "User message: {{message}}" output_format: json next: process_resultTemplate-Rendering
Abschnitt betitelt „Template-Rendering“Verwenden Sie Handlebars-Templates für dynamische Inhalte:
nodes: - id: format_response type: template config: template: | Hi {{user_name}}!
Here's your order summary: {{#each items}} - {{name}}: ${{price}} {{/each}}
Total: ${{total}} next: send_responseFlow-Validierung
Abschnitt betitelt „Flow-Validierung“Validieren Sie Ihre Flows vor dem Deployment:
greentic-flow doctor ./flows/
# Or with the GTC CLIgtc flow validate ./flows/hello.ygtcBest Practices
Abschnitt betitelt „Best Practices“- Flows fokussiert halten - Ein Flow pro Benutzerintention oder Workflow
- Aussagekräftige IDs verwenden - Node-IDs sollten ihren Zweck beschreiben
- Mit Kommentaren dokumentieren - Beschreibungen zu komplexen Flows hinzufügen
- Schrittweise testen - Nach jeder Änderung validieren
- Flows versionieren - Semantische Versionierung verwenden
Beispiel: Vollständiger Customer-Service-Flow
Abschnitt betitelt „Beispiel: Vollständiger Customer-Service-Flow“name: customer_serviceversion: "1.0"description: Handle customer inquiries with AI assistance
nodes: # Analyze the incoming message - id: analyze_intent type: llm config: model: "gpt-4" system_prompt: | Classify the customer's intent into one of: - greeting - order_status - product_question - complaint - other
Respond with JSON: {"intent": "...", "confidence": 0.0-1.0} prompt: "{{message}}" output_format: json next: route_intent
# Route based on intent - id: route_intent type: branch config: conditions: - expression: "intent.intent == 'greeting'" next: handle_greeting - expression: "intent.intent == 'order_status'" next: handle_order_status - expression: "intent.intent == 'complaint'" next: handle_complaint default: handle_general
# Handle greeting - id: handle_greeting type: reply config: message: "Hello! Welcome to our support. How can I help you today?"
# Handle order status - id: handle_order_status type: http config: method: GET url: "https://api.example.com/orders/{{order_id}}" next: format_order_response
- id: format_order_response type: template config: template: | Your order #{{order_id}} is currently: {{status}} Expected delivery: {{delivery_date}} next: send_order_response
- id: send_order_response type: reply config: message: "{{formatted_response}}"
# Handle complaints with escalation - id: handle_complaint type: reply config: message: "I'm sorry to hear that. Let me connect you with a specialist who can help resolve this." next: escalate_to_human
- id: escalate_to_human type: event config: event_type: "escalation.requested" payload: reason: "complaint" conversation_id: "{{session_id}}"
# General handler - id: handle_general type: llm config: model: "gpt-4" system_prompt: "You are a helpful customer service agent. Be friendly and concise." prompt: "{{message}}" next: send_general_response
- id: send_general_response type: reply config: message: "{{llm_response}}"
triggers: - type: message target: analyze_intentNächste Schritte
Abschnitt betitelt „Nächste Schritte“- Packs - Ihre Flows für das Deployment paketieren
- Komponenten - Benutzerdefinierte Node-Typen erstellen
- Flow-Schema-Referenz - Vollständiges YAML-Schema