Skip to content

Commit f4b9505

Browse files
committed
fix(agno): remove pydantic runtime dependency
1 parent de65b32 commit f4b9505

4 files changed

Lines changed: 48 additions & 5 deletions

File tree

instrumentation-loongsuite/loongsuite-instrumentation-agno/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Removed
11+
12+
- Remove the direct `pydantic` runtime dependency from Agno instrumentation.
13+
1014
## Version 0.6.0 (2026-06-03)
1115

1216
### Removed

instrumentation-loongsuite/loongsuite-instrumentation-agno/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies = [
3030
"opentelemetry-instrumentation >= 0.58b0",
3131
"opentelemetry-semantic-conventions >= 0.58b0",
3232
"opentelemetry-util-genai",
33-
"pydantic",
3433
"wrapt >= 1.17.3, < 2.0.0",
3534
]
3635

instrumentation-loongsuite/loongsuite-instrumentation-agno/src/opentelemetry/instrumentation/agno/utils.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
from dataclasses import asdict, is_dataclass
1919
from typing import Any, Mapping, Sequence
2020

21-
from pydantic import BaseModel
22-
2321
from opentelemetry.util.genai.extended_semconv.gen_ai_extended_attributes import (
2422
GEN_AI_SESSION_ID,
2523
GEN_AI_USER_ID,
@@ -62,8 +60,17 @@ def _to_dict(value: Any) -> dict[str, Any] | None:
6260
return None
6361
if isinstance(value, Mapping):
6462
return dict(value)
65-
if isinstance(value, BaseModel):
66-
return value.model_dump(mode="json")
63+
model_dump = getattr(value, "model_dump", None)
64+
if callable(model_dump):
65+
try:
66+
return model_dump(mode="json")
67+
except TypeError:
68+
try:
69+
return model_dump()
70+
except Exception:
71+
return None
72+
except Exception:
73+
return None
6774
if is_dataclass(value):
6875
return asdict(value)
6976
to_dict = getattr(value, "to_dict", None)

instrumentation-loongsuite/loongsuite-instrumentation-agno/tests/test_agno.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,39 @@ def test_tool_result_messages_do_not_duplicate_text_parts():
508508
assert parts[0].response == {"temperature": 21}
509509

510510

511+
def test_model_dump_objects_are_serialized_without_pydantic_base_class():
512+
class ModelDumpToolCall:
513+
def model_dump(self, mode="json"):
514+
assert mode == "json"
515+
return {
516+
"id": "call_1",
517+
"function": {
518+
"name": "get_weather",
519+
"arguments": '{"city":"Hangzhou"}',
520+
},
521+
}
522+
523+
messages = convert_agent_input(
524+
[
525+
SimpleNamespace(
526+
role="assistant",
527+
content=None,
528+
tool_calls=[ModelDumpToolCall()],
529+
)
530+
]
531+
)
532+
533+
parts = messages[0].parts
534+
tool_calls = [
535+
part for part in parts if getattr(part, "type", None) == "tool_call"
536+
]
537+
538+
assert len(tool_calls) == 1
539+
assert tool_calls[0].id == "call_1"
540+
assert tool_calls[0].name == "get_weather"
541+
assert tool_calls[0].arguments == {"city": "Hangzhou"}
542+
543+
511544
def test_missing_finish_reason_is_not_reported():
512545
agent = Agent(name="NoFinishReasonAgent", model=EchoModel(), tools=[])
513546
invocation = create_agent_invocation(agent, {"input": "hello"})

0 commit comments

Comments
 (0)