@@ -49,6 +49,7 @@ class ResearchEvent(Event):
49
49
50
50
class WriteEvent (Event ):
51
51
input : str
52
+ is_good : bool = False
52
53
53
54
54
55
class ReviewEvent (Event ):
@@ -82,7 +83,7 @@ async def research(
82
83
@step ()
83
84
async def write (
84
85
self , ctx : Context , ev : WriteEvent , writer : FunctionCallingAgent
85
- ) -> ReviewEvent | StopEvent :
86
+ ) -> ReviewEvent | PublishEvent :
86
87
MAX_ATTEMPTS = 2
87
88
ctx .data ["attempts" ] = ctx .data .get ("attempts" , 0 ) + 1
88
89
too_many_attempts = ctx .data ["attempts" ] > MAX_ATTEMPTS
@@ -93,20 +94,19 @@ async def write(
93
94
msg = f"Too many attempts ({ MAX_ATTEMPTS } ) to write the blog post. Proceeding with the current version." ,
94
95
)
95
96
)
96
- if too_many_attempts :
97
+ if ev . is_good or too_many_attempts :
97
98
# 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' ] } ```" ,
100
101
)
101
- return StopEvent (result = result )
102
102
result : AgentRunResult = await self .run_agent (ctx , writer , ev .input )
103
103
ctx .data ["result" ] = result
104
104
return ReviewEvent (input = result .response .message .content )
105
105
106
106
@step ()
107
107
async def review (
108
108
self , ctx : Context , ev : ReviewEvent , reviewer : FunctionCallingAgent
109
- ) -> WriteEvent | PublishEvent :
109
+ ) -> WriteEvent :
110
110
result : AgentRunResult = await self .run_agent (ctx , reviewer , ev .input )
111
111
review = result .response .message .content
112
112
old_content = ctx .data ["result" ].response .message .content
@@ -118,9 +118,9 @@ async def review(
118
118
)
119
119
)
120
120
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 ,
124
124
)
125
125
else :
126
126
return WriteEvent (
0 commit comments