inline-resources
workflowv1.0.0Inline resources: LLM, HTTP, Exec, SQL, and Python running before/after main resource
Install
Then run locally:
Configure LLM provider in ~/.kdeps/config.yaml (created automatically on first run).
README
Inline Resources Example
This example demonstrates the inline resources feature in KDeps, which allows you to configure multiple LLM, HTTP, Exec, SQL, and Python resources to run before or after the main resource execution.
Overview
Inline resources provide a way to:
- Execute preparatory tasks before the main resource runs
- Perform cleanup or post-processing tasks after the main resource completes
- Keep related operations organized within a single resource definition
- Avoid creating separate resource definitions for small auxiliary tasks
Features Demonstrated
Before Inline Resources
Resources configured in the before section execute before the main resource:
- HTTP call to fetch configuration
- Shell command to prepare environment
Main Resource
The primary resource that performs the core business logic:
- LLM chat processing with Ollama
After Inline Resources
Resources configured in the after section execute after the main resource:
- SQL query to store results
- Python script for post-processing
- HTTP call to send notifications
Execution Order
The execution order for a resource with inline resources is:
- ExprBefore expressions (if any)
- Before inline resources (executed sequentially)
- Main resource (chat, httpClient, sql, python, or exec)
- After inline resources (executed sequentially)
- Expr/ExprAfter expressions (if any)
- APIResponse formatting (if configured)
Configuration
Inline Resource Structure
run:
# Inline resources to run before main resource
before:
- httpClient:
method: GET
url: "https://api.example.com/data"
- exec:
command: "echo 'Preparing...'"
# Main resource
chat:
model: llama3.2:1b
prompt: "Process this"
# Inline resources to run after main resource
after:
- sql:
connection: "sqlite3://./db.sqlite"
query: "INSERT INTO logs VALUES (?)"
- python:
script: "print('Done')"
Supported Inline Resource Types
Each inline resource can be one of:
- chat: LLM interaction
- httpClient: HTTP requests
- sql: Database queries
- python: Python script execution
- exec: Shell command execution
Error Handling
If an inline resource fails:
- Execution stops immediately
- The error is propagated up
- Subsequent inline resources and main resource are not executed
- Resource-level
onErrorconfiguration can be used to handle errors
Running the Example
-
Start Ollama:
ollama pull llama3.2:1b -
Create the SQLite database:
sqlite3 results.db "CREATE TABLE IF NOT EXISTS results (data TEXT, timestamp TEXT)" -
Run the workflow:
kdeps run workflow.yaml --input '{"data": "test data"}'
Use Cases
Inline resources are useful for:
- Data Enrichment: Fetch additional data before processing
- Environment Setup: Prepare files or environment variables
- Logging and Auditing: Record operations in a database
- Notifications: Send alerts or updates after completion
- Cleanup: Remove temporary files or reset state
- Caching: Store results for future use
Best Practices
- Keep inline resources focused: Each should perform a single, well-defined task
- Handle errors appropriately: Use
onErrorconfiguration when needed - Consider timeouts: Set appropriate timeouts for each inline resource
- Use expressions: Access context data with
{{get('variable')}} - Order matters: Inline resources execute sequentially in the order defined
Comparison with Separate Resources
Without Inline Resources (Traditional Approach)
# workflow.yaml with 4 separate resource files
resources:
- fetch-config.yaml # Before
- prepare-env.yaml # Before
- main-processing.yaml # Main
- store-results.yaml # After
- send-notification.yaml # After
With Inline Resources (New Approach)
# Single resource file with inline resources
run:
before:
- httpClient: ... # Fetch config
- exec: ... # Prepare env
chat: ... # Main processing
after:
- sql: ... # Store results
- httpClient: ... # Send notification
Benefits:
- Fewer files to manage
- Related operations stay together
- Clearer execution flow
- Reduced boilerplate
Advanced Features
Combining with ExprBefore/ExprAfter
You can combine inline resources with expression blocks:
run:
exprBefore:
- set('timestamp', now())
before:
- httpClient: ...
chat: ...
after:
- sql: ...
expr:
- set('duration', now() - get('timestamp'))
Accessing Results
Inline resource results are stored in the execution context and can be accessed by subsequent resources or expressions.
Notes
- Inline resources are optional - you can use
before,after, both, or neither - A resource can have inline resources without a main resource type
- Inline resources respect the resource's error handling configuration
- Each inline resource has access to the full execution context
Versions
| Version | Published | Status |
|---|---|---|
| 1.0.0 | 4/11/2026 | active |
Details
- Author
- kdeps
- License
- Apache-2.0
- Latest Version
- 1.0.0
- Published
- 4/11/2026