Repository navigation
refactor(ai): replace PydanticAgent with pydantic-ai Agent - #4237
Merged
dan-petty merged 5 commits intoNov 9, 2026
Merged
Conversation
dan-petty
force-pushed
the
refactor/2489-replace-pydanticagent-with-pydantic-ai-agent
branch
from
November 9, 2026 16:35
f79d575 to
aaaf059
Compare
dan-petty
marked this pull request as ready for review
November 9, 2026 16:56
dan-petty
deleted the
refactor/2489-replace-pydanticagent-with-pydantic-ai-agent
branch
November 9, 2026 16:57
dan-petty
pushed a commit
that referenced
this pull request
Nov 9, 2026
🤖 I have created a release *beep* *boop* --- ## [0.101.1](v0.101.0...v0.101.1) (2026-11-09) ### Bug Fixes * **devcontainer:** a rejected unlock password becomes the keyring password ([#4249](#4249)) ([cc3d22e](cc3d22e)) * **roadmap:** count the reported input in the run window estimate ([#4238](#4238)) ([af9c27a](af9c27a)) * **roadmap:** send one tool call at a time to a Claude group ([#4243](#4243)) ([b855601](b855601)) ### Code Refactoring * **ai:** replace PydanticAgent with pydantic-ai Agent ([#4237](#4237)) ([5edd7a5](5edd7a5)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
This was referenced Nov 11, 2026
dan-petty
added a commit
that referenced
this pull request
Nov 11, 2026
The spend hook of build_agent writes one spend record for each model request since #4237, but it adds no count to devops_cli_ai_model_answers_total and gives the ledger no cached prompt tokens. The stage, refine and alternatives runs go through that hook, so the Service sends no answer count after the rollout of #4237. No AI series names the job row that sent a request. The hook now counts each reply that names its model and passes the cached prompt tokens. model_answer_labels holds the fallback rule and the row for the hook and for record_run_spend. track_request_spend adds the row of request_scope to the request, token and spend series, and the runner Job applies its plan in the scope of the implement row.
dan-petty
added a commit
that referenced
this pull request
Nov 11, 2026
Since #4237, the stage, refine and alternatives runs send no `devops_cli_ai_model_answers_total`. The hook of `build_agent` writes one spend record for each request, but adds no answer count and passes no cached prompt tokens, so a cached prompt costs the full input rate. No AI series names the job row of a request. - The hook counts each reply that names its model and passes `cache_read_tokens`. - `model_answer_labels` holds the fallback rule and the row for the hook and `record_run_spend`. - `track_request_spend` adds `row` (the `request_scope` row or `other`) to the request, token and spend series. - The runner Job applies its plan in the scope of the row `implement`. Only the implement step calls `record_run_spend`, and its agent has no hook, so a request counts one time. Closes #4475 Change: `openspec/changes/archive/2026-11-11-4475-stage-and-refine-send-no-answer/`
This was referenced Nov 11, 2026
dan-petty
added a commit
that referenced
this pull request
Nov 11, 2026
## What The spend hook of `build_agent` records the seconds of each model request in `duration_seconds`. A before hook keeps the monotonic start time in a `ContextVar`. The after hook writes the record with the seconds since then. A request that raises runs no after hook, so it writes no record. ## Why Since #4237 the stage, refine and alternatives runs write their records through this hook. It passed no duration, so every record held 0.0 and the mean duration of a spend report was too low. Both hooks are `async def`: pydantic-ai runs a plain `def` hook in an executor, where the `ContextVar` would not reach the after hook. The record is written with `asyncio.to_thread`, so the SQLite write stays off the event loop. Closes #4504 Change: `openspec/changes/archive/2026-11-11-4504-agent-requests-record-no-duration-in/`
This was referenced Nov 12, 2026
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.
Replace the hand-rolled agent loop and memory classes with native pydantic-ai Agent. Centralize agent construction in build_agent with per-request spend tracking.
Closes #2489
Change:
openspec/changes/archive/2026-11-09-2489-replace-pydanticagent-with-pydantic-ai-agent/