Repository navigation
Description
Problem or Motivation
Two agent runtimes run in production (origin/main 08d70ca, 2026-10-28):
PydanticAgent(src/devops_cli/ai/agents/agent.py,runner.py,pipeline.py) is a hand-rolled tool loop overLLMClient.chat_messages.devops ai chatanddevops ai pipeline(src/devops_cli/commands/ai.py) build it. It finds a tool call by parsing the model's text (_detect_tool_intent,runner.py:177, called atagent.py:942), becauseLLMClienthas no native tool calls. Its RAG step catches every exception (agent.py:828-839).- pydantic-ai's
Agentruns the refine investigation (src/devops_cli/roadmap/refine_investigation.py, feat(roadmap): refine investigates each question with code and web tools and decides design questions by the best practice, so only decisions reserved for a person wait on one #2398). feat(roadmap): refine investigates each question with code and web tools and decides design questions by the best practice, so only decisions reserved for a person wait on one #2398 rejectedPydanticAgentfor the reasons above, and measured native tool calls through the gateway withToolOutput.
#1005 planned the opposite direction: keep the hand-rolled loop as the only runtime and delete every native Agent. #2398 reversed that direction, so #1005 is closed as not planned. pydantic-ai is the project's model library (owner decision on #1001, 2026-10-08), and the proposed answer on #1005 (2026-10-08) was to adopt the native Agent once parity passes.
Proposed Solution & Architectural Design
- One construction point builds a pydantic-ai
Agentover the task's model (get_task_model,src/devops_cli/ai/client/factory.py). It attaches one capability whoseafter_model_requesthook records each model reply withtrack_request_spend(amendment on refactor(ai): one agent runtime behind one construction point, with no silent fallback #1005, 2026-10-17). A native run then shows indevops_cli_ai_requests_totaland in the spend ledger. The refine investigation uses this construction point. devops ai chatruns on it: text and thinking stream fromrun_stream_events(ThinkingPartDelta), the persona tools are pydantic-ai tools, the chat invariants are instructions, and the conversation is the message history.devops ai pipelineruns each stage on it.- The hand-rolled loop is deleted:
PydanticAgent,runner.py,MultiAgentPipeline,AgentMemoryand their tests. The modules that other packages still import (agents/embeddings.pyfor RAG,agents/context.pyandagents/tools.pyforai/toolsets/andai/tools/) move next to their users, or stay with a statement why. GatewayRouter.build_pydantic_cascade_model(src/devops_cli/ai/gateway.py) has no caller insrc. It is deleted with its tests.- The change is probably larger than one pull request. Proposed split: (1) the construction point with the spend capability, and the refine investigation on it; (2)
devops ai chat; (3)devops ai pipeline; (4) delete the hand-rolled loop.
Target Subsystem
src/devops_cli/ai/agents/, src/devops_cli/commands/ai.py, src/devops_cli/roadmap/refine_investigation.py, src/devops_cli/ai/client/factory.py, src/devops_cli/ai/gateway.py.
Existing Tool Considered
pydantic-ai 2.54.0, the pinned version: Agent, run_stream, run_stream_events, ThinkingPart and ThinkingPartDelta, and the capabilities Hooks (with after_model_request), MCP, HandleDeferredToolCalls and ProcessHistory (read in the installed package). The change builds no tool loop, and it deletes the hand-rolled one.
Key questions
- Which pydantic-ai feature covers each feature of the loop that
devops ai chatanddevops ai pipelineuse: streaming, thinking, persona tools, chat invariants and memory, MCP tools? (proposed) The features above. A gap stops the move of that command, and the item names the gap. - Refine records one spend record for each run today (
_record_spend). Does it record one for each model request? (proposed) Yes, asLLMClientdoes. - Does
devops ai pipelinestay? (proposed) Yes, moved as it is.
Acceptance criteria
- One function in
srcbuilds an agent, andrg "PydanticAgent|_detect_tool_intent" srcfinds nothing. - With
TestModelorFunctionModel, a chat turn and a pipeline stage run offline, and each model request adds one spend record. GatewayRouter.build_pydantic_cascade_modelis deleted.uv run devops cipasses.- Pending a person:
devops ai chatwith a persona and its tools runs against the gateway as before.
Related
Supersedes #1005. Related: #1001, #2398, #958, #1003 (#2452).
Source: #1005
Alternatives check of 2026-11-04: not-applicable.
Class: refactor, no search.
Tool: none found.
Proposed design
Problem statement
Two agent runtimes run in production. The hand-rolled PydanticAgent loop reads tool calls from the model's text and catches every RAG error. pydantic-ai's Agent already runs the refine investigation (#2398). This item makes that Agent the one runtime for devops ai chat and devops ai pipeline, records one spend record for each model request, and deletes the hand-rolled loop.
Acceptance criteria
Requirement: one-construction-point
The refine investigation, devops ai chat and devops ai pipeline SHALL build their pydantic-ai Agent through one function in src/devops_cli/ai/client/factory.py.
Scenario: the-three-users-call-the-construction-point
- WHEN
rg -n 'Agent\(' src/devops_cli/commands/ai.py src/devops_cli/roadmap/refine_investigation.pyruns - THEN the command finds no match, and both files import the construction function from
src/devops_cli/ai/client/factory.py
Requirement: hand-rolled-loop-deleted
The src tree MUST hold no PydanticAgent, _detect_tool_intent, MultiAgentPipeline or AgentMemory, and MUST hold no ai/agents/agent.py, ai/agents/runner.py, ai/agents/pipeline.py or ai/agents/memory.py.
Scenario: removed-identifiers-and-modules-absent
- WHEN
rg 'PydanticAgent|_detect_tool_intent|MultiAgentPipeline|AgentMemory' srcruns - THEN the command finds no match, and the four loop modules do not exist under
src/devops_cli/ai/agents/
Requirement: chat-runs-offline
A devops ai chat turn SHALL run offline on the pydantic-ai Agent with the model_fake fixture and its persona tools.
Scenario: chat-turn-with-a-persona-tool
- WHEN
devops ai chatruns one turn with a persona whose tool themodel_fakefixture calls - THEN the console shows the tool result and the reply, and no model request leaves the machine
Requirement: pipeline-runs-offline
Each devops ai pipeline stage SHALL run offline on the pydantic-ai Agent with the model_fake fixture.
Scenario: two-stage-pipeline
- WHEN
devops ai pipelineruns two personas with themodel_fakefixture - THEN the command prints one section for each stage, and no model request leaves the machine
Requirement: spend-per-model-request
The construction point SHALL add exactly one spend record for each model request of a run.
Scenario: two-request-run-adds-two-records
- WHEN a chat turn makes two model requests with the
model_fakefixture - THEN the spend ledger holds two new records for the run
Requirement: cascade-model-deleted
GatewayRouter MUST hold no build_pydantic_cascade_model method.
Scenario: method-absent
- WHEN
rg 'build_pydantic_cascade_model' src testsruns - THEN the command finds no match
Requirement: chat-alias-deleted
src/devops_cli/commands/ai.py MUST hold no _stream_interactive_chat_turn alias.
Scenario: alias-absent
- WHEN
rg '_stream_interactive_chat_turn' src testsruns - THEN the command finds no match
Requirement: surviving-tests-use-edge-fakes
A test that the deletion keeps SHALL patch no devops_cli name and SHALL import no name that starts with _.
Scenario: no-patch-of-a-project-name
- WHEN the
testsdirectory is searched for a patch target that starts withdevops_cli - THEN the search finds no match in a test file that the deletion keeps
Requirement: ci-passes
uv run devops ci MUST pass on the changed branch.
Scenario: ci-suite-green
- WHEN
uv run devops ciruns on the changed branch - THEN every check completes with a passing status
Existing Tool Considered
pydantic-ai 2.54.0, the pinned version, covers the need: Agent, run_stream_events, ThinkingPart, ThinkingPartDelta, the Hooks capability with after_model_request, MCP, HandleDeferredToolCalls and ProcessHistory. It lacks a conversation summary of its own, so the chat keeps its history and trims it with ProcessHistory. It also keeps no ledger, so the construction point adds one hook that records each model reply. The alternatives check of 2026-11-04 gave not-applicable for this refactor, named no tool and ran no search, so no other tool was compared. The change builds no tool loop and deletes the hand-rolled one, so it pays no cost to build or keep a loop.
Key questions
- Which files hold the hand-rolled loop and its tests?: The loop is in
src/devops_cli/ai/agents/agent.py,runner.py,pipeline.pyandmemory.py. Its tests are the seven files that the tracker test(mcp): mcp, agent and tool tests run on edge fakes #1330 comment names, fromtests/ai/agents/test_pydantic_agent.pytotests/ai/rag/test_pipeline_context_budget.py. [sources: src/devops_cli/ai/agents/agent.py, src/devops_cli/ai/agents/runner.py, src/devops_cli/ai/agents/pipeline.py, src/devops_cli/ai/agents/memory.py, tests/ai/agents/test_pydantic_agent.py] - Which pydantic-ai feature covers each feature that the hand-rolled loop gives
devops ai chatanddevops ai pipeline: streaming, thinking, persona tools, chat invariants and memory, and MCP tools?:run_stream_eventsstreams the reply and the thinking of one run, withThinkingPartDeltafor the thinking and the text deltas for the reply. A persona tool is a pydantic-aiTool. Theinstructionsparameter holds the chat invariants.message_historyholds the conversation. TheMCPcapability adds the MCP tools. A gap stops the move of that command, and the item names the gap. (best practice) [sources: src/devops_cli/roadmap/refine_investigation.py, src/devops_cli/ai/agents/agent.py]- Chosen: pydantic-ai native features. The pinned pydantic-ai 2.54.0 gives each feature natively, and the refine investigation already runs on them (feat(roadmap): refine investigates each question with code and web tools and decides design questions by the best practice, so only decisions reserved for a person wait on one #2398).
- Rejected: the hand-rolled PydanticAgent loop. It reads tool calls from the model's text and catches every RAG error. It is the code that this item deletes.
- How does the chat hold the conversation now that
AgentMemoryis deleted?: The chat keeps the conversation as the run's pydantic-ai message history and passes it to the next turn. TheProcessHistorycapability trims it to the model's window.AgentMemoryand its summary call go with the loop. (best practice) [sources: src/devops_cli/commands/ai.py, src/devops_cli/ai/agents/memory.py]- Chosen: message history with the ProcessHistory capability. pydantic-ai holds the conversation of a run as its message history, and ProcessHistory trims it. No project code stays to keep it.
- Rejected: keep AgentMemory beside the Agent. The item deletes AgentMemory, and a second memory would keep the duplicate runtime that the item removes.
- Does the construction point record one spend record for each model request?: Yes. The construction point attaches one capability whose
after_model_requesthook adds one spend record for each model reply. A run of two model requests adds two records. (best practice) [sources: src/devops_cli/roadmap/refine_investigation.py, src/devops_cli/ai/agents/agent.py]- Chosen: one record per model reply through after_model_request. The hook fires after each model request, so the count matches the requests that the run made.
- Rejected: one record per run. A run of several turns then hides its real spend, and the ledger cannot price a turn.
- Where does the one construction function live?: In
src/devops_cli/ai/client/factory.py, next toget_task_model. That function already returns the pydantic-ai model of a task, with the task's provider and gateway URL. (best practice) [sources: src/devops_cli/ai/client/factory.py]- Chosen:
src/devops_cli/ai/client/factory.py, next toget_task_model. The file already resolves the model of a task, and the construction point uses that result. - Rejected: a new module
ai/agents/builder.py. The item deletes the other modules ofai/agents/, so a new module there would sit among the deletions.
- Chosen:
- Where do
agents/embeddings.py,agents/context.pyandagents/tools.pygo?:agents/embeddings.pymoves tosrc/devops_cli/ai/rag/, next to the investigator that uses it.agents/context.pyandagents/tools.pystay insrc/devops_cli/ai/agents/: they re-export theTool,AbstractToolsetandFunctionToolsettypes ofai/toolsandai/toolsets, so a move would invert that dependency. (best practice) [sources: src/devops_cli/ai/agents/tools.py, src/devops_cli/ai/agents/embeddings.py]- Chosen: move
embeddings.pytoai/rag/and keepcontext.pyandtools.py. The RAG investigator is the one user ofembeddings.py.context.pyandtools.pyhold the shared types that the rest ofai/imports. - Rejected: move all three next to their users.
tools.pyimportsai/toolsandai/toolsets, so a move of it into those packages would make a cycle. - Rejected: keep all three.
embeddings.pyserves only the RAG path, so it belongs beside the investigator.
- Chosen: move
- Does
devops ai pipelinestay?: Yes.devops ai pipelinekeeps its stages, its tools and its output, and each stage runs on a pydantic-aiAgentfrom the construction point. (best practice) [sources: src/devops_cli/commands/ai.py, src/devops_cli/ai/agents/pipeline.py]- Chosen: keep the command and move each stage to the Agent. The body keeps the command, and only its runtime changes.
- Rejected: delete the command. The body keeps it, and no other item holds its behaviour.
- How do the tests that survive the deletion avoid patches of
devops_clinames and private imports?: The tests of the deleted loop go with it. A surviving test uses themodel_fake,qdrant,embedder,configandclifixtures, patches nodevops_cliname and imports no name that starts with_. The_stream_interactive_chat_turnalias incommands/ai.pyis deleted, and the test imports the public name.tests/ai/rag/test_pipeline_context_budget.pypointsDEFAULT_TIKTOKEN_CACHE_ENV_VARSat an empty directory in place of the patch of_get_tiktoken_encoding. (best practice) [sources: src/devops_cli/commands/ai.py, tests/ai/rag/test_pipeline_context_budget.py, tests/ai/agents/test_pydantic_agent.py]- Chosen: edge fakes and public names. The tracker test(mcp): mcp, agent and tool tests run on edge fakes #1330 comment asks for it, and a test on an edge fake keeps its check when the project code changes.
- Rejected: keep the name patches and the private imports. They bind a test to the code that the item deletes, so the test fails for a reason that is not its own.
Fit
Needs splitting into 4 items:
- feat(ai): add one pydantic-ai Agent construction point with a per-request spend capability, and run the refine investigation on it
- refactor(ai): run
devops ai chaton the construction point's pydantic-ai Agent - refactor(ai): run
devops ai pipelineon the construction point's pydantic-ai Agent - refactor(ai): delete the hand-rolled PydanticAgent loop, its tests and
GatewayRouter.build_pydantic_cascade_model
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Oct 28, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
The candidate replaces one agent implementation with another and deletes the old code.It is a planned architectural cleanup, not a defect or security fix, so it is not urgent.It removes a duplicate runtime, cuts maintenance cost, and aligns the codebase with the project's chosen model library.The candidate states the work spans four pull requests across chat, pipeline, construction point, and deletion.Both work in the ai client layer, but #1001 unifies the model/provider seam while the candidate replaces the agent runtime above it.devops-cli-service commentedon Oct 29, 2026
The proposal at 0f7bc26 needs splitting into 4 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.
devops-cli-service commentedon Nov 4, 2026
Alternatives check: not-applicable
Class: refactor. The check makes no search and no model call for an item of this class.
Tool: none found
Checked on 2026-11-04. A person decides what this means for the item. The check changes no label and closes no issue.
dan-petty commentedon Nov 6, 2026
Tracker #1330 hands the tests of the hand-rolled loop to this item. #1330 builds no rename, split or new test for that code. This item deletes the code.
The test files are:
tests/ai/agents/test_pydantic_agent.pytests/ai/agents/test_agent.pytests/ai/agents/test_agent_invariants.pytests/ai/agents/test_ai_agent_deferred_tools.pytests/ai/agents/test_pydantic_ai_exceptions.pytests/ai/agents/test_pydantic_ai_native_capabilities.pytests/ai/rag/test_pipeline_context_budget.pyMeasured at origin/main 29309f0. Together they hold 17 patches of
devops_clinames and 11 private imports.Please keep these points in the pull requests of this item.
model_fake,qdrant,embedder,configand theclifixture. It patches nodevops_cliname and imports no_-name.commands/ai.pyhas the alias_stream_interactive_chat_turn = stream_interactive_chat_turn. Only a test needs it. Delete the alias and import the public name.investigate_rag_contextbuilds its ownQdrantClientandEmbeddingsEngine. test(ai): Wire rag once in ai/rag, test with edge fakes #1329 criterion 4 changes that. Until it lands, the pipeline tests patch the investigator.test_pipeline_context_budget.pypatches the token counter_get_tiktoken_encoding. Point the tiktoken cache environment variable (DEFAULT_TIKTOKEN_CACHE_ENV_VARS) at an empty directory instead. The counter then fails through its own code.ALLOW_MODEL_REQUESTSandai/agents/testing.py. It touches lines ofagent.pythat this item deletes. Whichever lands first, the other rebases.devops-cli-service commentedon Nov 6, 2026
The proposal at 56f1520 needs splitting into 4 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.
devops ai chaton the construction point's pydantic-ai Agentdevops ai pipelineon the construction point's pydantic-ai AgentGatewayRouter.build_pydantic_cascade_model[-]refactor(ai): pydantic-ai's Agent is the one agent runtime, and devops ai chat and devops ai pipeline leave the hand-rolled PydanticAgent loop[/-][+]refactor(ai): Replace PydanticAgent with pydantic-ai Agent[/+]dan-petty commentedon Nov 6, 2026
The job shortened the title of this item. The summary had 128 characters, and the limit is 60. The type and the scope stay.
refactor(ai): pydantic-ai's Agent is the one agent runtime, and devops ai chat and devops ai pipeline leave the hand-rolled PydanticAgent looprefactor(ai): Replace PydanticAgent with pydantic-ai Agentdevops-cli-service commentedon Nov 9, 2026
Released in v0.101.1: https://github.com/dan-petty/devops-cli/releases/tag/v0.101.1
devops-cli-service commentedon Nov 9, 2026
Live since 2026-11-09 17:44 UTC