Implicit state machine middleware for LangChain v1 agents. Ordered task pipelines with per-task tool scoping, prompt injection, and composable validation.
Project description
langchain-task-steering
Implicit state-machine middleware for LangChain v1 agents. Define ordered task pipelines with per-task tool scoping, dynamic prompt injection, and composable validation — all as a drop-in AgentMiddleware.
Also available for TypeScript/JavaScript.
PENDING ──> IN_PROGRESS ──> COMPLETE
The model drives its own transitions by calling update_task_status. The middleware enforces ordering, scopes tools, injects the active task's instruction into the system prompt, and gates completion via pluggable validators.
When to use this
| Scenario | task-steering | LangGraph explicit workflows |
|---|---|---|
| Linear task pipeline (A then B then C) | Best fit | Verbose — one node + edges per task |
| Per-task tool scoping | Built-in | Manual — separate tool lists per node |
| Dynamic tasks from config / DB | Easy — tasks are data | Hard — graph is compiled at build time |
| Multiple workflows, agent-driven activation | Built-in — WorkflowSteeringMiddleware |
Manual — routing logic + subgraphs |
| Human-in-the-loop within tasks | Built-in — interrupt() in tools |
Built-in — interrupt() per node |
| Branching / parallel execution | Not supported | Built-in — edges + Send() |
| Complex orchestration with retries / cycles | Not supported | Built-in — conditional edges |
| Composition with other middleware | Native — it's an AgentMiddleware |
N/A — different abstraction |
Rule of thumb: If your tasks are sequential and tool-scoped, use task-steering. If you need agent-driven workflow selection with mixed freeform + structured work, use WorkflowSteeringMiddleware. If you need branching, parallelism, or per-node graph control, use explicit LangGraph workflows.
Install
pip install langchain-task-steering
For development:
git clone https://github.com/edvinhallvaxhiu/langchain-task-steering
cd langchain-task-steering/packages/python
pip install -e ".[dev]"
Requirements
- Python >= 3.10
langchain >= 1.0.0langgraph >= 0.4.0
Quick start
from langchain.agents import create_agent
from langchain.tools import tool
from langchain_task_steering import TaskSteeringMiddleware, Task
@tool
def add_items(items: list[str]) -> str:
"""Add items to the inventory."""
return f"Added {len(items)} items."
@tool
def categorize(categories: dict[str, list[str]]) -> str:
"""Assign items to categories."""
return f"Categorized into {len(categories)} groups."
pipeline = TaskSteeringMiddleware(
tasks=[
Task(
name="collect",
instruction="Collect all relevant items from the user's input.",
tools=[add_items],
),
Task(
name="categorize",
instruction="Organize the collected items into categories.",
tools=[categorize],
),
],
)
agent = create_agent(
model="anthropic:claude-sonnet-4-6",
middleware=[pipeline],
system_prompt="You are an inventory assistant.",
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "I have apples, bolts, and milk."}]}
)
The agent automatically receives an update_task_status tool and sees a task pipeline block in its system prompt. It must complete collect before starting categorize.
Workflow mode
For agents that handle mixed workloads — freeform conversation plus structured workflows — use WorkflowSteeringMiddleware:
from langchain_task_steering import Workflow, WorkflowSteeringMiddleware
middleware = WorkflowSteeringMiddleware(
workflows=[
Workflow(
name="onboarding",
description="Onboard a new user",
tasks=[
Task(name="collect_info", instruction="Collect user details.", tools=[...]),
Task(name="register", instruction="Register the account.", tools=[...]),
],
global_tools=[ask_user],
),
Workflow(
name="support",
description="Handle a support request",
tasks=[...],
),
],
)
The agent starts in freeform mode with its full toolset. When a request matches a workflow, it calls activate_workflow("onboarding") to enter the structured pipeline. Tool scoping, prompt injection, and task ordering kick in only while a workflow is active.
See Workflow Mode for full documentation.
Documentation
| Topic | Description |
|---|---|
| Task Mode | Task lifecycle, hooks, tool scoping, required tasks, configuration |
| Workflow Mode | Dynamic workflow activation, catalog, human-in-the-loop, deactivation |
| Task Middleware | TaskMiddleware hooks, validation, composition, persistent state |
| Summarization | Post-completion message compression (replace and summarize modes) |
| Skills | Task-scoped skills from SKILL.md files |
| Backend Passthrough | Whitelisting backend tools through the filter |
Development
cd packages/python
pip install -e ".[dev]"
pytest
pytest --cov=langchain_task_steering
License
MIT — see LICENSE.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_task_steering-0.1.6.tar.gz.
File metadata
- Download URL: langchain_task_steering-0.1.6.tar.gz
- Upload date:
- Size: 51.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41059e63cbeedac84ec00a375473e8bf82030fcf63b76752cb416e70054ad0f9
|
|
| MD5 |
ffe7e7964f2ff8b7ba5e7dea8cc7507b
|
|
| BLAKE2b-256 |
44b9aec01d2ee7c788d99d285740e2e1fda446ebe4e91460dbc6c8b513ccc313
|
Provenance
The following attestation bundles were made for langchain_task_steering-0.1.6.tar.gz:
Publisher:
publish.yml on edvinhallvaxhiu/langchain-task-steering
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_task_steering-0.1.6.tar.gz -
Subject digest:
41059e63cbeedac84ec00a375473e8bf82030fcf63b76752cb416e70054ad0f9 - Sigstore transparency entry: 1283164928
- Sigstore integration time:
-
Permalink:
edvinhallvaxhiu/langchain-task-steering@98d6a7d0545d54db9b6637caa92ebb6d3027692d -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/edvinhallvaxhiu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@98d6a7d0545d54db9b6637caa92ebb6d3027692d -
Trigger Event:
release
-
Statement type:
File details
Details for the file langchain_task_steering-0.1.6-py3-none-any.whl.
File metadata
- Download URL: langchain_task_steering-0.1.6-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a117e524458008047f78f862325a240135ddfc7a3f33068143621aa8aa56bdbc
|
|
| MD5 |
1e827e24f525ca58234e67980b6d3097
|
|
| BLAKE2b-256 |
ee6ca8cac4f69594706fd3314cbdfa09f41f58120e1f7bbe60161b7124b17d54
|
Provenance
The following attestation bundles were made for langchain_task_steering-0.1.6-py3-none-any.whl:
Publisher:
publish.yml on edvinhallvaxhiu/langchain-task-steering
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_task_steering-0.1.6-py3-none-any.whl -
Subject digest:
a117e524458008047f78f862325a240135ddfc7a3f33068143621aa8aa56bdbc - Sigstore transparency entry: 1283164935
- Sigstore integration time:
-
Permalink:
edvinhallvaxhiu/langchain-task-steering@98d6a7d0545d54db9b6637caa92ebb6d3027692d -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/edvinhallvaxhiu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@98d6a7d0545d54db9b6637caa92ebb6d3027692d -
Trigger Event:
release
-
Statement type: