File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -1252,6 +1252,14 @@ async def _get_new_response(
1252
1252
model = cls ._get_model (agent , run_config )
1253
1253
model_settings = agent .model_settings .resolve (run_config .model_settings )
1254
1254
model_settings = RunImpl .maybe_reset_tool_choice (agent , tool_use_tracker , model_settings )
1255
+ # If the agent has hooks, we need to call them before and after the LLM call
1256
+ if agent .hooks :
1257
+ await agent .hooks .on_llm_start (
1258
+ context_wrapper ,
1259
+ agent ,
1260
+ system_prompt ,
1261
+ input
1262
+ )
1255
1263
1256
1264
new_response = await model .get_response (
1257
1265
system_instructions = filtered .instructions ,
@@ -1266,6 +1274,13 @@ async def _get_new_response(
1266
1274
previous_response_id = previous_response_id ,
1267
1275
prompt = prompt_config ,
1268
1276
)
1277
+ # If the agent has hooks, we need to call them after the LLM call
1278
+ if agent .hooks :
1279
+ await agent .hooks .on_llm_end (
1280
+ context_wrapper ,
1281
+ agent ,
1282
+ new_response
1283
+ )
1269
1284
1270
1285
context_wrapper .usage .add (new_response .usage )
1271
1286
You can’t perform that action at this time.
0 commit comments