Skip to main content
Version: 1.0.0

Add Touba to Python orchestration

Call a Touba strategy from a LangGraph node or LangChain tool while keeping execution authority in the Core. Install the Python SDK, then the optional, tested framework dependencies (MIT licenses):

touba sdk install python
source .venv/bin/activate
python -m pip install langgraph==1.2.16 langchain-core==1.6.12

On Windows use .venv\Scripts\Activate.ps1 instead of source. The Touba SDK installs offline; downloading the optional frameworks requires network access.

program.tb
module integration
strategy Review
takes value as Text
gives Text
do
human.approve
with context as value
into approval
give value
orchestration.py
from typing import TypedDict
from langchain_core.tools import tool
from langgraph.graph import StateGraph, START, END
from touba_sdk import ToubaEngine

engine = ToubaEngine(project_root=".")

@tool
def review_invoice(value: str) -> dict:
"""Submit an invoice for review; a pause is not an approval."""
run = engine.run(source="program.tb", inputs={"value": value})
return {"status": run.status, "reason": run.reason, "result": run.result}

class State(TypedDict, total=False):
value: str
status: str
reason: str
result: str | None

def review_node(state: State) -> dict:
return review_invoice.invoke({"value": state["value"]})

builder = StateGraph(State)
builder.add_node("review", review_node)
builder.add_edge(START, "review")
builder.add_edge("review", END)
result = builder.compile().invoke({"value": "Invoice 42"})
assert result["reason"] == "human_approval_pending"
assert result["result"] is None

Run python orchestration.py. No model or paid service is needed. Direct review_invoice.invoke({"value": "Invoice 42"}) calls use the same governed entry. Both paths return stopped / human_approval_pending, not approval invented by the framework.

For a business workflow, add source capabilities, required roles and limits. Configure manifest, human_approval_host, effect_journal and a unique human_checkpoint_out per operation in trusted host code. A real decision resumes that checkpoint with human_resume_checkpoint and human_decisions; it does not rerun the node from the beginning. Store the trace and its run_id with your application operation ID.

The model supplies typed business input, not manifest, file paths or identity adapters. Pause the business flow on a pending outcome. Consume a completed result only after checking status == "success" and reason == "completed".

Touba governs this call, not the framework's other actions. A second fresh call is a new operation. Do not automatically retry effectful nodes without business idempotency. Explicit resumes retain the same journal and do not replay applied effects. See the approval tutorial.