@@ -16,6 +16,9 @@ public InstructService(IServiceProvider services, ILogger<InstructService> logge
1616
1717 public async Task < InstructResult > Execute ( string agentId , RoleDialogModel message , string ? templateName = null )
1818 {
19+ var agentService = _services . GetRequiredService < IAgentService > ( ) ;
20+ Agent agent = await agentService . LoadAgent ( agentId ) ;
21+
1922 // Trigger before completion hooks
2023 var hooks = _services . GetServices < IInstructHook > ( ) ;
2124 foreach ( var hook in hooks )
@@ -25,7 +28,7 @@ public async Task<InstructResult> Execute(string agentId, RoleDialogModel messag
2528 continue ;
2629 }
2730
28- await hook . BeforeCompletion ( message ) ;
31+ await hook . BeforeCompletion ( agent , message ) ;
2932
3033 // Interrupted by hook
3134 if ( message . StopCompletion )
@@ -39,9 +42,7 @@ public async Task<InstructResult> Execute(string agentId, RoleDialogModel messag
3942 }
4043
4144 // Render prompt
42- var agentService = _services . GetRequiredService < IAgentService > ( ) ;
43- Agent agent = await agentService . LoadAgent ( agentId ) ;
44- var prompt = string . IsNullOrEmpty ( templateName ) ?
45+ var prompt = string . IsNullOrEmpty ( templateName ) ?
4546 agentService . RenderedInstruction ( agent ) :
4647 agentService . RenderedTemplate ( agent , templateName ) ;
4748
@@ -60,7 +61,7 @@ public async Task<InstructResult> Execute(string agentId, RoleDialogModel messag
6061 continue ;
6162 }
6263
63- await hook . AfterCompletion ( response ) ;
64+ await hook . AfterCompletion ( agent , response ) ;
6465 }
6566
6667 return response ;
0 commit comments