/ examples / consolidated_params / basic_hooks.py
basic_hooks.py
 1  """
 2  Basic Hooks Example - Agent-Centric API
 3  
 4  Demonstrates lifecycle hooks with consolidated params.
 5  Valid keys: on_step, on_tool_call, middleware
 6  """
 7  
 8  from praisonaiagents import Agent
 9  
10  # Define hook callbacks
11  def on_step_callback(step_info):
12      print(f"Step: {step_info}")
13  
14  def on_tool_call_callback(tool_info):
15      print(f"Tool called: {tool_info}")
16  
17  # Basic: Enable hooks with dict
18  agent = Agent(
19      instructions="You are a helpful assistant.",
20      hooks={
21          "on_step": on_step_callback,
22          "on_tool_call": on_tool_call_callback,
23      },
24  )
25  
26  if __name__ == "__main__":
27      response = agent.start("What is 2 + 2?")
28      print(response)