Skip to content

V1 Workflows en

weego edited this page Nov 15, 2026 · 1 revision

Workflows and Multiple Agents

简体中文 | English

Applies to v1.0.0. Do not introduce durable scheduling for a simple role handoff, or treat unconstrained handoffs as a verified workflow.

Need Entry point Completion condition
Route a conversation to an Agent with another role LightSwarm The target Agent replies. Hooks and policies control handoff.
Run known steps with known dependencies LightFlow Dependencies, checkpoints, approvals, and per-step state can be inspected.
Add tasks during execution and verify artifacts LightDAG Only an application-owned Verifier can accept and publish candidate artifacts.
Reconnect to a single long-running task that need not be a DAG ExecutionService The backend confirms that execution ended; the application validates the result separately. See Durable Tasks.

LightFlow: fixed dependencies and human review

The steps below use local Python objects. Replace them with configured LightAgent instances in a real application.

from tempfile import TemporaryDirectory

from LightAgent import ApprovalDecision, JsonLightFlowStore, LightFlow

class LocalWriter:
    def run(self, query, **kwargs):
        return "草稿:" + query

with TemporaryDirectory() as directory:
    def create_flow():
        return (
            LightFlow(store=JsonLightFlowStore(directory))
            .step("draft", agent=LocalWriter())
            .step("review", agent=LocalWriter(), depends_on=["draft"], requires_approval=True)
        )

    flow = create_flow()
    waiting = flow.run("描述验收计划", run_id="report-001")
    assert any(step.approval_request_id for step in waiting.steps)
    reconnected = create_flow()
    reconnected.approve("report-001", "review", ApprovalDecision.approve(reviewer_id="editor"))
    done = reconnected.resume("report-001")
    assert done.success
    print([(step.name, step.status) for step in done.steps])

Use depends_on to declare upstream steps and a step's query callback to build bounded downstream inputs. Retrying cannot repair a cycle or unknown dependency. LightFlow supports per-step retry, timeout, fallback, conditional skip, cancellation, tracing, and persisted checkpoints. Inspect runs with get_run() and list_runs(). rerun_step(run_id, step_name) reruns that step and its dependents. Reusing an explicit completed run ID returns the stored checkpoint without invoking Agents again. Approval can allow, reject, edit, or supply a result. Authenticate reviewers and prevent cross-run reuse. The JSON store is for lightweight local use, not distributed queuing. See the LightFlow Reference for arguments and statuses.

LightSwarm: routing and handoff

Using the model configuration in Getting Started, create a front-desk Agent and a support Agent. The example assumes frontdesk and support have distinct name, role, and instructions settings and serve the same request tenant:

from LightAgent import LightSwarm

swarm = LightSwarm()
swarm.register_agent(frontdesk, support)
print(swarm.run(agent=frontdesk, query="如何导出应用的运行日志?", stream=False))

The model selects the intended role; it need not make the same choice every time. Use on_handoff to review handoffs, restrict targets, and preserve the parent trace. Delegation must not override permission or memory boundaries. The complete multi-agent example and the failure map cover registration, role descriptions, and transport behavior. Use LightFlow rather than free handoff when execution order must be fixed.

LightDAG: dynamic decomposition, verification, and repair

From a v1.0.0 checkout, run this complete offline example. It splits a root task into two children, repairs a task after a failed verification, and integrates the verified artifacts:

python example/14.dynamic_dag.py

To integrate it in an application:

  1. Construct LightDAG with an explicit SqliteTaskGraphStore, LocalArtifactStore, resource limits, and a trusted CallableVerifier.
  2. Register a Worker. Return TaskOutcome.candidate(), decompose(), or blocked(), not an arbitrary string as proof of completion.
  3. In TaskSpec, define the goal, acceptance contract, Worker, and Verifier. Pass tenant, project, and permissions from a trusted SecurityContext to create_run().
  4. A decomposition proposal carries a graph revision. The runtime checks dependencies, cycles, quotas, leases, and the revision before updating the graph. The parent integrates only after its dependencies publish verified artifacts.
  5. Use list_tasks() to inspect state. Only an authorized host should pause, cancel, resume, clear a blocker, or replace an unfinished task. Verified artifacts are read by digest and published status. Create a new run to change an already-verified contract.

See the LightDAG Reference for another model-free example and runtime details. Workers can call explicit backends, but the Verifier must check the domain requirements independently of the model's success claim. Scheduling is single-host; leases and fencing reject stale results, but cannot undo external side effects.

Clone this wiki locally