You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> You cannot use yield to send messages here. If you need to send, please use the `event.send()` method directly.
291
291
292
+
#### On Agent Begin
293
+
294
+
> Requires AstrBot version > v4.23.1
295
+
296
+
When the Agent starts running, the `on_agent_begin` hook is triggered.
297
+
298
+
```python
299
+
from astrbot.api.event importfilter, AstrMessageEvent
300
+
from astrbot.core.agent.run_context import ContextWrapper
301
+
from astrbot.core.astr_agent_context import AstrAgentContext
302
+
303
+
@filter.on_agent_begin()
304
+
asyncdefon_agent_begin(self, event: AstrMessageEvent, run_context: ContextWrapper[AstrAgentContext]): # Note there are three parameters
305
+
print("Agent started")
306
+
```
307
+
308
+
> You cannot use yield to send messages here. If you need to send, please use the `event.send()` method directly.
309
+
310
+
#### Before LLM Tool Call
311
+
312
+
> Requires AstrBot version > v4.23.1
313
+
314
+
When the Agent is about to call an LLM tool, the `on_using_llm_tool` hook is triggered.
315
+
316
+
You can obtain the `FunctionTool` object and tool call arguments.
317
+
318
+
```python
319
+
from astrbot.api.event importfilter, AstrMessageEvent
320
+
from astrbot.core.agent.tool import FunctionTool
321
+
322
+
@filter.on_using_llm_tool()
323
+
asyncdefon_using_llm_tool(
324
+
self,
325
+
event: AstrMessageEvent,
326
+
tool: FunctionTool,
327
+
tool_args: dict|None,
328
+
):
329
+
print(tool.name, tool_args)
330
+
```
331
+
332
+
> You cannot use yield to send messages here. If you need to send, please use the `event.send()` method directly.
333
+
334
+
#### After LLM Tool Call
335
+
336
+
> Requires AstrBot version > v4.23.1
337
+
338
+
After the LLM tool call completes, the `on_llm_tool_respond` hook is triggered.
339
+
340
+
You can obtain the `FunctionTool` object, tool call arguments, and tool call result.
341
+
342
+
```python
343
+
from mcp.types import CallToolResult
344
+
345
+
from astrbot.api.event importfilter, AstrMessageEvent
346
+
from astrbot.core.agent.tool import FunctionTool
347
+
348
+
@filter.on_llm_tool_respond()
349
+
asyncdefon_llm_tool_respond(
350
+
self,
351
+
event: AstrMessageEvent,
352
+
tool: FunctionTool,
353
+
tool_args: dict|None,
354
+
tool_result: CallToolResult |None,
355
+
):
356
+
print(tool.name, tool_args, tool_result)
357
+
```
358
+
359
+
> You cannot use yield to send messages here. If you need to send, please use the `event.send()` method directly.
360
+
361
+
#### On Agent Done
362
+
363
+
> Requires AstrBot version > v4.23.1
364
+
365
+
After the Agent finishes running, the `on_agent_done` hook is triggered. This hook is triggered after `on_llm_response`.
366
+
367
+
```python
368
+
from astrbot.api.event importfilter, AstrMessageEvent
369
+
from astrbot.api.provider import LLMResponse
370
+
from astrbot.core.agent.run_context import ContextWrapper
371
+
from astrbot.core.astr_agent_context import AstrAgentContext
372
+
373
+
@filter.on_agent_done()
374
+
asyncdefon_agent_done(self, event: AstrMessageEvent, run_context: ContextWrapper[AstrAgentContext], resp: LLMResponse): # Note there are four parameters
375
+
print(resp)
376
+
```
377
+
378
+
> You cannot use yield to send messages here. If you need to send, please use the `event.send()` method directly.
379
+
292
380
#### Before Sending Message
293
381
294
382
Before sending a message, the `on_decorating_result` hook is triggered.
0 commit comments