Skip to content

Execution flow reference ​

This page lists every field and option. The overview shows what it does and a first example.

How kdeps resolves, orders, and runs resources in a workflow. kdeps run runs that DAG directly.

Overview ​

When you run kdeps run workflow.yaml or call POST /api/v1/run, the engine:

  1. Parses the workflow and builds a dependency graph from requires fields
  2. Detects cycles (fails fast if any exist)
  3. Finds the targetActionId resource and walks its transitive dependencies
  4. Topologically sorts resources so dependencies run before dependents. The order is the same on each run. kdeps uses the requires of a resource in the order that the resource lists them
  5. Executes resources in that order, running independent resources in parallel (see Independent resources)

Execution order ​

Request at targetActionId1. Build dependency grapheach resource = node; requires = edgesfails fast on cycles2. Walk transitive depsbackward from targetActionIdcollect only needed nodes3. Topological sortdeps always run before dependentsindependent resources run in parallel4. Execute each resourcea. before: blockb. skip - any true? skip silentlyc. check - all true? proceed, else faild. main action (chat, sql, http...)e. after: blockf. onError handler5. Terminal resourceapiResponse: formats outputJSON response returned

Dependency graph ​

How requires works ​

yaml
# workflow.yaml (conceptual)
metadata:
  targetActionId: respond            # engine walks backward from here

resources:
  - actionId: fetchData
    component:
      name: http_request
      with:
        url: https://api.example.com/data

  - actionId: analyzeData
    flow:
      requires: [fetchData]            # runs only after fetchData succeeds
    chat:
      context:
        prompt: "Analyze: {{ output('fetchData') }}"

  - actionId: respond
    flow:
      requires: [analyzeData]          # runs only after analyzeData succeeds
    apiResponse:
      response: "{{ output('analyzeData') }}"

Execution order: fetchData -> analyzeData -> respond

Transitive dependencies ​

The engine resolves the full transitive closure. If A requires B, and B requires C, then C runs before both:

yaml
# resources/example.yaml
- actionId: C
  component:
    name: exec
    with:
      command: echo "first"

- actionId: B
  requires: [C]
  chat:
    prompt: "Build on: {{ output('C') }}"

- actionId: A
  requires: [B]
  apiResponse:
    response: "{{ output('B') }}"

Execution order: C -> B -> A

Independent resources ​

Resources that do not depend on each other run in parallel, a maximum of 4 at the same time. A resource starts only after its requires finish:

yaml
# resources/example.yaml
- actionId: draft
  chat:
    prompt: "{{ get('q') }}"

- actionId: reviewScope                      # requires draft only: runs beside reviewRisks
  requires: [draft]
  chat:
    prompt: "Review the scope: {{ output('draft') }}"

- actionId: reviewRisks
  requires: [draft]
  chat:
    prompt: "Review the risks: {{ output('draft') }}"

- actionId: report
  requires: [reviewScope, reviewRisks]       # starts when both reviews finish
  chat:
    prompt: "Merge: {{ output('reviewScope') }} {{ output('reviewRisks') }}"

reviewScope and reviewRisks run at the same time. report waits for both.

The engine also orders resources that share a key without requires:

In a resource's YAMLEffect
get('k') after another resource's set('k')waits for the writer
set('k') after another resource's get('k') or set('k')keeps their order
output('id') or get('id') of another resourcewaits for that resource

A component: call runs beside others when the component is read-only in the permission policy (web_search, read_file, web_scraper, ...) and has no teardown:. Each call gets its own inputs and outputs. As a result, three web_search calls with different queries run at the same time. Other components (write_file, bash_exec, http_request, ...) run alone.

A resource whose effects the YAML can't show also runs alone, in its usual place: exec:, python:, items:, loop:, apiResponse:, chat with tools, header or param validations, a computed key (get(name)), 'item'/'loop' storage, session() and memory_* calls.

One cap covers workflow resources, subagents, judges, and loop tool calls. It is the parallel event:

yaml
# ~/.kdeps/events/parallel.yaml
name: parallel
items: 4          # tasks that run at once, in each batch
run: cap
disabled: false   # true runs everything one at a time

Cycle detection ​

The engine detects cycles during graph construction and fails fast with ErrCodeDependencyCycle:

yaml
# This creates a cycle and will fail:
- actionId: A
  requires: [B]

- actionId: B
  requires: [A]    # cycle: A -> B -> A

Skip vs check ​

Both run before the main action, but they behave differently:

skipcheck
LogicANY expression true triggers skipALL expressions must be true
On failureResource skipped silently, workflow continuesWorkflow stops, error returned
Error codeN/AConfigurable via validations.error.code
Use caseConditional execution, optional resourcesInput validation, preconditions

Skip example ​

yaml
# resources/example.yaml
validations:
  skip:
    - get('q') == ''          # if query is empty, skip this resource

Check example ​

yaml
# resources/example.yaml
validations:
  check:
    - get('apiKey') != nil    # must have API key
    - len(get('q')) <= 500    # query must be under 500 chars
  error:
    code: 400
    message: Missing API key or query too long

Loop execution ​

When a resource has a loop config, the engine runs the full resource cycle (before -> check -> action -> after) repeatedly:

loop startsloop.condition is true?before: blockcheck (every iteration)main actionafter: blockloop.every set?sleep(every)iteration >= maxIterations?loop endsyesnoyesnoyes, safety capno

See Loop for full details.

See also ​

kdeps has the Apache 2.0 License.