File tree Expand file tree Collapse file tree
instrumentation-loongsuite/loongsuite-instrumentation-agno
src/opentelemetry/instrumentation/agno Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1818from dataclasses import asdict , is_dataclass
1919from typing import Any , Mapping , Sequence
2020
21- from pydantic import BaseModel
22-
2321from 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 )
Original file line number Diff line number Diff 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+
511544def test_missing_finish_reason_is_not_reported ():
512545 agent = Agent (name = "NoFinishReasonAgent" , model = EchoModel (), tools = [])
513546 invocation = create_agent_invocation (agent , {"input" : "hello" })
You can’t perform that action at this time.
0 commit comments