Repository navigation
Description
Context & Rationale
Callers pick between two agent runtimes with different contracts. Checked at 9c879ae.
PydanticAgent[T, DepsT](ai/agents/agent.py, 1,230 lines, withrunner.py, 496) is a hand-rolled tool loop overclient.chat_messages(:887,:1086,:1131). It is constructed directly at 10 sites outsideagents/:commands/ai.py(2),harness/agents.py(2),harness/workflow.py,review/pipeline.py(2), the bridge.pydantic_ai_bridge.create_pydantic_ai_agent(:236-295) builds a nativepydantic_ai.Agentand, on any exception, falls back toPydanticAgent, returningAnywith a differentruncontract.durable.py:614builds a nativeAgentdirectly. 34 source files import pydantic_ai directly.ai/agents/pydantic_agent.py(931 lines) exists to make the hand-rolled class look like pydantic_ai.tests/test_pydantic_agent.py(33 tests) fakeschat_messages; that is the de facto seam.
Deletion test: delete the hand-rolled loop and run on a native Agent with a Model built from the one model seam, and the loop's complexity vanishes into the dependency while the devops-specific capabilities (capabilities.py, guardrails, spend) stay. Or delete the bridge and keep the loop. Either way the silent fallback goes.
Scope & Deliverables
- Deliverable: one factory returns one concrete agent type with
runandrun_stream; persona, harness and command callers never see pydantic_ai or the client; the fallback is gone. - Tests:
test_pydantic_agent.pykeeps thechat_messagesseam; the bridge-fallback tests go. - Key questions (open; the direction is the decision):
- Does pydantic_ai have parity for the deferred tools, thinking and MCP sampling the hand-rolled loop carries (fix(ai): agent toolset instructions, deferred-tool context, the sampling-model stub, harness memory and shell process groups #958)?
- If not, is the native path deleted instead?
- Constraint: depends on refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001; feat(ai): pinned invariants survive memory summarization, lead every system prompt and recur on a cadence #985 and feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857 change what the loop does and should land first.
Strategic Alignment
- Design: none
- Depends on: refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001
- Related: fix(ai): agent toolset instructions, deferred-tool context, the sampling-model stub, harness memory and shell process groups #958, feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857, feat(ai): pinned invariants survive memory summarization, lead every system prompt and recur on a cadence #985, feat(ai): sequential pipeline stages carry a budgeted context, with the scratchpad appended once #859
- Source: architecture review of 2026-10-02, AI core
Scope added 2026-10-02: checked at 38517a8. Production never builds a native pydantic_ai agent, so callers do not choose between two runtimes today. The only two pydantic_ai.Agent(...) constructions in src are in create_pydantic_ai_agent (ai/pydantic_ai_bridge.py:236-295, construction at :281) and create_durable_pydantic_agent (ai/durable.py:571-614). The first is called only by get_persona_pydantic_agent (:297-321), which nothing in src calls; the second is only re-exported (ai/agents/pydantic_agent.py:221). The silent fallback (:282-295) is therefore reachable only from tests. Every production agent is a PydanticAgent, built in commands/ai.py (2), ai/harness/agents.py, ai/harness/workflow.py, ai/review/pipeline.py (2) and the bridge's fallback. The bridge's other public functions (inject_prompt_cache_points, create_cached_user_prompt, execute_structured_workflow_sync, build_fallback_cascade_model and its one caller GatewayRouter.build_pydantic_cascade_model, ai/gateway.py:554) have no production caller either. They are also the only route to resolve_pydantic_ai_model, and through it to ai/providers and ai/direct.py (see #1001). The knowledge-base page ai/knowledge_base/it_domains/tools/pydantic_ai.md:22-26 teaches the dead factories. AGENTS.md:392 asks for provider protocols under providers/. That bullet is not in ai/instruction_generator.py, and AGENTS.md is curated, not generated (#840).
Acceptance criteria
-
PydanticAgentis the only agent runtime.create_pydantic_ai_agent,get_persona_pydantic_agent,_fallback_pydantic_agent,inject_prompt_cache_points,create_cached_user_prompt,build_fallback_cascade_model,execute_structured_workflowandexecute_structured_workflow_sync(ai/pydantic_ai_bridge.py:210-449),GatewayRouter.build_pydantic_cascade_modelandcreate_durable_pydantic_agentare deleted.rg 'pydantic_ai import .*\bAgent\b|pydantic_ai\.Agent\(' srcfinds nothing, andai/agents/pydantic_agent.py:5-7no longer re-exportspydantic_ai.agent.Agent, which nosrcmodule imports from it. - Everything only those functions reach is deleted with them:
resolve_pydantic_ai_modeland its helpers,ai/providers/,ai/direct.py, and their re-exports. The PR lists each deleted public name with the search that shows it had no caller insrc. - Every agent construction in
srcbuilds a typedPydanticAgent[...]. No function that builds an agent returnsAny, and none falls back on an exception. - Tests that cover only deleted code are deleted, and the PR names them (for example the bridge-fallback tests in
tests/test_pydantic_agent.py,tests/test_providers.pyandtests/mock_provider.py).tests/test_pydantic_agent.pykeeps itschat_messagesseam tests. - The knowledge-base page no longer shows the deleted factories.
- AGENTS.md:392 is edited in place to name
LLMClientas the model seam, with deterministic fakes for offline tests. AGENTS.md is not regenerated:devops ai agentswould write its short template over the curated file (ai/instruction_generator.py:412-427, docs(agents): instruction surfaces state only what is true, anddevops ai agentsnever overwrites AGENTS.md #840). - The new and changed tests run offline, with no model, network or cluster.
-
uv run devops cipasses. - (person-run)
devops ai chatand onedevops review pathrun as before.
Key questions
- Does pydantic_ai have parity for the deferred tools, thinking and MCP sampling the hand-rolled loop carries (fix(ai): agent toolset instructions, deferred-tool context, the sampling-model stub, harness memory and shell process groups #958)? (proposed) This item does not need the answer. Production never runs the native path, so deleting it changes no behaviour. Adopting a native runtime later is a feature item with its own parity check against fix(ai): agent toolset instructions, deferred-tool context, the sampling-model stub, harness memory and shell process groups #958.
- If not, is the native path deleted instead? (proposed) Yes, now. The pre-1.0 policy does not keep unused code paths.
- Which item deletes
ai/providersandai/direct.py, this one or refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001? (proposed) This one, because only the native path reaches them. refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 then refactors a single stack and depends on this item, which reverses today's "Depends on: refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001". - Does
pydantic_aistay a dependency? (proposed) Yes. 42 source files import it at 38517a8 (31 at module level), many outside the native path. The PR reports the count after the deletion; removing the dependency is a separate item if the count reaches zero. - When does it land? (proposed) After fix(ai): agent toolset instructions, deferred-tool context, the sampling-model stub, harness memory and shell process groups #958 (v0.2.25), which edits
ai/agents/andai/harness/. feat(ai): pinned invariants survive memory summarization, lead every system prompt and recur on a cadence #985 and feat(mcp): mcp tools declare ToolAnnotations, and mutating tools require approval in devops-cli's own agent loop #857 change the hand-rolled loop, which stays, so they no longer need to land first.
Update 2026-10-08: refinement
Owner decision on #1001: resolve_pydantic_ai_model, the pydantic-ai providers and ai/direct.py stay; #1331 deletes the legacy classes. The first criterion stands: delete the fallback and dead factories (ai/pydantic_ai_bridge.py:262-494, ai/gateway.py:555, and ai/durable.py:583 unless #1331 removed it). #1001 owns the provider route and the AGENTS.md:444 bullet. Open key question for the owner: adopt the native pydantic_ai.Agent? (proposed) Yes, once parity for deferred tools, thinking and MCP sampling passes.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsReady
Activity
dan-petty commentedon Oct 8, 2026
Owner decision on #1001, 2026-10-08: the model seam is pydantic-ai models through
pydantic_ai.direct. That reverses this item's criterion deletingresolve_pydantic_ai_model, the pydantic-ai providers inai/providers/__init__.pyandai/direct.py: #1001 rebuilds that route on the egress factory client as the one model seam. The legacyBaseLLMProviderclasses (#1331) still go.Key question for the owner: with pydantic-ai as the model layer, should the agent runtime become the native
pydantic_ai.Agentover that seam, deleting the hand-rolledPydanticAgentloop? This item's deletion test already names that option. Proposed answer: yes, once the parity check in this item's key questions passes (deferred tools, thinking, MCP sampling, #958). Until then, keep the hand-rolled loop and delete the silent fallback as planned.dan-petty commentedon Oct 17, 2026
Amendment from the gateway usage investigation of 2026-10-17, at main 3dd7fa6.
track_request_spend:create_pydantic_ai_agent,get_persona_pydantic_agent,execute_structured_workflowand its_syncvariant,build_fallback_cascade_model,GatewayRouter.build_pydantic_cascade_modelandcreate_durable_pydantic_agent.SpendGuard(src/devops_cli/ai/agents/spend.py:56-76) and the governance token bucket only count in memory.pydantic_ai.Agent(this item's open key question), the adopting change attaches one capability whoseafter_model_requestcallstrack_request_spendfromresponse.usage,response.model_nameand the current stage.TestModelshows up indevops_cli_ai_requests_totaland in the ledger.No traffic on these paths in 30 days, so priority stays P2.
refactor(ai): chat_structured is the one structured-output path (#2452)
dan-petty commentedon Oct 28, 2026
Closed as not planned. The item conflicts with a more recent project direction. #2489 carries its goal, one agent runtime with no silent fallback, in the direction that the project now takes.
Evidence (origin/main 08d70ca, 2026-10-28):
PydanticAgentthe only agent runtime: "rg 'pydantic_ai import .*\bAgent\b|pydantic_ai\.Agent\(' srcfinds nothing".Agent(src/devops_cli/roadmap/refine_investigation.py). Its design rejectedPydanticAgentwith evidence: the loop finds a tool call by parsing the model's text (_detect_tool_intent,src/devops_cli/ai/agents/runner.py:177), its RAG step catches every exception (agent.py:828-839), andLLMClient, which it calls, has no native tool calls. Against the gateway, the nativeAgentwithToolOutputmade native tool calls.Agentonce parity passes.create_pydantic_ai_agent,get_persona_pydantic_agent, the silent fallback,create_durable_pydantic_agent,inject_prompt_cache_points,create_cached_user_prompt,execute_structured_workflowandai/agents/pydantic_agent.pyare no longer insrc. One dead factory stays,GatewayRouter.build_pydantic_cascade_model, and refactor(ai): Replace PydanticAgent with pydantic-ai Agent #2489 deletes it.No code was written for this item.