Handbook
101-02 — Run a governed task
A one-shot script that runs pw_chunk_classify via TaskRunner using fake_chat—no network.
Updated
What you will build
A one-shot script that runs pw_chunk_classify via TaskRunner using fake_chat—no network.
Prerequisites
- 101-01 completed (venv + install).
Files you will touch
None required; optional comparison with examples/basic/run_fake_task.py.
Step 1 — Same snippet as maintainers use
From repo root, venv active:
PYTHONPATH=src python3 - <<'PY'
import json
from forge_lcdl.env import LlmEnvProfile
from forge_lcdl.runner import TaskRunner
from forge_lcdl.types import ChatResult
payload = {
"chunk_results": [
{
"chunk_id": "c1",
"is_question_block": True,
"confidence": 0.9,
"reason": "toy fake response",
}
]
}
def fake_chat(messages, **kwargs):
return ChatResult(True, json.dumps(payload))
profile = LlmEnvProfile(
kind="certificator",
base_url="http://localhost",
api_key="",
model="fake",
timeout_sec=30,
ngrok_bypass=False,
prefer_json_object_mode=True,
)
runner = TaskRunner(chat=fake_chat)
r = runner.run(
"pw_chunk_classify",
"v1",
{
"url": "https://example.com",
"chunks": [{"chunk_id": "c1", "text_snippet": "Sample?"}],
},
profile=profile,
)
print(r)
PY
Step 2 — Or run the packaged example
PYTHONPATH=src python3 examples/basic/run_fake_task.py
Expected output
- Printed line contains
Ok(and achunkskey insidevalue(the task mergeschunk_resultsfrom the model-shaped JSON onto input chunks). See basic task runner example.
Common failures
| Symptom | Fix |
|---|---|
unknown task |
Check task_id spelling and v1 folder exists under contracts/ |
Parse Err |
Ensure fake_chat returns valid JSON string |
Verify
PYTHONPATH=src python3 examples/basic/run_fake_task.py | grep -q "chunks" && echo OK
What changed
You understand injectable chat, ChatResult, and TaskRunner.run boundaries.
Concepts
TaskRunner— holds transport for tests or production adapters.- Contract path —
src/forge_lcdl/contracts/pw_chunk_classify/v1/(next lesson).