chap-llama-index
Adapter between LlamaIndex Workflows and the CHAP Coordinator. When a workflow step pauses for human input, the human's decision -- approve, edit, or reject -- becomes a hash-linked, replayable CHAP audit entry.
decision CHAP envelope
-------- ---------------------------
approve decide.approve
override decide.override (proposed vs returned, as a diff)
reject decide.reject
The proposed output on the InputRequiredEvent is the artefact under
review; the human's HumanResponseEvent is the decision on it. An edit is
recorded as an RFC 6902 diff, so the chain captures what changed and why,
not just approved/rejected.
Install
pip install chap-llama-index
Depends on chap-coordinator>=0.2.9. LlamaIndex is optional: the
adapter reads events structurally, so the bridge and its tests work
without it installed. Install the extra to run a live workflow:
pip install "chap-llama-index[llama-index]"
Quick start
Workflows surface human-in-the-loop as events: a step returns an
InputRequiredEvent and waits; a second step consumes the matching
HumanResponseEvent. The driver that answers the pause is where both
events meet, so that is where the decision is recorded:
from workflows.events import InputRequiredEvent, HumanResponseEvent
from chap_coordinator import Coordinator
from chap_llama_index import ChapHitlBridge
bridge = ChapHitlBridge(
Coordinator(),
workspace="wsp_payments",
agent="agent:writer#v1",
reviewer="human:alice@example.org",
)
handler = workflow.run()
async for event in handler.stream_events():
if isinstance(event, InputRequiredEvent):
response = HumanResponseEvent(
response={"amount": 50, "to": "acct-9"}, # the edited output
decision="override",
user_name="human:sam@example.org",
rationale="over the desk limit; capped to 50",
tags=["limit-exceeded"],
)
bridge.record_decision(event, response, decision=response.get("decision"))
handler.ctx.send_event(response)
await handler
Decision is explicit
Workflows events are schemaless and carry no approve/edit/reject signal,
so decision is a required argument -- the adapter never guesses intent
from the response text. proposed, returned, rationale, tags,
intent_preserved, and approver default to fields read off the events
(event.get(...)) and can each be overridden per call:
bridge.record_decision(input_event, response_event, decision="approve")
intent_preserved defaults to true on an override (a refining edit);
set it false on the response for a substituting edit -- a different
decision, not a refinement.
Approver identity
CHAP has no ambient actor: the decider is whatever from the envelope
carries. The bridge uses its reviewer by default, but the
HumanResponseEvent's user_name (or an explicit approver=) overrides
it, and the adapter joins that approver -- with a participant type taken
from the URI scheme -- before recording. Each decision is its own task
whose review is addressed to that approver, so the record satisfies the
Coordinator's authorisation rules.
What you get in the audit chain
One paused step with an edit yields:
seq=3 task.create agent:writer#v1
seq=4 task.complete agent:writer#v1
seq=5 review.request agent:writer#v1 to=human:sam@example.org
seq=6 decide.override human:sam@example.org diff=[{op:replace, path:/amount, value:50}]
Every entry carries prev_hash, so the chain verifies externally or
anchors to a SCITT transparency service with the audit-scitt/1.0
profile.
Example
examples/01-approve-edit-reject.py drives one paused workflow through
approve, a refining edit, a substituting edit, and a reject against real
llama-index-workflows, and prints the resulting chain.
Compatibility
chap-coordinator0.2.9llama-index-workflows1.x–2.x (optional; verified against 2.22)- Python 3.10, 3.11, 3.12, 3.13
License
Apache 2.0. See LICENSE.
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 chap_llama_index-0.2.9.tar.gz.
File metadata
- Download URL: chap_llama_index-0.2.9.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
473e43b5b4e14e14b8e0d35516f95d3dd1adc452e91ae504f9aa8f9b5c6ebbbd
|
|
| MD5 |
b880862102365a41ba374aa98dc7943e
|
|
| BLAKE2b-256 |
a397676ffda5a2a40f1c11bdf05f690b5682a0cc8fd8030d98180cf52c0b9305
|
File details
Details for the file chap_llama_index-0.2.9-py3-none-any.whl.
File metadata
- Download URL: chap_llama_index-0.2.9-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
658bb9851c4a716cc2dfa331ea077181951a9847890b507d78bbb74f4eec3975
|
|
| MD5 |
81bd9fb82f2d3a131ef75d2c8684a1e6
|
|
| BLAKE2b-256 |
9f42e33e5caff3919c1fc7d0425b709f7ba2236fef44c4fe232d8b289dcbbfcd
|