Skip to content

Workflow Mode

Workflow mode runs a deterministic DAG pipeline: a request arrives, resources execute in dependency order, and the result is returned. Every run follows the same path for the same input.

Run with:

bash
kdeps run workflow.yaml

How it works

incoming requestPOST /api/v1/chatresolve dep graphwalks backward from targetActionIdresource: validatefails fast if input invalidresource: llmreads get('q'); calls the modelresource: respreads get('llm'); builds the responseHTTP responseoutput stored as get('validate')output stored as get('llm')

requires: is like an import -- the resource won't run until its dependencies have output. Resources with no shared dependency path run concurrently.

When to use workflow mode

  • You need a deterministic, auditable pipeline.
  • You are building a REST API, bot, or file-processing service.
  • You want full control over which resources run and in what order.
  • You need validation, early-exit, and explicit error handling.

Comparison with agent mode

Workflow mode (kdeps run)Agent mode (kdeps serve)
ExecutionDAG, deterministicLLM loop, tool-driven
Entry pointmetadata.targetActionIdUser prompt
ResourcesDeclared orderRun as part of a whole-workflow tool
SessionSingle executionInteractive REPL

Minimal example

workflow.yaml:

yaml
# workflow.yaml
apiVersion: kdeps.io/v1
kind: Workflow

metadata:
  name: chat-api
  version: "1.0.0"
  targetActionId: response

settings:
  apiServer:
    hostIp: "127.0.0.1"
    portNum: 16395
    routes:
      - path: /api/v1/chat
        methods: [POST]

resources/llm.yaml:

yaml
# resources/llm.yaml
actionId: llm
validations:
  check:
    - get('q') != ''
  error:
    code: 400
    message: "'q' is required"
chat:
  model: llama3.2:1b
  role: user
  prompt: "{{ get('q') }}"
  timeout: 60s

resources/response.yaml:

yaml
# resources/response.yaml
actionId: response
requires: [llm]
apiResponse:
  success: true
  response:
    answer: get('llm')

Run:

bash
kdeps run workflow.yaml

curl -X POST http://localhost:16395/api/v1/chat \
  -H "Content-Type: application/json" \
  -d '{"q": "What is entropy?"}'

Input sources

Workflow mode supports three input sources configured in settings:

yaml
# API (default) - starts an HTTP server
settings:
  apiServer:
    portNum: 16395
    routes:
      - path: /api/v1/chat
        methods: [POST]

# Bot - connects to a chat platform; blocks until SIGINT
settings:
  input:
    sources: [bot]
    bot:
      executionType: polling   # polling = persistent; stateless = one message then exit
      discord:
        botToken: "${DISCORD_BOT_TOKEN}"

# File - reads one file from disk or stdin, runs once, exits
settings:
  input:
    sources: [file]
    file:
      path: /data/input.txt

See Input Sources for full configuration.

See Also

Released under the Apache 2.0 License.