-
|
Shouldn't I be able to create a workflow from the json output generated by My sample code is producing the following error: Here is the code I'm using: async def main():
"""Build and run a simple 2-step workflow using the fluent builder API."""
upper_case = UpperCase(id="upper_case_executor")
# Build the workflow using a fluent pattern:
# 1) add_edge(from_node, to_node) defines a directed edge upper_case -> reverse_text
# 2) set_start_executor(node) declares the entry point
# 3) build() finalizes and returns an immutable Workflow object
workflow = WorkflowBuilder().add_edge(upper_case, reverse_text).set_start_executor(upper_case).build()
wf_json = workflow.to_json()
# Run the workflow by sending the initial message to the start node.
# The run(...) call returns an event collection; its get_outputs() method
# retrieves the outputs yielded by any terminal nodes.
events = await workflow.run("hello world")
print(events.get_outputs())
# Summarize the final run state (e.g., IDLE)
print("Workflow result:", events.get_final_state())
workflow2 = Workflow.from_json(wf_json)
events2 = await workflow2.run("hello json")
print("Workflow2 result:", events2.get_final_state())
"""
Sample Output:
['DLROW OLLEH']
Final state: WorkflowRunState.IDLE
""" |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi @pjirsa, The Why it fails:
Alternatives:
An improvement on our side: the inherited |
Beta Was this translation helpful? Give feedback.
Hi @pjirsa,
The
to_json()andfrom_json()methods onWorkfloware not designed as a public serialization API for workflow persistence.Why it fails:
to_json()serializes the workflow's structural definition (executors, edges, start node) for observability/tracing purposes. Thefrom_json()is inherited fromDictConvertiblewhich does a naivecls(**data), butWorkflow.__init__requires live Python objects (Executor,RunnerContext) that cannot be round-tripped through JSON.Alternatives: