Skip to content

Commit 5e52b61

Browse files
committed
keep old workflow
1 parent f026796 commit 5e52b61

File tree

1 file changed

+9
-9
lines changed
  • templates/types/multiagent/fastapi/app/examples

1 file changed

+9
-9
lines changed

templates/types/multiagent/fastapi/app/examples/workflow.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ResearchEvent(Event):
4949

5050
class WriteEvent(Event):
5151
input: str
52+
is_good: bool = False
5253

5354

5455
class ReviewEvent(Event):
@@ -82,7 +83,7 @@ async def research(
8283
@step()
8384
async def write(
8485
self, ctx: Context, ev: WriteEvent, writer: FunctionCallingAgent
85-
) -> ReviewEvent | StopEvent:
86+
) -> ReviewEvent | PublishEvent:
8687
MAX_ATTEMPTS = 2
8788
ctx.data["attempts"] = ctx.data.get("attempts", 0) + 1
8889
too_many_attempts = ctx.data["attempts"] > MAX_ATTEMPTS
@@ -93,20 +94,19 @@ async def write(
9394
msg=f"Too many attempts ({MAX_ATTEMPTS}) to write the blog post. Proceeding with the current version.",
9495
)
9596
)
96-
if too_many_attempts:
97+
if ev.is_good or too_many_attempts:
9798
# too many attempts or the blog post is good - stream final response if requested
98-
result = await self.run_agent(
99-
ctx, writer, ev.input, streaming=ctx.data["streaming"]
99+
return PublishEvent(
100+
input=f"Please publish this content: ```{ev.input}```. The user request was: ```{ctx.data['user_input']}```",
100101
)
101-
return StopEvent(result=result)
102102
result: AgentRunResult = await self.run_agent(ctx, writer, ev.input)
103103
ctx.data["result"] = result
104104
return ReviewEvent(input=result.response.message.content)
105105

106106
@step()
107107
async def review(
108108
self, ctx: Context, ev: ReviewEvent, reviewer: FunctionCallingAgent
109-
) -> WriteEvent | PublishEvent:
109+
) -> WriteEvent:
110110
result: AgentRunResult = await self.run_agent(ctx, reviewer, ev.input)
111111
review = result.response.message.content
112112
old_content = ctx.data["result"].response.message.content
@@ -118,9 +118,9 @@ async def review(
118118
)
119119
)
120120
if post_is_good:
121-
user_input = ctx.data["user_input"]
122-
return PublishEvent(
123-
input=f"Please publish this content: ```{old_content}```. The user request was: ```{user_input}```",
121+
return WriteEvent(
122+
input=f"You're blog post is ready for publication. Please respond with just the blog post. Blog post: ```{old_content}```",
123+
is_good=True,
124124
)
125125
else:
126126
return WriteEvent(

0 commit comments

Comments
 (0)