BuildRiot
Sign in

Article · AI

Pydantic AI Harness adds IPython code mode alongside Monty

Pydantic AI’s v2.63.0, published October 28, 2026, with an October 27 release heading, adds IPythonCodeMode and enables Monty’s dynamic tool catalog by default. This article proposes a sales-analysis fixture for comparing package access, permissions, state retention, and tool-discovery caching.

Image published by Pydantic
Image: Pydantic (Publisher press kit)

Key takeaway

Both modes retain Python variables, so persistence alone does not settle the choice. Developers should first match package needs and execution permissions to their workload, then measure state recovery and tool-discovery caching.

One release changes execution and tool discovery

Pydantic AI’s v2.63.0 release added IPythonCodeMode, giving Harness agents access to full CPython and installed packages. Published October 28, 2026, it also made Monty CodeMode’s dynamic tool catalog the default. The changes serve separate needs: running package-dependent Python and preserving a stable prompt prefix as tools appear. Sources: Pydantic on GitHub, Pydantic

The release title carries October 27, 2026, while GitHub’s publication line shows October 28 at 00:55. The capabilities belong to Pydantic AI Harness, which remains on a 0.x version line. The catalog pull request cites that versioning context when explaining why a minor release can include this compatibility change. Developers should distinguish the repository’s release number from the versions of individual packages. Sources: Pydantic on GitHub

Compare the same sales calculation

Start with a controlled sales-analysis fixture: a single tool returning monthly revenue in integer cents for North and South. Each region’s response contains January followed by February. Ask the agent to compare January-to-February growth and retain the loaded data. It should return growth percentages and the winning region, or an explicit tie. Keep the model, instructions, tool implementation, and data constant. Request another calculation within the run, then repeat across a new run to separate those two persistence requirements.

The implementation provides separate capabilities through a common run_code interface. The setup below switches the capability while keeping the agent construction the same. Use it as the starting point for a comparison with the same model and task. Sources: Pydantic on GitHub

from pydantic_ai import Agent
from pydantic_ai_harness import CodeMode, IPythonCodeMode

capability = CodeMode()          # Monty arm
# capability = IPythonCodeMode() # IPython arm

agent = Agent(model, capabilities=[capability])

IPython exposes registered tools as synchronous functions, while Monty exposes asynchronous functions. The illustrative cells below perform the same arithmetic through those interfaces, with IPython first. The IPython example loads results into pandas DataFrames, although this small calculation does not require pandas. Package access becomes more useful when the task expands into joins, statistical routines, or plotting. Sources: Pydantic

import pandas as pd

north = pd.DataFrame(get_sales(region="north"))
south = pd.DataFrame(get_sales(region="south"))
growth = {
    "north": (north["revenue_cents"].iloc[1]
              / north["revenue_cents"].iloc[0] - 1) * 100,
    "south": (south["revenue_cents"].iloc[1]
              / south["revenue_cents"].iloc[0] - 1) * 100,
}
if growth["north"] == growth["south"]:
    winner = "tie"
elif growth["north"] > growth["south"]:
    winner = "north"
else:
    winner = "south"
{"growth_percent": growth, "winner": winner}
north = await get_sales(region="north")
south = await get_sales(region="south")
growth = {
    "north": (north[1]["revenue_cents"] / north[0]["revenue_cents"] - 1) * 100,
    "south": (south[1]["revenue_cents"] / south[0]["revenue_cents"] - 1) * 100,
}
if growth["north"] == growth["south"]:
    winner = "tie"
elif growth["north"] > growth["south"]:
    winner = "north"
else:
    winner = "south"
{"growth_percent": growth, "winner": winner}

Package access brings host permissions

IPythonCodeMode runs CPython in a separate kernel process and can use installed packages. Its installation extra includes ipykernel and jupyter-client without requiring Monty. Registered tool calls still pass through argument validation, hooks, approval handlers, and usage accounting. Those controls govern registered calls; they do not make the kernel a permissions sandbox. Sources: Pydantic on GitHub, Pydantic

Pydantic’s documentation says IPython has the user’s filesystem, network, environment, and process permissions. Monty describes its protection as language-level isolation, rather than a container, virtual machine, or seccomp boundary. Without configured host functions or mounts, generated code cannot access files, environment variables, sockets, or processes. The table below separates these access rules from scheduling and integration support. Sources: Pydantic, Pydantic on GitHub

Table

Execution and integration differences

AttributeMonty CodeModeIPythonCodeMode
Python environmentRestricted implementationFull CPython and installed packages
Host accessExplicit grants through host functions or mountsUser’s filesystem, network, environment, and process permissions
Tool schedulingAsync functions; supports asyncio.gatherSynchronous, sequential calls
Cross-run stateStored interpreter dump through repl_storeLive namespace through explicit IPythonKernel
Durable executionSupported integrationsUnsupported
Dynamic catalogSupported and now defaultUnsupported
Both modes retain state, but their permissions, scheduling, and integrations differ.Sources: Pydantic, Pydantic on GitHub

Monty supports functions, comprehensions, exceptions, simple classes, and asynchronous constructs, but its limitations include inheritance and generator functions. Its map, filter, and zip operations evaluate eagerly, and generator expressions produce lists. These differences matter when assessing memory use for larger sales datasets. Test the actual transformations before assuming familiar Python syntax produces the same behavior. Sources: Pydantic

Retained variables have different lifecycles

Monty retains variables, imports, and functions between run_code calls within a run. Cross-run persistence requires repl_store, whose asynchronous load and save operations store an opaque interpreter dump under a conversation key. Incompatible versions or resource limits can cause restoration to be discarded. Dumps require trusted storage because they are unauthenticated, and the store is not used during durable execution. Sources: Pydantic

IPython starts its kernel lazily and normally shuts it down when the run ends. An explicit IPythonKernel preserves its live namespace across runs, leaves cleanup to the application, and serializes cells sharing that kernel. Its default timeout is 60 seconds, excluding tool-call time. An interrupt normally preserves state, but failure to stop within another five seconds shuts down the kernel. The next call receives a fresh kernel; output is capped at 10 MiB. Sources: Pydantic

Pydantic’s benchmark article describes Monty defaults of 30 seconds of execution and a 256 MiB heap. Monty pauses execution budgets while awaiting host operations and applies separate compilation constraints. These limits are not directly comparable with IPython’s deadline. For the sales fixture, check whether loaded data survives another cell, another agent run, and a timeout or process crash. Conversation history alone does not prove that executable state survived. Sources: Pydantic

Tool discovery changes prompt caching

Extend the fixture with a deferred sales-target tool and ask the agent to discover it after calculating growth. Under Monty’s new default, discovered function definitions accumulate in an instruction block instead of repeatedly rewriting run_code’s description. Deferred tools managed by run_code use local search_tools, and disabling the dynamic catalog restores the previous behavior. Another instruction-contributing toolset with the identifier code_mode now causes a duplicate-ID error. Sources: Pydantic on GitHub

IPython keeps signatures in its tool description as its toolset changes and does not support the dynamic catalog. A persistent kernel therefore does not provide Monty’s cache-preserving discovery mechanism. The catalog pull request reports 480 runs across 10 tasks, two modes, six models, and four repetitions. It reports Opus input falling from 18.6k to 12.4k tokens per run, with approximately 70% less uncached input. OpenAI and Gemini results were reported as neutral. Sources: Pydantic, Pydantic on GitHub

Those maintainer measurements compare catalog modes, not IPython with Monty. Pydantic’s separate 5,276-run benchmark compared Monty with ordinary tool calling on version 2.56.1.dev13; its benchmark code is not public. It reported 58% lower long-task costs, but three of five scaling tasks cost 21–38% more with code mode at five items. Neither comparison establishes which runtime is faster for pandas analysis. Treat the sales fixture as a proposed test, not a measured result, and measure caching under the intended provider and discovery pattern. Sources: Pydantic on GitHub, Pydantic

Choose by required access, then measure

For the initial arithmetic workload, Monty is a reasonable starting point when generated code should receive only explicitly granted access. Its asynchronous tool interface supports asyncio.gather, while IPython tool calls run sequentially. IPython is the stronger candidate when the job depends on installed packages and the deployment can accommodate its host permissions. Establish those requirements before comparing speed. Sources: Pydantic, Pydantic on GitHub

Evaluate the small arithmetic workload first, then add pandas and plotting as a separate workload. Pin package versions and record correctness, cold and warm latency, peak memory, state retention, timeout recovery, and cache tokens during tool discovery. Repeat runs to distinguish consistent behavior from individual outcomes. For applications retaining kernels or restoring dumps, define how lost state is detected and sales data is reloaded before another calculation is accepted.

Attribution

Sources

  1. 1Pydantic on GitHubRelease v2.63.0 (2026-10-27)Source published (UTC)
  2. 2Pydantic on GitHubAdd an IPython Code Mode alongside the Monty-based CodeMode
  3. 3PydanticIPython Code Mode
  4. 4Pydantic on GitHubDefault CodeMode to dynamic_catalog=True
  5. 5Pydantic on GitHubMonty security model
  6. 6PydanticLimitations
  7. 7PydanticCode Mode
  8. 8PydanticCode mode vs tool calling: a 5,276-run benchmarkSource published (UTC)
  9. 9PydanticResource limits

Read the original source for full details and context.

Report a problem

Links, dates or what you expected. Do not include passwords or private data.

More on AI

All AI stories
Pydantic AI Harness adds IPython code mode alongside Monty · BuildRiot