首页龙虾技能列表 › Pydantic Ai Agent Creation — 技能工具

Pydantic Ai Agent Creation — 技能工具

v1.0.0

Create PydanticAI agents with type-safe dependencies, structured outputs, and proper configuration. Use when building AI agents, creating chat systems, or in...

0· 109·1 当前·1 累计
by @anderskev (Kevin Anderson)·MIT-0
下载技能包
License
MIT-0
最后更新
2026/3/20
安全扫描
VirusTotal
无害
查看报告
OpenClaw
安全
high confidence
The skill is an instruction-only guide for building Pydantic-based AI agents; its instructions, scope, and requirements are consistent with the stated purpose and it does not request unrelated credentials or install code.
评估建议
This skill is a documentation/instruction bundle (no code installed) and appears coherent with its purpose. Before using the provided examples you will need to supply appropriate model provider credentials (OpenAI/Anthropic/Google/etc.) in your runtime environment — those are not requested by the skill manifest. When you run agent code in your environment: (1) keep provider API keys limited to the least privilege and store them in secure places (not hard-coded), (2) be mindful that enabling inst...
详细分析 ▾
用途与能力
The name/description (creating PydanticAI agents) matches the SKILL.md content: code examples, configuration, and patterns for typed agents. It references external model providers (OpenAI, Anthropic, Google, etc.) but does not request unrelated capabilities or secrets in the manifest.
指令范围
All runtime instructions are code examples and guidance for constructing agents and validation flows. The document does not instruct the agent to read local files, environment secrets, or send data to unexpected endpoints; it stays within the stated purpose.
安装机制
There is no install spec and no code files to be written or executed. This is instruction-only, so nothing will be downloaded or installed by the skill itself.
凭证需求
The skill declares no required environment variables or credentials. It references external model providers (which, when you run code based on these instructions, will require provider API keys), but the skill itself does not request or collect unrelated secrets.
持久化与权限
Flags indicate normal, non-persistent behavior (always: false). The skill does not request elevated or permanent presence and does not modify other skills or system-wide settings.
安全有层次,运行前请审查代码。

License

MIT-0

可自由使用、修改和再分发,无需署名。

运行时依赖

无特殊依赖

版本

latestv1.0.02026/3/20

- Initial release of pydantic-ai-agent-creation skill. - Enables creation of PydanticAI agents with type-safe dependencies and structured outputs. - Supports model selection via provider:model-name format. - Allows use of Pydantic models for validated, typed agent responses. - Provides flexible agent configuration for output types, dependencies, instructions, retries, settings, and execution methods. - Includes guidance for parameterized, dependency-free, and structured agent patterns.

● 无害

安装命令 点击复制

官方npx clawhub@latest install pydantic-ai-agent-creation
镜像加速npx clawhub@latest install pydantic-ai-agent-creation --registry https://cn.clawhub-mirror.com

技能文档

Quick Start

from pydantic_ai import Agent

# Minimal agent (text output) agent = Agent('openai:gpt-4o') result = agent.run_sync('Hello!') print(result.output) # str

Model Selection

Model strings follow provider:model-name format:

# OpenAI
agent = Agent('openai:gpt-4o')
agent = Agent('openai:gpt-4o-mini')

# Anthropic agent = Agent('anthropic:claude-sonnet-4-5') agent = Agent('anthropic:claude-haiku-4-5')

# Google agent = Agent('google-gla:gemini-2.0-flash') agent = Agent('google-vertex:gemini-2.0-flash')

# Others: groq:, mistral:, cohere:, bedrock:, etc.

Structured Outputs

Use Pydantic models for validated, typed responses:

from pydantic import BaseModel
from pydantic_ai import Agent

class CityInfo(BaseModel): city: str country: str population: int

agent = Agent('openai:gpt-4o', output_type=CityInfo) result = agent.run_sync('Tell me about Paris') print(result.output.city) # "Paris" print(result.output.population) # int, validated

Agent Configuration

agent = Agent(
    'openai:gpt-4o',
    output_type=MyOutput,           # Structured output type
    deps_type=MyDeps,               # Dependency injection type
    instructions='You are helpful.',  # Static instructions
    retries=2,                      # Retry attempts for validation
    name='my-agent',                # For logging/tracing
    model_settings=ModelSettings(   # Provider settings
        temperature=0.7,
        max_tokens=1000
    ),
    end_strategy='early',           # How to handle tool calls with results
)

Running Agents

Three execution methods:

# Async (preferred)
result = await agent.run('prompt', deps=my_deps)

# Sync (convenience) result = agent.run_sync('prompt', deps=my_deps)

# Streaming async with agent.run_stream('prompt') as response: async for chunk in response.stream_output(): print(chunk, end='')

Instructions vs System Prompts

# Instructions: Concatenated, for agent behavior
agent = Agent(
    'openai:gpt-4o',
    instructions='You are a helpful assistant. Be concise.'
)

# Dynamic instructions via decorator @agent.instructions def add_context(ctx: RunContext[MyDeps]) -> str: return f"User ID: {ctx.deps.user_id}"

# System prompts: Static, for model context agent = Agent( 'openai:gpt-4o', system_prompt=['You are an expert.', 'Always cite sources.'] )

Common Patterns

Parameterized Agent (Type-Safe)

from dataclasses import dataclass
from pydantic_ai import Agent, RunContext

@dataclass class Deps: api_key: str user_id: int

agent: Agent[Deps, str] = Agent( 'openai:gpt-4o', deps_type=Deps, )

# deps is now required and type-checked result = agent.run_sync('Hello', deps=Deps(api_key='...', user_id=123))

No Dependencies (Satisfy Type Checker)

# Option 1: Explicit type annotation
agent: Agent[None, str] = Agent('openai:gpt-4o')

# Option 2: Pass deps=None result = agent.run_sync('Hello', deps=None)

Decision Framework

ScenarioConfiguration
Simple text responsesAgent(model)
Structured data extractionAgent(model, output_type=MyModel)
Need external servicesAdd deps_type=MyDeps
Validation retries neededIncrease retries=3
Debugging/monitoringSet instrument=True
数据来源:ClawHub ↗ · 中文优化:龙虾技能库
OpenClaw 技能定制 / 插件定制 / 私有工作流定制

免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制

了解定制服务