22import time
33import json
44import logging
5+ from praisonaiagents ._logging import get_logger
56import asyncio
67import contextlib
78import threading
1617from .session_manager import SessionManagerMixin
1718
1819# Module-level logger for thread safety errors and debugging
19- logger = logging . getLogger (__name__ )
20+ logger = get_logger (__name__ )
2021
2122# ============================================================================
2223# Performance: Lazy imports for heavy dependencies
@@ -195,7 +196,6 @@ def __init__(self, agent_name: str, total_cost: float, max_budget: float):
195196 f"${ total_cost :.4f} >= ${ max_budget :.4f} "
196197 )
197198
198-
199199class Agent (ToolExecutionMixin , ChatHandlerMixin , SessionManagerMixin ):
200200 # Class-level counter for generating unique display names for nameless agents
201201 _agent_counter = 0
@@ -255,16 +255,16 @@ def _get_default_model(cls):
255255 def _configure_logging (cls ):
256256 """Configure logging settings once for all agent instances."""
257257 # Configure logging to suppress unwanted outputs
258- logging . getLogger ("litellm" ).setLevel (logging .WARNING )
258+ get_logger ("litellm" ).setLevel (logging .WARNING )
259259
260260 # Allow httpx logging when LOGLEVEL=debug, otherwise suppress it
261261 loglevel = os .environ .get ('LOGLEVEL' , 'INFO' ).upper ()
262262 if loglevel == 'DEBUG' :
263- logging . getLogger ("httpx" ).setLevel (logging .INFO )
264- logging . getLogger ("httpcore" ).setLevel (logging .INFO )
263+ get_logger ("httpx" ).setLevel (logging .INFO )
264+ get_logger ("httpcore" ).setLevel (logging .INFO )
265265 else :
266- logging . getLogger ("httpx" ).setLevel (logging .WARNING )
267- logging . getLogger ("httpcore" ).setLevel (logging .WARNING )
266+ get_logger ("httpx" ).setLevel (logging .WARNING )
267+ get_logger ("httpcore" ).setLevel (logging .WARNING )
268268
269269 @classmethod
270270 def from_template (
@@ -2771,7 +2771,7 @@ def run_autonomous(
27712771 "agent_name" : getattr (self , 'name' , None ),
27722772 })
27732773 elif self .autonomy_config .get ("observe" ):
2774- logging . getLogger (__name__ ).info (
2774+ get_logger (__name__ ).info (
27752775 f"[autonomy] iteration={ iterations } stage={ stage } "
27762776 f"response_len={ len (response_str )} "
27772777 )
@@ -3161,7 +3161,7 @@ async def main():
31613161 "agent_name" : getattr (self , 'name' , None ),
31623162 })
31633163 elif self .autonomy_config .get ("observe" ):
3164- logging . getLogger (__name__ ).info (
3164+ get_logger (__name__ ).info (
31653165 f"[autonomy-async] iteration={ iterations } stage={ stage } "
31663166 f"response_len={ len (response_str )} "
31673167 )
@@ -6337,7 +6337,7 @@ def _chat_impl(self, prompt, temperature, tools, output_json, output_pydantic, r
63376337 self ._final_display_shown = False
63386338
63396339 # Log all parameter values when in debug mode
6340- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
6340+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
63416341 param_info = {
63426342 "prompt" : str (prompt )[:100 ] + "..." if isinstance (prompt , str ) and len (str (prompt )) > 100 else str (prompt ),
63436343 "temperature" : temperature ,
@@ -6503,7 +6503,7 @@ def _chat_impl(self, prompt, temperature, tools, output_json, output_pydantic, r
65036503 self ._persist_message ("assistant" , response_text )
65046504
65056505 # Log completion time if in debug mode
6506- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
6506+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
65076507 total_time = time .time () - start_time
65086508 logging .debug (f"Agent.chat completed in { total_time :.2f} seconds" )
65096509
@@ -6846,7 +6846,7 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda
68466846 self ._final_display_shown = False
68476847
68486848 # Log all parameter values when in debug mode
6849- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
6849+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
68506850 param_info = {
68516851 "prompt" : str (prompt )[:100 ] + "..." if isinstance (prompt , str ) and len (str (prompt )) > 100 else str (prompt ),
68526852 "temperature" : temperature ,
@@ -6950,7 +6950,7 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda
69506950
69516951 self .chat_history .append ({"role" : "assistant" , "content" : response_text })
69526952
6953- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
6953+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
69546954 total_time = time .time () - start_time
69556955 logging .debug (f"Agent.achat completed in { total_time :.2f} seconds" )
69566956
@@ -6969,7 +6969,7 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda
69696969 # Rollback chat history if LLM call fails
69706970 self .chat_history = self .chat_history [:chat_history_length ]
69716971 _get_display_functions ()['display_error' ](f"Error in LLM chat: { e } " )
6972- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
6972+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
69736973 total_time = time .time () - start_time
69746974 logging .debug (f"Agent.achat failed in { total_time :.2f} seconds: { str (e )} " )
69756975 return None
@@ -7058,7 +7058,7 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda
70587058 tools = formatted_tools ,
70597059 )
70607060 result = await self ._achat_completion (response , tools )
7061- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
7061+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
70627062 total_time = time .time () - start_time
70637063 logging .debug (f"Agent.achat completed in { total_time :.2f} seconds" )
70647064 # Execute callback after tool completion
@@ -7072,7 +7072,7 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda
70727072 response_format = {"type" : "json_object" }
70737073 )
70747074 response_text = response .choices [0 ].message .content
7075- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
7075+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
70767076 total_time = time .time () - start_time
70777077 logging .debug (f"Agent.achat completed in { total_time :.2f} seconds" )
70787078 # Execute callback after JSON/Pydantic completion
@@ -7114,7 +7114,7 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda
71147114 # Return the original response without reflection
71157115 self .chat_history .append ({"role" : "user" , "content" : original_prompt })
71167116 self .chat_history .append ({"role" : "assistant" , "content" : response_text })
7117- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
7117+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
71187118 total_time = time .time () - start_time
71197119 logging .debug (f"Agent.achat completed in { total_time :.2f} seconds" )
71207120 return await self ._atrigger_after_agent_hook (original_prompt , response_text , start_time )
@@ -7166,7 +7166,7 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda
71667166 break
71677167 continue
71687168
7169- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
7169+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
71707170 total_time = time .time () - start_time
71717171 logging .debug (f"Agent.achat completed in { total_time :.2f} seconds" )
71727172
@@ -7183,13 +7183,13 @@ async def _achat_impl(self, prompt, temperature, tools, output_json, output_pyda
71837183 return None
71847184 except Exception as e :
71857185 _get_display_functions ()['display_error' ](f"Error in chat completion: { e } " )
7186- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
7186+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
71877187 total_time = time .time () - start_time
71887188 logging .debug (f"Agent.achat failed in { total_time :.2f} seconds: { str (e )} " )
71897189 return None
71907190 except Exception as e :
71917191 _get_display_functions ()['display_error' ](f"Error in achat: { e } " )
7192- if logging . getLogger ().getEffectiveLevel () == logging .DEBUG :
7192+ if get_logger ().getEffectiveLevel () == logging .DEBUG :
71937193 total_time = time .time () - start_time
71947194 logging .debug (f"Agent.achat failed in { total_time :.2f} seconds: { str (e )} " )
71957195 return None
@@ -7271,7 +7271,6 @@ async def _achat_completion(self, response, tools, reasoning_steps=False):
72717271 _get_display_functions ()['display_error' ](f"Error executing tool { function_name } : { e } " )
72727272 results .append (None )
72737273
7274-
72757274 # If we have results, format them into a response
72767275 if results :
72777276 formatted_results = "\n " .join ([str (r ) for r in results if r is not None ])
0 commit comments