Skip to content

chore: port pydantic-ai v1.71.0 — Toolset forRun/forRunStep lifecycle hooks#30

Merged
a7ul merged 2 commits intomainfrom
copilot/chore-port-pydantic-ai-v1-71-0
Mar 25, 2026
Merged

chore: port pydantic-ai v1.71.0 — Toolset forRun/forRunStep lifecycle hooks#30
a7ul merged 2 commits intomainfrom
copilot/chore-port-pydantic-ai-v1-71-0

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 25, 2026

Ports the AbstractToolset.for_run / for_run_step state-isolation hooks introduced in pydantic-ai v1.71.0 to the TypeScript SDK. Bumps tracked version to 1.71.0.

Changes

  • lib/toolsets/toolset.ts — Two optional methods added to the Toolset<TDeps> interface:

    • forRun?(ctx) — called once per run before the first model turn; return a run-scoped instance (default: this)
    • forRunStep?(ctx) — called at the start of each model turn with the run-scoped instance; return a step-scoped instance (default: this)
    • Both are optional → zero breaking changes to existing implementations
  • lib/execution/_run_utils.ts — New initToolsetsForRun() helper (exported) fans out forRun calls; private resolveToolsetsForStep() fans out forRunStep calls per turn; prepareTurn() gains an optional runScopedToolsets param that triggers step resolution

  • lib/execution/run.ts / stream.ts / event_stream.ts — Each entry-point calls initToolsetsForRun before the turn loop and threads the run-scoped array through prepareTurn

  • tests/toolsets_test.ts — 5 new tests: forRun called once per run, run isolation, forRunStep called per turn, per-step distinct instances, both hooks combined

  • docs/reference/features.mdx — New rows for forRun and forRunStep in the Toolsets parity table

Usage example

class StatefulToolset implements Toolset {
  tools() { return [...]; }

  // Fresh instance per run — isolates any per-run state
  forRun(_ctx: RunContext): Toolset {
    return new StatefulToolset();
  }

  // Fresh snapshot per turn — e.g. capture mutable state before each step
  forRunStep(_ctx: RunContext): Toolset {
    return this.snapshot();
  }
}
Original prompt

This section details on the original issue you should resolve

<issue_title>chore: port pydantic-ai v1.71.0 changes</issue_title>
<issue_description>## Versions

Version
Previous v1.70.0
New v1.71.0
PyPI https://pypi.org/project/pydantic-ai/1.71.0/
Compare pydantic/pydantic-ai@v1.70.0...v1.71.0

Release Summary

Pydantic AI Release: v1.70.0 → v1.71.0

PyPI: https://pypi.org/project/pydantic-ai/1.71.0/
GitHub Release: https://github.com/pydantic/pydantic-ai/releases/tag/v1.71.0
Compare: pydantic/pydantic-ai@v1.70.0...v1.71.0

Release Notes

What's Changed

🚀 Features

  • Add Capabilities: composable, reusable units of agent behavior that bundle tools, lifecycle hooks, instructions, and model settings into a single class you plug into any agent
  • Add AgentSpec and Agent.from_file for loading agents from YAML/JSON, with support for templated instructions referencing deps (via TemplateStr)
  • Add Hooks capability for defining hooks using decorators
  • Add Thinking capability and cross-provider thinking model setting
  • Add provider-adaptive tools capabilities WebSearch, WebFetch, MCP, ImageGeneration that automatically fall back from builtin (provider) tools to local tools
  • Add AbstractToolset.for_run and for_run_step for state isolation
  • Add openai:gpt-5.4-mini and openai:gpt-5.4-nano

Full Changelog:

Changed Files in pydantic-ai

.github/workflows/bots.yml
README.md
clai/README.md
docs/.hooks/main.py
docs/agent-spec.md
docs/agent.md
docs/api/capabilities.md
docs/builtin-tools.md
docs/capabilities.md
docs/dependencies.md
docs/extensibility.md
docs/graph.md
docs/hooks.md
docs/index.md
docs/message-history.md
docs/thinking.md
docs/third-party-tools.md
docs/toolsets.md
mkdocs.yml
pydantic_ai_slim/pydantic_ai/__init__.py
pydantic_ai_slim/pydantic_ai/_agent_graph.py
pydantic_ai_slim/pydantic_ai/_cli/__init__.py
pydantic_ai_slim/pydantic_ai/_function_schema.py
pydantic_ai_slim/pydantic_ai/_history_processor.py
pydantic_ai_slim/pydantic_ai/_instructions.py
pydantic_ai_slim/pydantic_ai/_output.py
pydantic_ai_slim/pydantic_ai/_run_context.py
pydantic_ai_slim/pydantic_ai/_spec.py
pydantic_ai_slim/pydantic_ai/_template.py
pydantic_ai_slim/pydantic_ai/_tool_manager.py
pydantic_ai_slim/pydantic_ai/_utils.py
pydantic_ai_slim/pydantic_ai/agent/__init__.py
pydantic_ai_slim/pydantic_ai/agent/abstract.py
pydantic_ai_slim/pydantic_ai/agent/spec.py
pydantic_ai_slim/pydantic_ai/agent/wrapper.py
pydantic_ai_slim/pydantic_ai/capabilities/__init__.py
pydantic_ai_slim/pydantic_ai/capabilities/abstract.py
pydantic_ai_slim/pydantic_ai/capabilities/builtin_or_local.py
pydantic_ai_slim/pydantic_ai/capabilities/combined.py
pydantic_ai_slim/pydantic_ai/capabilities/history_processor.py
pydantic_ai_slim/pydantic_ai/capabilities/hooks.py
pydantic_ai_slim/pydantic_ai/capabilities/image_generation.py
pydantic_ai_slim/pydantic_ai/capabilities/mcp.py
pydantic_ai_slim/pydantic_ai/capabilities/prefix_tools.py
pydantic_ai_slim/pydantic_ai/capabilities/prepare_tools.py
pydantic_ai_slim/pydantic_ai/capabilities/thinking.py
pydantic_ai_slim/pydantic_ai/capabilities/toolset.py
pydantic_ai_slim/pydantic_ai/capabilities/web_fetch.py
pydantic_ai_slim/pydantic_ai/capabilities/web_search.py
pydantic_ai_slim/pydantic_ai/capabilities/wrapper.py
pydantic_ai_slim/pydantic_ai/durable_exec/dbos/_agent.py
pydantic_ai_slim/pydantic_ai/durable_exec/prefect/_agent.py
pydantic_ai_slim/pydantic_ai/durable_exec/temporal/_agent.py
pydantic_ai_slim/pydantic_ai/durable_exec/temporal/_dynamic_toolset.py
pydantic_ai_slim/pydantic_ai/durable_exec/temporal/_toolset.py
pydantic_ai_slim/pydantic_ai/exceptions.py
pydantic_ai_slim/pydantic_ai/models/__init__.py
pydantic_ai_slim/pydantic_ai/models/anthropic.py
pydantic_ai_slim/pydantic_ai/models/bedrock.py
pydantic_ai_slim/pydantic_ai/models/cerebras.py
pydantic_ai_slim/pydantic_ai/models/google.py
pydantic_ai_slim/pydantic_ai/models/groq.py
pydantic_ai_slim/pydantic_ai/models/openai.py
pydantic_ai_slim/pydantic_ai/models/openrouter.py
pydantic_ai_slim/pydantic_ai/models/xai.py
pydantic_ai_slim/pydantic_ai/profiles/__init__.py
pydantic_ai_slim/pydantic_ai/profiles/anthropic.py
pydantic_ai_slim/pydantic_ai/profiles/cohere.py
pydantic_ai_slim/pydantic_ai/profiles/deepseek.py
pydantic_ai_slim/pydantic_ai/profiles/google.py
pydantic_ai_slim/pydantic_ai/profiles/grok.py
pydantic_ai_slim/pydantic_ai/profiles/groq.py
pydantic_ai_slim/pydantic_ai/profiles/mistral.py
pydantic_ai_slim/pydantic_ai/profiles/openai.py
pydantic_ai_slim/pydantic_ai/providers/anthropic.py
pydantic_ai_slim/pydantic_ai/providers/bedrock.py
pydantic_ai_slim/pydantic_ai/providers/cerebras.py
pydantic_ai_slim/pydantic_ai/providers/openrouter.py
pydantic_ai_slim/pydantic_ai/run.py
pydantic_ai_s...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes a7ul/vibes#29

<!-- START COPILOT CODING AGENT TIPS -->
---

⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with [Raycast](https://gh.io/cca-raycast-docs).

Copilot AI changed the title [WIP] Chore: port pydantic-ai v1.71.0 changes chore: port pydantic-ai v1.71.0 — Toolset forRun/forRunStep lifecycle hooks Mar 25, 2026
Copilot AI requested a review from a7ul March 25, 2026 09:39
Copilot finished work on behalf of a7ul March 25, 2026 09:39
@a7ul a7ul marked this pull request as ready for review March 25, 2026 10:17
@a7ul a7ul merged commit eb951a5 into main Mar 25, 2026
1 check passed
@a7ul a7ul deleted the copilot/chore-port-pydantic-ai-v1-71-0 branch March 25, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants