# Pydantic AI 2.63 Adds IPython Code Mode and Agent Loop Controls

Pydantic AI 2.63 adds trusted-local IPython execution, opt-in loop detection and PostgreSQL spend tracking, with a CodeMode default change to review.

By Paras Madan | 2026-10-28


Pydantic AI 2.63.0 adds an IPython execution mode, repeated-action detection and PostgreSQL-backed spending counters to its agent harness. The changes give developers more execution options and controls for unattended work. GitHub records publication on October 28, though the [release title is dated October 27](https://github.com/pydantic/pydantic-ai/releases/tag/v2.63.0).

## IPython is for trusted local work

`IPythonCodeMode` lets an agent run full CPython with installed packages and retain state between code cells. It exposes the same `run_code` tool shape as the existing Monty-based CodeMode, but uses an IPython kernel. This suits local analysis or coding workflows that need packages outside Monty's restricted environment. [IPython implementation](https://github.com/pydantic/pydantic-ai/pull/11570).

The distinction matters: IPythonCodeMode is not a sandbox. The maintainers recommend Monty for production and web-facing agents. Installing `pydantic-ai-harness[ipython]` supplies the IPython dependencies; developers then choose the new capability explicitly rather than receiving it through an automatic runtime switch.

By default, the kernel starts when first needed and stops at the end of the run. An explicitly managed kernel can persist across runs. A cell timeout attempts an interrupt and may restart an unresponsive kernel, so applications should account for lost state. Durable execution is not supported by this mode.

## Existing CodeMode users have a default to review

The separate `CodeMode()` capability now defaults to `dynamic_catalog=True`. Function signatures move into an append-only instruction block rather than living in the `run_code` tool description. When a tool becomes available during a run, its description can be added to conversation history without rewriting the earlier tool definition. [Default-change and migration details](https://github.com/pydantic/pydantic-ai/pull/11358).

This changes prompt construction even when application tool functions stay the same. Deferred tools taken over by CodeMode are discovered through local `search_tools`, rather than the provider's native tool search. Another instruction-producing toolset using the same `code_mode` identifier can now trigger a duplicate-ID error.

Pass `dynamic_catalog=False` to retain the previous behavior while reviewing the change. The lower-level `CodeModeToolset` default remains unchanged. Teams with prompt snapshots or caching checks should include those in their upgrade review instead of assuming unchanged Python functions mean unchanged model inputs.

## Loop detection and shared budget accounting

`DetectLoops` is an opt-in capability that looks for repeated calls or results, alternating tool calls and repeated text during output-validation retries. Its default response nudges the model with an instruction. Setting `action='error'` ends the run with an error instead; custom handlers and thresholds are also available. [DetectLoops behavior](https://github.com/pydantic/pydantic-ai/pull/11471).

Choose that response deliberately. Repeated polling can be legitimate, while repeatedly attempting a failed operation may warrant stopping. A nudge gives the model another instruction, not a guarantee that it will recover. Existing request and token limits remain useful backstops.

For deployments with multiple workers, `PostgresSpendStore` lets `SpendLimits` share counters through PostgreSQL. It accepts an application-owned, asyncpg-compatible connection pool and adds no database-driver dependency. Counter increments and replay-deduplication markers are committed together, with repeated tokens skipped during the configured retention period. Teams already using PostgreSQL can avoid adding Redis solely for these counters. [PostgreSQL spend-store implementation](https://github.com/pydantic/pydantic-ai/pull/11527).

The upgrade decisions are concrete: use IPython only where its execution permissions fit, review the CodeMode prompt change, and decide what a detected loop should do before enabling it. Shared spending records improve coordination across workers; they should not be mistaken for a provider-side billing cap.

I'm Paras. I work at the intersection of AI, engineering and distribution.

I help technical founders explain agent-framework releases and migration details in content developers can read, use and share.

[Book a 30-minute call](https://cal.com/paras-madan/30min).
