22
33namespace NeuronAI ;
44
5+ use NeuronAI \Events \MessageSending ;
6+ use NeuronAI \Events \MessageSent ;
7+ use NeuronAI \Events \ToolCalled ;
8+ use NeuronAI \Events \ToolCalling ;
59use NeuronAI \Exceptions \InvalidMessageInstance ;
610use NeuronAI \Exceptions \MissingCallbackParameter ;
711use NeuronAI \Exceptions \ToolCallableNotSet ;
@@ -90,7 +94,12 @@ public function run(?Message $message = null): Message
9094 $ this ->resolveChatHistory ()->addMessage ($ message );
9195 }
9296
93- $ this ->notify ('message:sending ' , $ this ->resolveChatHistory ()->getLastMessage ());
97+ $ this ->notify (
98+ 'message:sending ' ,
99+ new MessageSending (
100+ $ this ->resolveChatHistory ()->getLastMessage ()
101+ )
102+ );
94103
95104 $ response = $ this ->provider ()
96105 ->systemPrompt ($ this ->instructions ())
@@ -99,17 +108,19 @@ public function run(?Message $message = null): Message
99108 $ this ->resolveChatHistory ()->toArray ()
100109 );
101110
102- $ this ->notify ('message:sent ' , [
103- 'response ' => $ response ,
104- 'message ' => $ this ->resolveChatHistory ()->getLastMessage ()
105- ]);
111+ $ this ->notify (
112+ 'message:sent ' ,
113+ new MessageSent (
114+ $ this ->resolveChatHistory ()->getLastMessage (),
115+ $ response
116+ )
117+ );
106118
107119 if ($ response instanceof ToolCallMessage) {
108- $ this ->notify ('tool:calling ' , $ response );
120+ $ this ->notify ('tool:calling ' , new ToolCalling ( $ response) );
109121 $ toolResult = $ response ->getTool ()->execute ($ response ->getInputs ());
110- $ this ->notify ('tool:called ' , $ toolResult );
122+ $ this ->notify ('tool:called ' , new ToolCalled ( $ response , $ toolResult) );
111123
112- // Execute the tool and submit the response to the LLM again.
113124 $ this ->run (new UserMessage ($ toolResult ));
114125 }
115126
0 commit comments