技能详情(站内镜像,无评论)
作者:Kevin Anderson @anderskev
许可证:MIT-0
MIT-0 ·免费使用、修改和重新分发。无需归因。
版本:v1.0.0
统计:⭐ 0 · 22 · 1 current installs · 1 all-time installs
⭐ 0
安装量(当前) 1
🛡 VirusTotal :良性 · OpenClaw :良性
Package:anderskev/pydantic-ai-agent-creation
安全扫描(ClawHub)
- VirusTotal :良性
- OpenClaw :良性
OpenClaw 评估
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.
目的
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.
综合结论
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 place…
安装(复制给龙虾 AI)
将下方整段复制到龙虾中文库对话中,由龙虾按 SKILL.md 完成安装。
请把本段交给龙虾中文库(龙虾 AI)执行:为本机安装 OpenClaw 技能「Pydantic Ai Agent Creation」。简介:Create PydanticAI agents with type-safe dependencies, structured outputs, and p…。
请 fetch 以下地址读取 SKILL.md 并按文档完成安装:https://raw.githubusercontent.com/openclaw/skills/refs/heads/main/skills/anderskev/pydantic-ai-agent-creation/SKILL.md
(来源:yingzhi8.cn 技能库)
SKILL.md
---
name: pydantic-ai-agent-creation
description: Create PydanticAI agents with type-safe dependencies, structured outputs, and proper configuration. Use when building AI agents, creating chat systems, or integrating LLMs with Pydantic validation.
---
# Creating PydanticAI Agents
## Quick Start
```python
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:
```python
# 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:
```python
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
```python
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:
```python
# 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
```python
# 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)
```python
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)
```python
# 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
| Scenario | Configuration |
|----------|--------------|
| Simple text responses | `Agent(model)` |
| Structured data extraction | `Agent(model, output_type=MyModel)` |
| Need external services | Add `deps_type=MyDeps` |
| Validation retries needed | Increase `retries=3` |
| Debugging/monitoring | Set `instrument=True` |