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

@@ -0,0 +1,43 @@
import asyncio
from crewai.flow.flow import Flow, listen, start
from pydantic import BaseModel
class ExampleState(BaseModel):
counter: int = 0
message: str = ""
class StructuredExampleFlow(Flow[ExampleState]):
initial_state = ExampleState
@start()
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"
print(f"State after start_method: {self.state}")
return "Start result"
@listen(start_method)
async def second_method(self, result):
print(f"Second method, received: {result}")
print(f"State before increment: {self.state}")
self.state.counter += 1
self.state.message += " - updated"
print(f"State after second_method: {self.state}")
return "Second result"
@listen(start_method or second_method)
async def logger(self):
print("OR METHOD RUNNING")
print("CURRENT STATE FROM OR: ", self.state)
async def main():
flow = StructuredExampleFlow()
await flow.run()
asyncio.run(main())