Skip to content

Build a document summarizer: full text ​

This page has every step and detail. The overview is the short version.

Build a single-shot workflow that reads a document from a file. It sends the document to a local LLM and returns a structured JSON summary. It runs one time and stops. It has no server and no polling.

kdeps workflows usually run as an HTTP API. The file input source is the exception: the workflow reads one file, processes it, prints the result, and exits. This is the shape you want for a cron job, a CI step, or a kdeps run ... | jq one-liner.

Needs: A text file to summarize. Any .txt or .md file works.

Step 1: create the project ​

bash
mkdir -p doc-summarizer/resources
cd doc-summarizer

Step 2: configure the file input source ​

Create workflow.yaml:

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

metadata:
  name: doc-summarizer
  version: "1.0.0"
  targetActionId: response      # the resource whose output is returned

deploy:
  runtime:
    pythonVersion: "3.12"
  input:
    sources: [file]             # read one file, then exit
    file:
      path: ""                  # empty: supply the path at run time

With sources: [file] the workflow does not start a server. It resolves the file, runs the resource graph one time, and prints the response.

Step 3: expose the file content ​

Create resources/01-read.yaml:

yaml
# resources/01-read.yaml
actionId: readFile
name: Read file content

component:
  name: exec
  with:
    command: echo "file loaded"   # a no-op action; the real work is the response block
apiResponse:
  success: true
  response:
    path: "{{ input('filePath') }}"
    preview: "{{ input('fileContent') | truncate(200) }}"

input('fileContent') is the file's text. input('filePath') is its path. The file input source sets both values before a resource runs.

Step 4: summarize with an LLM ​

Create resources/02-summarize.yaml:

yaml
# resources/02-summarize.yaml
actionId: summarize
name: Summarize document
flow:
  requires: [readFile]            # run after readFile

chat:
  model:
    name: llama3.2:1b
  context:
    prompt: |
      You are a document analyst. Return a JSON object with exactly these keys:
        - "title": a short descriptive title (max 10 words)
        - "summary": a 2-3 sentence summary
        - "key_points": an array of 3-5 bullet-point strings

      Document:
      {{ input('fileContent') }}

      Return only valid JSON. No markdown, no explanation.

Step 5: return the structured result ​

Create resources/03-response.yaml:

yaml
# resources/03-response.yaml
actionId: response
name: Final response
flow:
  requires: [summarize]

apiResponse:
  success: true
  response:
    file: "{{ input('filePath') }}"
    analysis: "{{ get('summarize') }}"   # the LLM output

get('summarize') reads the output of the summarize resource by its actionId.

Step 6: validate and run ​

bash
kdeps validate .

Run it three ways - all equivalent:

bash
# 1. Pass the path with --file
kdeps run . --file ./notes.txt

# 2. Pipe content on stdin
cat notes.txt | kdeps run .

# 3. Use an environment variable
KDEPS_FILE_PATH=./notes.txt kdeps run .

All of these read the full file into memory as fileContent. The default maximum is 256 MiB (to change it, set KDEPS_FILE_INPUT_MAX_BYTES). If notes.txt is a large bulk-data file and not a note, this is important. See File source.

Output:

json
{
  "file": "./notes.txt",
  "analysis": {
    "title": "Quarterly planning notes",
    "summary": "The team agreed to ship the API in March and defer the mobile client.",
    "key_points": [
      "API ships in March",
      "Mobile client deferred to Q3",
      "Hire one backend engineer"
    ]
  }
}

Next steps ​

kdeps has the Apache 2.0 License.