Added Pydantic AI sync, async, temporal integration#359
Open
michael-chou359 wants to merge 4 commits into
Open
Added Pydantic AI sync, async, temporal integration#359michael-chou359 wants to merge 4 commits into
michael-chou359 wants to merge 4 commits into
Conversation
86e30bb to
739f1e5
Compare
739f1e5 to
bee0223
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Greptile Summary
This PR adds Pydantic AI integration to the Agentex SDK — a sync HTTP-streaming converter (
convert_pydantic_ai_to_agentex_events), an async Redis-streaming helper (stream_pydantic_ai_events), a shared tracing handler, and three complete tutorial examples (sync, async-base, and async-Temporal). It also refactorsCoalescingBuffer.close()instreaming.pyto stop the flush task by setting_closedand awaiting natural exit rather than cancelling mid-flush, eliminating the duplicate-tail publish on stream close._pydantic_ai_sync.py): mapsPartStartEvent,PartDeltaEvent,PartEndEvent, andFunctionToolResultEventtoStreamTaskMessageStart/Delta/Full/Done; supports streaming tool-call argument deltas. A previously-flagged P1 remains: theThinkingPartstart event emitsTextContentinstead ofReasoningContentwhile subsequent deltas useReasoningContentDelta, causing a type mismatch._pydantic_ai_async.py): correctly usesReasoningContentfor thinking parts; pushes events to Redis viaadk.streaming/adk.messages._pydantic_ai_tracing.py): usesuuid5-derived deterministic span IDs soon_tool_start/on_tool_endcan pair correctly across Temporal activity boundaries without shared in-memory state.workflow.py/agent.py): shows a full durable-agent pattern where aTemporalAgentevent stream handler streams tokens to Redis from inside model activities.Confidence Score: 4/5
Safe to merge with caution — the ThinkingPart content-type mismatch in the sync converter is still unaddressed and will cause reasoning content to render incorrectly on any client that dispatches on the start-event content type.
The sync converter starts a ThinkingPart message with TextContent but immediately sends ReasoningContentDelta deltas. Clients that switch rendering mode based on the Start event content type will display thinking tokens as a plain text bubble rather than a collapsible reasoning block. Everything else looks well-structured and correct.
src/agentex/lib/adk/_modules/_pydantic_ai_sync.py — the ThinkingPart start event still emits TextContent instead of ReasoningContent
Important Files Changed
Sequence Diagram
sequenceDiagram participant Client as HTTP or Signal participant ACP as FastACP Handler participant PA as Pydantic AI Agent participant Converter as Sync or Async Converter participant Redis as Redis via adk.streaming participant Tracing as Agentex Tracing API Client->>ACP: task event or message ACP->>PA: agent.run_stream_events(message) loop Per part PA-->>Converter: PartStartEvent Text or Thinking or ToolCall Converter->>Redis: StreamTaskMessageStart PA-->>Converter: PartDeltaEvent Converter->>Redis: StreamTaskMessageDelta PA-->>Converter: PartEndEvent Converter->>Redis: StreamTaskMessageDone alt ToolCallPart ended Converter->>Tracing: on_tool_start span create end end PA-->>Converter: FunctionToolResultEvent Converter->>Redis: StreamTaskMessageFull ToolResponseContent Converter->>Tracing: on_tool_end span patch end_time PA-->>Converter: AgentRunResultEvent ignored Converter->>ACP: final_text returnedComments Outside Diff (1)
src/agentex/lib/adk/_modules/_pydantic_ai_sync.py, line 431-450 (link)TextContentinstead ofReasoningContentThe sync converter emits
StreamTaskMessageStart(content=TextContent(...))forThinkingPartevents (line 434–440), but immediately follows withStreamTaskMessageDelta(delta=ReasoningContentDelta(...))deltas. The async counterpart (_pydantic_ai_async.py) consistently usesReasoningContentas the initial content type for the same event. The type mismatch — aTextContentstart receivingReasoningContentDeltaupdates — means any server-side logic that requires the accumulated message type to match the delta type will either fail silently or render thinking content as a plain text bubble rather than a collapsible reasoning block.ReasoningContentis not imported in this file at all, confirming the type was never set intentionally.Prompt To Fix With AI
Prompt To Fix All With AI
Reviews (4): Last reviewed commit: "added tracing" | Re-trigger Greptile