mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-08 08:11:38 +00:00
fix(run_agent): use safe attribute extraction instead of vars() on response objects
vars() raises TypeError on objects that don't expose __dict__ — this includes pydantic v2 models and certain OpenAI SDK response types. The crash occurred in the debug logging path when provider detection fell back to scanning response attributes. Replace vars(response) with a three-way fallback: check __dict__ first, then model_dump() for pydantic models, then an empty dict, wrapped in a try/except for any remaining edge cases. Fixes #6133
This commit is contained in:
parent
a521005fe5
commit
c1191e78cb
2 changed files with 46 additions and 1 deletions
11
run_agent.py
11
run_agent.py
|
|
@ -9499,7 +9499,16 @@ class AIAgent:
|
|||
# Check for x-openrouter-provider or similar metadata
|
||||
if provider_name == "Unknown" and response:
|
||||
# Log all response attributes for debugging
|
||||
resp_attrs = {k: str(v)[:100] for k, v in vars(response).items() if not k.startswith('_')}
|
||||
try:
|
||||
if hasattr(response, "__dict__"):
|
||||
_resp_dict = response.__dict__
|
||||
elif hasattr(response, "model_dump"):
|
||||
_resp_dict = response.model_dump()
|
||||
else:
|
||||
_resp_dict = {}
|
||||
resp_attrs = {k: str(v)[:100] for k, v in _resp_dict.items() if not k.startswith('_')}
|
||||
except (TypeError, AttributeError):
|
||||
resp_attrs = {}
|
||||
if self.verbose_logging:
|
||||
logging.debug(f"Response attributes for invalid response: {resp_attrs}")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue