Skip to content

refactor(harness)!: consolidate the Pydantic-AI harness + remove tracing handler#431

Merged
declan-scale merged 2 commits into
nextfrom
declan-scale/harness-pydantic-consolidation
Jun 23, 2026
Merged

refactor(harness)!: consolidate the Pydantic-AI harness + remove tracing handler#431
declan-scale merged 2 commits into
nextfrom
declan-scale/harness-pydantic-consolidation

Conversation

@declan-scale

@declan-scale declan-scale commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fifth slice of #425. Mirrors the LangGraph consolidation (#430) for the Pydantic-AI harness.

Breaking

  • Removed create_pydantic_ai_tracing_handler (and its handler class). Span tracing is derived from the canonical stream by UnifiedEmitter.

Consolidation

  • _pydantic_ai_async.py + _pydantic_ai_tracing.py collapsed into _pydantic_ai_sync.py and _pydantic_ai_turn.py (stream_pydantic_ai_events).
  • adk/__init__.py re-wired (pydantic imports only).
  • Removes the now-redundant test_pydantic_ai_sync_unified.py.

Test plan

  • pytest pydantic sync/async/turn + harness + conformance — 95 passed
  • import agentex.lib.adk clean; handler gone from __all__

Notes

Stacked on #430. Retarget to next after the chain merges.

🤖 Generated with Claude Code

Greptile Summary

This PR completes the Pydantic-AI harness consolidation by removing the deprecated create_pydantic_ai_tracing_handler / AgentexPydanticAITracingHandler and collapsing the old _pydantic_ai_async.py + _pydantic_ai_tracing.py modules into _pydantic_ai_turn.py. Span tracing is now derived automatically from the canonical event stream by UnifiedEmitter, matching the LangGraph consolidation in #430.

  • Deleted files: _pydantic_ai_async.py, _pydantic_ai_tracing.py, and test_pydantic_ai_sync_unified.py — their functionality is absorbed into _pydantic_ai_turn.py and test_pydantic_ai_sync.py.
  • Signature cleanups: tracing_handler parameter removed from PydanticAITurn.__init__, convert_pydantic_ai_to_agentex_events, and stream_pydantic_ai_events; all tracing is now opt-in via UnifiedEmitter(trace_id=...).
  • Shared test fixture: Duplicate local _FakeTracing classes in the harness tests are replaced with a single FakeTracing imported from tests/lib/core/harness/_fakes.py.

Confidence Score: 5/5

This refactor is safe to merge — it removes deprecated code paths in favor of the unified emitter, and all new and existing tests pass.

The consolidation is a pure refactor: functionality moves from old modules to new ones without introducing new behavior. The breaking change is clearly documented in CHANGELOG.md, test coverage is comprehensive (passthrough equivalence, span derivation, and both sync/async harness paths), and the deleted code has direct replacements.

No files require special attention

Important Files Changed

Filename Overview
src/agentex/lib/adk/_modules/_pydantic_ai_turn.py Absorbs stream_pydantic_ai_events from the deleted _pydantic_ai_async.py; removes tracing_handler parameter from PydanticAITurn and strips the TYPE_CHECKING import for the deleted tracing module. Logic is unchanged.
src/agentex/lib/adk/_modules/_pydantic_ai_sync.py Drops tracing_handler parameter and its on_tool_start/on_tool_end call-sites from convert_pydantic_ai_to_agentex_events; removes unused TYPE_CHECKING guard for the deleted tracing module. All existing streaming logic is preserved.
src/agentex/lib/adk/init.py Re-wires pydantic imports: stream_pydantic_ai_events + PydanticAITurn now come from _pydantic_ai_turn (single import); create_pydantic_ai_tracing_handler removed from imports and all.
tests/lib/adk/test_pydantic_ai_sync.py Removes TestTracingHandlerSync (now obsolete); adds TestUnifiedSyncPathPassthrough and TestUnifiedSyncPathSpanDerivation covering the new emitter-based span derivation path. Imports FakeTracing from the shared harness fakes module.
tests/lib/core/harness/test_harness_pydantic_ai_async.py Replaces local _FakeTracing (2-tuple started) with shared FakeTracing (3-tuple started) from _fakes; adjusts one unpacking site accordingly. No logic changes to the tests themselves.
tests/lib/core/harness/test_harness_pydantic_ai_sync.py Same as the async harness test — replaces local _FakeTracing with shared FakeTracing and unpacks the third (input) element at the one assertion site that inspects the tuple.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Caller
    participant stream_pydantic_ai_events
    participant PydanticAITurn
    participant convert_pydantic_ai_to_agentex_events
    participant UnifiedEmitter

    note over Caller,UnifiedEmitter: New consolidated path (this PR)

    Caller->>stream_pydantic_ai_events: stream, task_id
    stream_pydantic_ai_events->>PydanticAITurn: "PydanticAITurn(stream, model=None)"
    stream_pydantic_ai_events->>UnifiedEmitter: "UnifiedEmitter(task_id, trace_id=None, parent_span_id=None)"
    stream_pydantic_ai_events->>UnifiedEmitter: auto_send_turn(turn)
    UnifiedEmitter->>PydanticAITurn: turn.events
    PydanticAITurn->>convert_pydantic_ai_to_agentex_events: stream (no tracing_handler)
    convert_pydantic_ai_to_agentex_events-->>PydanticAITurn: "StreamTaskMessage* events"
    PydanticAITurn-->>UnifiedEmitter: "StreamTaskMessage* events"
    UnifiedEmitter-->>UnifiedEmitter: derive spans (if trace_id provided)
    UnifiedEmitter-->>stream_pydantic_ai_events: TurnResult
    stream_pydantic_ai_events-->>Caller: result.final_text
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Caller
    participant stream_pydantic_ai_events
    participant PydanticAITurn
    participant convert_pydantic_ai_to_agentex_events
    participant UnifiedEmitter

    note over Caller,UnifiedEmitter: New consolidated path (this PR)

    Caller->>stream_pydantic_ai_events: stream, task_id
    stream_pydantic_ai_events->>PydanticAITurn: "PydanticAITurn(stream, model=None)"
    stream_pydantic_ai_events->>UnifiedEmitter: "UnifiedEmitter(task_id, trace_id=None, parent_span_id=None)"
    stream_pydantic_ai_events->>UnifiedEmitter: auto_send_turn(turn)
    UnifiedEmitter->>PydanticAITurn: turn.events
    PydanticAITurn->>convert_pydantic_ai_to_agentex_events: stream (no tracing_handler)
    convert_pydantic_ai_to_agentex_events-->>PydanticAITurn: "StreamTaskMessage* events"
    PydanticAITurn-->>UnifiedEmitter: "StreamTaskMessage* events"
    UnifiedEmitter-->>UnifiedEmitter: derive spans (if trace_id provided)
    UnifiedEmitter-->>stream_pydantic_ai_events: TurnResult
    stream_pydantic_ai_events-->>Caller: result.final_text
Loading

Reviews (10): Last reviewed commit: "docs(changelog): record Pydantic-AI trac..." | Re-trigger Greptile

@declan-scale declan-scale force-pushed the declan-scale/harness-langgraph-consolidation branch from 4bb6bc7 to 86da19c Compare June 23, 2026 15:25
@declan-scale declan-scale force-pushed the declan-scale/harness-pydantic-consolidation branch from 7007832 to d7367a9 Compare June 23, 2026 15:26
@declan-scale

Copy link
Copy Markdown
Contributor Author

@greptile review

1 similar comment
@declan-scale

Copy link
Copy Markdown
Contributor Author

@greptile review

@declan-scale declan-scale force-pushed the declan-scale/harness-pydantic-consolidation branch from d7367a9 to 97b0418 Compare June 23, 2026 16:51
@declan-scale

Copy link
Copy Markdown
Contributor Author

@greptile review

@declan-scale declan-scale force-pushed the declan-scale/harness-langgraph-consolidation branch from 58aaeb4 to 66cc86b Compare June 23, 2026 19:53
@declan-scale declan-scale force-pushed the declan-scale/harness-pydantic-consolidation branch from 97b0418 to c7b151c Compare June 23, 2026 19:53
@declan-scale declan-scale force-pushed the declan-scale/harness-langgraph-consolidation branch from 66cc86b to 8dba84c Compare June 23, 2026 19:56
@declan-scale declan-scale force-pushed the declan-scale/harness-pydantic-consolidation branch from c7b151c to 176baf9 Compare June 23, 2026 19:56
@declan-scale declan-scale force-pushed the declan-scale/harness-langgraph-consolidation branch from 8dba84c to 940e00d Compare June 23, 2026 22:04
@declan-scale declan-scale force-pushed the declan-scale/harness-pydantic-consolidation branch from 176baf9 to 1b41f4d Compare June 23, 2026 22:04
@declan-scale declan-scale force-pushed the declan-scale/harness-langgraph-consolidation branch from 940e00d to c98b52e Compare June 23, 2026 22:29
@declan-scale declan-scale force-pushed the declan-scale/harness-pydantic-consolidation branch from 1b41f4d to 7448a38 Compare June 23, 2026 22:29
Base automatically changed from declan-scale/harness-langgraph-consolidation to next June 23, 2026 22:42
@declan-scale declan-scale force-pushed the declan-scale/harness-pydantic-consolidation branch from 7448a38 to 4d6f4cf Compare June 23, 2026 22:44
@declan-scale declan-scale reopened this Jun 23, 2026
@declan-scale declan-scale force-pushed the declan-scale/harness-pydantic-consolidation branch from d0b3075 to 7448a38 Compare June 23, 2026 23:22
declan-scale and others added 2 commits June 23, 2026 23:26
…ng handler

Collapse _pydantic_ai_async / _pydantic_ai_tracing into _pydantic_ai_sync
(convert helper) and _pydantic_ai_turn (stream_pydantic_ai_events). Span
tracing is derived from the canonical stream by UnifiedEmitter, so
create_pydantic_ai_tracing_handler is removed.

BREAKING CHANGE: create_pydantic_ai_tracing_handler is removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This PR removes create_pydantic_ai_tracing_handler from the public adk
surface; document it here (the previous PR's entry was narrowed to the
LangGraph handler it actually removed).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@declan-scale declan-scale force-pushed the declan-scale/harness-pydantic-consolidation branch from 7448a38 to b30a90b Compare June 23, 2026 23:26
@declan-scale declan-scale reopened this Jun 23, 2026
@declan-scale declan-scale merged commit 48c3da8 into next Jun 23, 2026
52 of 53 checks passed
@declan-scale declan-scale deleted the declan-scale/harness-pydantic-consolidation branch June 23, 2026 23:33
@stainless-app stainless-app Bot mentioned this pull request Jun 23, 2026
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.

2 participants