mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-23 23:28:15 +00:00
WIP. Working on adding and & or to flows. In the middle of setting up template for flow as well
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import asyncio
|
||||
|
||||
from crewai.flow.flow import Flow, listen, start
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -11,7 +13,7 @@ class StructuredExampleFlow(Flow[ExampleState]):
|
||||
initial_state = ExampleState
|
||||
|
||||
@start()
|
||||
def start_method(self):
|
||||
async def start_method(self):
|
||||
print("Starting the structured flow")
|
||||
print(f"State in start_method: {self.state}")
|
||||
self.state.message = "Hello from structured flow"
|
||||
@@ -19,7 +21,7 @@ class StructuredExampleFlow(Flow[ExampleState]):
|
||||
return "Start result"
|
||||
|
||||
@listen(start_method)
|
||||
def second_method(self, result):
|
||||
async def second_method(self, result):
|
||||
print(f"Second method, received: {result}")
|
||||
print(f"State before increment: {self.state}")
|
||||
self.state.counter += 1
|
||||
@@ -27,7 +29,19 @@ class StructuredExampleFlow(Flow[ExampleState]):
|
||||
print(f"State after second_method: {self.state}")
|
||||
return "Second result"
|
||||
|
||||
@listen(start_method)
|
||||
async def third_method(self, result):
|
||||
print(f"Third method, received: {result}")
|
||||
print(f"State before increment: {self.state}")
|
||||
self.state.counter += 1
|
||||
self.state.message += " - updated"
|
||||
print(f"State after third_method: {self.state}")
|
||||
return "Third result"
|
||||
|
||||
# Instantiate and run the flow
|
||||
structured_flow = StructuredExampleFlow()
|
||||
structured_flow.run()
|
||||
|
||||
async def main():
|
||||
flow = StructuredExampleFlow()
|
||||
await flow.run()
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
Reference in New Issue
Block a user