Skip to content

fix(agno): remove pydantic runtime dependency#221

Open
sipercai wants to merge 1 commit into
mainfrom
liuyu/fix-agno-util-genai-dependency
Open

fix(agno): remove pydantic runtime dependency#221
sipercai wants to merge 1 commit into
mainfrom
liuyu/fix-agno-util-genai-dependency

Conversation

@sipercai

@sipercai sipercai commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR removes the direct pydantic runtime dependency from loongsuite-instrumentation-agno and adds an Agno-side regression test proving that message-content capture mode does not gate span creation.

origin/main already has the Agno 2.x instrumentation migrated to opentelemetry-util-genai in d741321e feat(agno): adapt instrumentation for Agno 2. This PR is the remaining dependency-isolation and regression-test follow-up on top of that migration. The residual issue is that the Agno instrumentation package still declares pydantic as a normal dependency and directly imports BaseModel, which can make probe installation or pre-cache environments pull Python-ABI-specific pydantic-core wheels even when the target application has not installed Agno.

The change keeps support for Pydantic-style objects by using model_dump() duck typing instead of importing pydantic.BaseModel, and adds a focused test for that conversion path.

Fixes # (N/A; no public issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • python3 <loongsuite-github-pipeline>/scripts/check_loongsuite_pr_readiness.py --repo .
  • tox -e precommit
  • tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-agno
  • tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-agno
  • tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-agno -- -k content_capture_mode_does_not_gate_span_creation
  • Built the Agno wheel and inspected METADATA; normal runtime dependencies no longer include pydantic, pydantic-core, or agno.
  • Installed the rebuilt wheel into a Python 3.10 environment without Agno/Pydantic and imported the Agno instrumentor and utility module successfully.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Validation Evidence

Spec and Scope

  • Linked issue/spec: No public issue; requested as direct dependency-isolation fix for Agno instrumentation.
  • Base migration: Agno already uses opentelemetry-util-genai on origin/main via d741321e feat(agno): adapt instrumentation for Agno 2.
  • Changed surface: loongsuite-instrumentation-agno dependency metadata, Agno serialization utility, and focused tests.
  • Rebase base: latest origin/main at PR preparation time.

Local Checks

Check Command Result Notes
Static readiness python3 <loongsuite-github-pipeline>/scripts/check_loongsuite_pr_readiness.py --repo . pass LoongSuite static PR readiness checks passed.
Precommit tox -e precommit pass Ruff, ruff-format, uv-lock, and rstcheck passed.
Content capture regression tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-agno -- -k content_capture_mode_does_not_gate_span_creation pass 2 passed. Unset and NO_CONTENT still create AGENT/LLM spans while omitting message content attributes.
Focused tests tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-agno pass 20 passed. Covers sync, streaming, async, concurrency, tool, content-capture modes, error, and serialization paths.
Focused lint tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-agno pass Agno package ruff check passed.
Wheel metadata uv build --wheel --out-dir <tmpdir>/loongsuite-agno-rebased-dist instrumentation-loongsuite/loongsuite-instrumentation-agno pass Normal Requires-Dist contains OTel/util-genai/wrapt only; Agno remains in extras.
No-pydantic import Install rebuilt wheel plus local OTel/util-genai packages in a clean Python 3.10 environment pass agno, pydantic, and pydantic_core were absent; Agno instrumentor import and model_dump() duck typing succeeded.

CI

  • GitHub checks: not run yet; PR is being created after local validation.
  • Known unrelated failures: none known.

@sipercai sipercai force-pushed the liuyu/fix-agno-util-genai-dependency branch from f4b9505 to 3ac94d8 Compare June 17, 2026 07:15
@sipercai sipercai marked this pull request as ready for review June 17, 2026 07:56

@ralf0131 ralf0131 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by github-manager-bot

Summary

Removes the hard pydantic runtime dependency from loongsuite-instrumentation-agno by replacing the isinstance(value, BaseModel) type check with duck-typing via getattr(value, "model_dump", None). Includes a CHANGELOG entry and a focused regression test.

Findings

  • [Info] utils.py — The duck-typing approach is the right call: it avoids pulling pydantic-core wheels into environments where Agno itself is not installed, while still serializing Pydantic-style objects correctly via model_dump(mode="json") with a TypeError fallback for older Pydantic versions that lack the mode parameter.
  • [Info] pyproject.toml — Clean removal; moving pydantic to test deps (already present) is correct.

Tests

Comprehensive coverage: content_capture_mode_does_not_gate_span_creation proves span creation works without content capture, and the test_convert_value_with_pydantic_model_dump test verifies the duck-typing serialization path.

LGTM. Clean dependency-isolation fix with good test coverage.


Automated review by github-manager-bot

@sipercai

Copy link
Copy Markdown
Collaborator Author

Thanks for the review.

I checked the failing CI. Both failures are from Misc 0 / typecheck, and pyright reports only two errors in an unrelated VertexAI file:

  • instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/patch.py:176
  • instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/patch.py:260

Both are Unnecessary "# type: ignore" comment diagnostics. This PR does not touch VertexAI; its diff is limited to the Agno dependency metadata, Agno serialization utility, changelog, and Agno tests.

I also reproduced the same failure locally with tox -e typecheck. The Agno-specific checks still pass:

  • tox -c tox-loongsuite.ini -e py310-test-loongsuite-instrumentation-agno
  • tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-agno
  • tox -e precommit

I plan to keep this PR scoped to Agno dependency isolation. If maintainers require a fully green PR despite this pre-existing repo-wide typecheck failure, I can prepare a separate VertexAI cleanup or follow up after that fix lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants