WIP. Working on adding and & or to flows. In the middle of setting up template for flow as well

This commit is contained in:
Brandon Hancock
2024-09-11 16:26:02 -04:00
parent 3a266d6b40
commit a028566bd6
22 changed files with 627 additions and 32 deletions

View File

@@ -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())