@@ -148,6 +148,7 @@ def run(self, instruction, max_iterations=10):
148
148
:return: AgentOutput object.
149
149
:rtype: AgentOutput
150
150
"""
151
+ self .intermediate_steps .clear ()
151
152
logging .info (f"Running { self .name + ':' + self .version } with instruction: { instruction } " )
152
153
total_cost = 0.0
153
154
total_token = 0
@@ -158,8 +159,8 @@ def run(self, instruction, max_iterations=10):
158
159
logging .info (f"Prompt: { prompt } " )
159
160
response = self .llm .completion (prompt , stop = ["Observation:" ])
160
161
if response .state == "error" :
161
- print ("Planner failed to retrieve response from LLM" )
162
- raise ValueError ("Planner failed to retrieve response from LLM" )
162
+ print ("Failed to retrieve response from LLM" )
163
+ raise ValueError ("Failed to retrieve response from LLM" )
163
164
164
165
logging .info (f"Response: { response .content } " )
165
166
total_cost += calculate_cost (self .llm .model_name , response .prompt_token ,
@@ -180,7 +181,7 @@ def run(self, instruction, max_iterations=10):
180
181
self .intermediate_steps [- 1 ].append (result )
181
182
return AgentOutput (output = response .content , cost = total_cost , token_usage = total_token )
182
183
183
- def stream (self , instruction : Optional [str ] = None , output : Optional [BaseOutput ] = None ):
184
+ def stream (self , instruction : Optional [str ] = None , output : Optional [BaseOutput ] = None , max_iterations : int = 10 ):
184
185
"""
185
186
Stream output the agent with the given instruction.
186
187
@@ -197,7 +198,7 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
197
198
if output is None :
198
199
output = BaseOutput ()
199
200
output .thinking (self .name )
200
- for _ in range (10 ):
201
+ for _ in range (max_iterations ):
201
202
202
203
prompt = self ._compose_prompt (instruction )
203
204
logging .info (f"Prompt: { prompt } " )
@@ -208,8 +209,6 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
208
209
for i in response :
209
210
content += i .content
210
211
output .panel_print (i .content , self .name , True )
211
-
212
- # print(i.content)
213
212
output .clear ()
214
213
215
214
logging .info (f"Response: { content } " )
0 commit comments