i can now Use our system programmatically
This commit is contained in:
@@ -7,6 +7,7 @@ from .model import (
|
||||
NodeDef,
|
||||
NodeResult,
|
||||
NodeUse,
|
||||
SchemaRef,
|
||||
StateField,
|
||||
StateSchema,
|
||||
Workflow,
|
||||
@@ -46,6 +47,7 @@ __all__ = [
|
||||
"NodeDef",
|
||||
"NodeResult",
|
||||
"NodeUse",
|
||||
"SchemaRef",
|
||||
"StateField",
|
||||
"StateSchema",
|
||||
"NodeHandler",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from typing import cast
|
||||
|
||||
from .model import Workflow
|
||||
from .run_state import RuntimeContext
|
||||
@@ -233,7 +234,8 @@ def summarize_documents(
|
||||
def combine_summaries(
|
||||
payload: dict[str, object], ctx: RuntimeContext
|
||||
) -> dict[str, object]:
|
||||
item_summaries = payload["item_summaries"]
|
||||
raw_item_summaries = cast(list[object], payload["item_summaries"])
|
||||
item_summaries = [str(item) for item in raw_item_summaries]
|
||||
return {
|
||||
"outcome": "ok",
|
||||
"output": {"summary": " | ".join(item_summaries)},
|
||||
|
||||
+6
-4
@@ -31,8 +31,8 @@ class NodeDef(BaseModel):
|
||||
input_schema: SchemaRef
|
||||
output_schema: SchemaRef
|
||||
outcomes: list[str] = Field(min_length=1)
|
||||
retry: int | None = Field(None, ge=0)
|
||||
timeout_seconds: int | None = Field(None, gt=0)
|
||||
retry: int | None = Field(default=None, ge=0)
|
||||
timeout_seconds: int | None = Field(default=None, gt=0)
|
||||
|
||||
|
||||
class NodeUse(BaseModel):
|
||||
@@ -42,8 +42,8 @@ class NodeUse(BaseModel):
|
||||
desc: str | None = None
|
||||
in_map: dict[str, str] = Field(default_factory=dict)
|
||||
out_map: dict[str, str] = Field(default_factory=dict)
|
||||
retry: int | None = Field(None, ge=0)
|
||||
timeout_seconds: int | None = Field(None, gt=0)
|
||||
retry: int | None = Field(default=None, ge=0)
|
||||
timeout_seconds: int | None = Field(default=None, gt=0)
|
||||
|
||||
|
||||
class PathOperand(BaseModel):
|
||||
@@ -91,6 +91,8 @@ class ConditionNode(BaseModel):
|
||||
|
||||
|
||||
class ForeachNode(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
id: str
|
||||
type: Literal["foreach"]
|
||||
over: str
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from collections.abc import Callable, Mapping
|
||||
from typing import Any
|
||||
|
||||
from .conditions import safe_resolve_path
|
||||
@@ -19,7 +19,7 @@ def execute_node_use(
|
||||
run: RunState,
|
||||
node: NodeUse,
|
||||
node_def: NodeDef,
|
||||
registry: dict[str, NodeHandler],
|
||||
registry: Mapping[str, NodeHandler],
|
||||
) -> StepExecutionResult:
|
||||
handler = registry.get(node.node)
|
||||
if handler is None:
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from .errors import WorkflowExecutionError
|
||||
@@ -43,7 +44,7 @@ __all__ = [
|
||||
def execute_workflow(
|
||||
workflow: Workflow,
|
||||
workflow_input: dict[str, Any],
|
||||
registry: dict[str, NodeHandler],
|
||||
registry: Mapping[str, NodeHandler],
|
||||
) -> RunState:
|
||||
run = create_run_state(workflow, workflow_input)
|
||||
|
||||
@@ -62,7 +63,7 @@ def execute_workflow(
|
||||
def resume_workflow(
|
||||
workflow: Workflow,
|
||||
run: RunState,
|
||||
registry: dict[str, NodeHandler],
|
||||
registry: Mapping[str, NodeHandler],
|
||||
*,
|
||||
resume_payload: dict[str, Any] | None = None,
|
||||
resume_outcome: str = "submitted",
|
||||
@@ -121,7 +122,7 @@ def resume_workflow(
|
||||
def step_workflow(
|
||||
workflow: Workflow,
|
||||
run: RunState,
|
||||
registry: dict[str, NodeHandler],
|
||||
registry: Mapping[str, NodeHandler],
|
||||
*,
|
||||
index: WorkflowIndex | None = None,
|
||||
) -> RunState:
|
||||
|
||||
@@ -4,7 +4,7 @@ from .conditions import eval_condition
|
||||
from .flow_ops import append_trace
|
||||
from .frame_ops import frame_context_values
|
||||
from .interrupt_ops import build_interrupt_request
|
||||
from .model import ConditionNode, InterruptNode, JoinNode
|
||||
from .model import ConditionNode, InterruptNode
|
||||
from .run_state import FrameStatus, RunState, RunStatus, StepExecutionResult
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -390,7 +390,7 @@ def _declared_outcomes_for_step(step: Step, node_defs: dict[str, NodeDef]) -> se
|
||||
return {"loop", "done"}
|
||||
if step.type == "join":
|
||||
return {"done"}
|
||||
if step.type == "interrupt":
|
||||
if isinstance(step, InterruptNode):
|
||||
return set(step.outcomes)
|
||||
return set()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user