К основному содержанию
скилл CX Codex

migrating-pi-to-pydantic-ai — скилл для Claude Code: как ставить

Скилл помогает переписать TypeScript-агентов на базе Pi на Python с помощью Pydantic AI и Harness. Он пригодится при переносе расширений, сессий и инструментов.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add pydantic/skills --skill migrating-pi-to-pydantic-ai -a claude-code
Открыть на GitHub

Что делает migrating-pi-to-pydantic-ai

Скилл задаёт методику переноса TypeScript-приложений с библиотеки @earendil-works/pi-* на Pydantic AI. Он требует сначала исследовать рабочий сценарий: пройти один реальный запрос от CLI или createAgentSession до вызова модели и побочных эффектов. Только после фиксации контрактов выбирается целевая архитектура.

Расширения Pi делятся по зонам ответственности, потому что в Pi они смешивают UI терминала, команды и логику агента. В Pydantic AI инструменты и системные промпты упаковывают в Capability или класс AbstractCapability. Консольные интерфейсы, флаги командной строки и авторизацию оставляют на стороне хост-приложения на Python. Для базовых задач кодинга задействуется Coder из Pydantic AI Harness, а строгие цепочки шагов оформляются через pydantic_graph.

Позиция авторов однозначна: ни расширения Pi, ни Pydantic AI не изолируют выполнение кода. Поэтому для запуска недоверенных команд потребуется внешняя изоляция на уровне ОС или контейнера. Служебный контекст, ключи доступа и проектные настройки нельзя передавать в аргументы инструментов модели — их помещают строго в типизированные зависимости.

Какие задачи решает

  • перенести кодовую базу агента с TypeScript и Pi на Python с Pydantic AI
  • разделить смешанные расширения Pi на инструменты агента и хост-интерфейс
  • перевести обработку JSONL-сессий и ветвления истории диалогов в формат Pydantic AI
  • настроить безопасную передачу контекста и ключей через типизированные зависимости

Примеры запросов агенту

  • Помоги переписать расширение Pi с регистрацией инструментов на Capability в Pydantic AI
  • Проанализируй вызовы createAgentSession в TypeScript-коде и составь план переноса на Pydantic AI Harness
  • Раздели логику TUI-рендерера и вызовы модели из Pi для переноса интерфейса в Python

Как установить migrating-pi-to-pydantic-ai

1Через Skills CLI (Vercel)

npx skills add pydantic/skills --skill migrating-pi-to-pydantic-ai -a claude-code

2Вручную: положить файлы

~/.claude/skills/migrating-pi-to-pydantic-ai/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/migrating-pi-to-pydantic-ai/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о migrating-pi-to-pydantic-ai

Как установить migrating-pi-to-pydantic-ai в Claude Code?

Выполните в терминале команду npx skills add pydantic/skills --skill migrating-pi-to-pydantic-ai -a claude-code. Файлы скилла будут размещены по пути ~/.claude/skills/migrating-pi-to-pydantic-ai/SKILL.md.

Что делает скилл migrating-pi-to-pydantic-ai?

Он предоставляет руководство по миграции приложений на базе движка Pi из TypeScript в экосистему Python. Скилл учит переносить инструменты, сессии и расширения на компоненты Core, Harness и pydantic_graph.

Как переносятся сессии из формата JSONL в Pydantic AI?

Метод result.all_messages() сохраняет только историю сообщений модели, но теряет ветки дерева сессий, метки и записи сжатия из Pi. Для сохранения полной структуры потребуется отдельный адаптер совместимости или конвертация.

Исходный текст

SKILL.md · MIT
---
name: migrating-pi-to-pydantic-ai
description: Migrate TypeScript Pi coding-agent applications, extensions, or packages to Python with Pydantic AI and Pydantic AI Harness. Use when source code imports `@earendil-works/pi-*`, calls `createAgentSession`, registers Pi extensions, or relies on Pi tools, hooks, skills, sessions, compaction, providers, TUI, RPC, or packages.
---

# Migrate Pi to Pydantic AI

Preserve observable behavior, not Pi's TypeScript API. Migrate the smallest complete caller path and keep product/host infrastructure in the application.

## Trace the source before choosing a target

1. Read repository instructions, `package.json`, Pi settings, tests, extension/package manifests, and runtime entrypoints. Record the installed Pi, Pydantic AI, and Harness versions.
2. Trace one real request from the Pi CLI, RPC boundary, or `createAgentSession().prompt()` through resource discovery, system instructions, tools, extensions, model requests, messages, compaction/retry, events, session entries, UI/RPC output, and side effects. Establish a focused baseline or characterization test.
3. Inventory every active extension factory and package resource. For each `pi.on(...)`, `registerTool`, `registerCommand`, provider registration, renderer/UI contribution, skill, prompt, and persisted entry, record its firing point, trusted inputs, mutations, output, state owner, and caller-visible effect.
4. Separate these contracts when present:
   - model messages, append-only session entries/tree branches, compaction summaries, and extension state;
   - model-chosen tool input, trusted host context, project trust, approval, authorization, and OS isolation;
   - token deltas, tool lifecycle, Pi extension events, capability events, RPC events, and terminal rendering;
   - agent-loop behavior, CLI/TUI host behavior, provider transport, package distribution, and external side effects.
5. Record each observed contract, its owner, semantic difference, and executable proof. An installed but inactive Pi package feature is not migration scope.

Read [Research and concept mapping](references/RESEARCH-AND-MAPPING.md) for the detected features. Read [Verification and cutover](references/VERIFICATION-AND-CUTOVER.md) before implementation.

## Treat extensions as capability candidates

A Pi extension is the closest source concept to a Pydantic AI capability, but it is broader. An extension can combine agent behavior with terminal UI, commands, provider registration, resource discovery, and host lifecycle. **Port responsibilities, not the extension file:**

1. Map reusable model-facing behavior—tools, instructions, model settings, history/event processing, guardrails, and agent-loop hooks—to an existing Core or Harness capability when its lifecycle matches.
2. Bundle related instructions and tools in core `Capability`; subclass `AbstractCapability` only for reusable behavior that needs lifecycle hooks, adaptive models/settings, native tools, or typed capability events.
3. Keep CLI commands, flags, keyboard shortcuts, TUI renderers/dialogs, session selection, project trust, package installation, and provider credential setup in the Python application or interface adapter. They are not agent capabilities merely because a Pi extension owns them.
4. Split mixed extensions at that seam. A permission extension may become a `ToolGuardrail` or approval capability plus an application-owned approver UI; a coding package may become `Coder` plus host configuration; a provider extension remains a model/provider integration.
5. Preserve order only where evidence shows it matters. Pi handler load order and Pydantic AI capability/hook ordering are different contracts.

## Choose the smallest target

- **Core:** use `pydantic_ai.Agent` for the agent loop, typed dependencies, tools/toolsets, outputs, normalized messages, capabilities/hooks, streaming, approvals, usage limits, instrumentation, MCP, and provider/model integration.
- **Harness:** use `Coder` for Pi's ordinary coding tools only when its exact composition fits. Add focused capabilities such as `FileSystem`, `Shell`, `Skills`, `Planning`, `SubAgents`, guardrails, compaction, tool-output limits, or step persistence only for observed behavior.
- **Application/interface:** retain or replace CLI/TUI/RPC, auth, project trust, settings, provider login/catalogs, session browsing, package management, deployment, and transport deliberately.
- **Graph:** use plain async Python or `pydantic_graph` for deterministic workflows; do not encode them in prompts or subagents.
- **Gap:** name behavior with no supported public seam, explain its impact, and test a bounded adapter. Do not clone Pi's extension bus or JSONL format just to claim parity.

The normal embedded migration is one reusable `Agent`, `Coder` or a smaller capability composition, application services in typed dependencies, an application-owned message/session store, and a thin adapter at the existing RPC or UI boundary.

## Apply high-risk gates

- `ctx`, project trust, credentials, session managers, and service handles are trusted host context. Put equivalents in typed dependencies or application services, never model-chosen tool arguments.
- Pi session JSONL is an append-only branching host log containing more than model context. `result.all_messages()` preserves model history, not tree navigation, labels, extension entries, compaction records, model changes, queues, or abandoned branches. Choose and test conversion, a compatibility store, or an accepted fresh start.
- Pi compaction, context interception, steering/follow-up queues, retries, and branch summaries have specific timing. Select matching core/Harness seams independently and test ordering; generic message history or summarization is not automatic parity.
- Map `tool_call` permission gates by effect. Use guardrails for validation/block/redaction and deferred tools for an action that must await approval. Keep identity, authorization, UI, audit, persistence, and idempotency in the application.
- Pi extensions run arbitrary TypeScript with host permissions. A Pydantic AI capability also runs application code; neither is a sandbox. Use an OS/container/cloud isolation boundary for untrusted commands or code.
- Harness `Skills` loads configured `SKILL.md` instructions on demand but does not reproduce Pi's discovery roots, resource files, scripts, reload, package installation, or behavioral frontmatter. Preserve those separately when observed.
- Use `SubAgents` only for model-directed isolated tasks. Keep deterministic orchestration and Pi subprocess/tmux/package-specific semantics in application code.
- Map dynamic tool activation to core `ToolSearch` or on-demand capabilities only after testing load timing, schemas, prompt/cache changes, and provider fallback behavior.
- Pydantic AI run events and capability events do not reproduce Pi's extension event bus, RPC protocol, or TUI render lifecycle. Adapt only stable fields consumers use.
- Pi provider extensions and payload hooks may alter authentication, catalogs, wire payloads, headers, and streaming. Implement them at the Pydantic AI model/provider or application transport layer and run provider contract tests; do not hide them in a generic capability.

## Implement and prove one vertical slice

1. Preserve the supported CLI, RPC, SDK, job, or UI boundary and replace only agent-owned internals.
2. Start with core plus the smallest coding capabilities. Add broader Harness behavior only after a traced contract requires it.
3. For each source extension, document the split: capability behavior, application/interface behavior, retained integration, and gap. Test each side through its real boundary.
4. Use language-neutral fixtures for RPC/events and persisted records. Test tool arguments/results, errors, event order, session continuation, UI decisions, and side effects. Use deterministic models offline; add focused recorded/live provider tests only for provider behavior.
5. Remove Pi packages, settings, Node runtime, or extension adapters only after no retained path needs them.

Explain consequential semantic changes before implementing them: state the Pi behavior, target behavior, caller impact, recommended choice, and remaining risk.

## Completion

Apply the completion criterion in [Verification and cutover](references/VERIFICATION-AND-CUTOVER.md). Label fake, recording, live-provider, terminal, restart, and sandbox evidence accurately.

© pydantic · MIT · pydantic/skills

Похожие скиллы

Все скиллы по теме «Настройка агента: память, контекст, субагенты» →
setup-matt-pocock-skills Matt Pocock Скилл настраивает репозиторий для инженерных скиллов Matt Pocock: задаёт трекер задач, метки триажа и расположение доменной документации. Запустите его перед первым использованием остальных скиллов. 1 052 851установок ask-matt Matt Pocock Помогает выбрать подходящий скилл или рабочий поток из набора Matt Pocock. Пригодится, когда непонятно, с чего начать задачу: от идеи до разбора бага. 766 587установок to-tickets Matt Pocock Разбивает план, спецификацию или переписку на небольшие сквозные задачи и отмечает, какие из них блокируют остальные. Пригодится, когда нужно согласовать порядок работы до публикации задач в трекере. 711 230установок writing-plans Jesse Vincent Скилл превращает требования к многошаговой задаче в подробный план реализации до начала работы с кодом. Пригодится, когда исполнителю нужно зафиксировать файлы, интерфейсы и проверки. CX Codex 282 859установок caveman-review JuliusBrussee Пишет замечания к коду одной строкой: место, проблема, исправление. Пригодится, когда ревью диффа или PR надо пройти быстро и без воды. CX Codex +1 411 800установок caveman-compress JuliusBrussee Сжимает CLAUDE.md, списки задач и другие текстовые файлы в краткий формат, сохраняя читаемую резервную копию. CX Codex +1 411 500установок

Из того же набора17

logfire-infrastructure Скилл настраивает OpenTelemetry Collector так, чтобы метрики хостов, контейнеров, Kubernetes и баз данных уходили в Pydantic Logfire без правок в коде приложения. CX Codex +1 532установок migrating-langchain-to-pydantic-ai Скилл для переноса Python-приложений с LangChain, LangGraph и Deep Agents на Pydantic AI. Пригодится, когда нужно сохранить поведение, а не форму фреймворка. CX Codex +1 314установок migrating-openai-agents-sdk-to-pydantic-ai Инструкция для постепенного перевода Python-приложений с OpenAI Agents SDK на Pydantic AI и Harness. Помогает сохранить публичный контракт вызовов, хендоффы и стриминг. CX Codex +1 308установок migrating-vercel-ai-sdk-and-eve-to-pydantic-ai Переводит приложения на TypeScript Vercel AI SDK или Eve на Python с Pydantic AI. Полезен, когда нужно сохранить поведение, а не API исходника. CX Codex +1 306установок migrating-google-adk-to-pydantic-ai Помогает переносить Python-приложения с Google ADK на Pydantic AI, сохраняя поведение вызовов, инструментов, состояния и рабочих процессов. CX Codex +1 305установок migrating-claude-agent-sdk-to-pydantic-ai Скилл ведёт миграцию Python-приложения с Claude Agent SDK на Pydantic AI. Нужен, когда в коде есть импорт claude_agent_sdk. CX Codex +1 308установок migrating-mastra-to-pydantic-ai Скилл переносит TypeScript-приложения на Mastra в Python с Pydantic AI. Пригодится, когда код импортирует @mastra/* или использует агентов, инструменты и воркфлоу Mastra. CX Codex +1 304установок pydantic-ai Плагин подсказывает Claude, как писать агентов на Pydantic AI: шаблоны, деревья решений и разбор типичных ошибок. ★ 145звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой