Token导航 LogoToken导航TokenDH.com
研究检索敏感数据github未标认证来源可访问clear审计异常

pydantic-ai-agentpydantic AI Agent 搜索

Agent Skill

pydantic-ai-agent 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

419

周安装

18

GitHub Stars

公开资料未说明

下载量

147
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:pydantic-ai-agent(pydantic AI Agent 搜索)
来源仓库:https://github.com/randomstar/skill-set
仓库路径:skills/pydantic-ai-agent
安装命令:
npx skills add https://github.com/randomstar/skill-set --skill pydantic-ai-agent
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/randomstar/skill-set --skill pydantic-ai-agent

简介

用于查找、检索和筛选相关信息。pydantic-ai-agent 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

  • 适合根据关键词或任务场景快速定位候选结果。
  • 可结合来源仓库与原始 README 进一步核验具体用法。
  • 安装前需确认权限范围及是否会触发联网或文件读写操作。
  • 建议检查维护状态,避免使用不稳定或已弃用的技能。

SKILL.md

Pydantic AI Agent Builder

Build production-grade AI agents using Pydantic AI with a layered architectural pattern.

When to Use This Skill

Use this skill when building:

  • AI agents with tool/function calling capabilities
  • Conversational agents with state management
  • Streaming chat applications (SSE, real-time responses)
  • Multi-provider LLM applications (OpenAI, Anthropic, Google, Ollama)
  • FastAPI web services with AI agents
  • CLI applications with AI agents
  • Agents requiring dependency injection for tools

Quick Start

1. Scaffold a New Project

python scripts/scaffold_agent.py my_agent
cd my_agent
pip install -r requirements.txt

Options:

  • --minimal - Core files only
  • --web - Include FastAPI example
  • --cli - Include CLI example

2. Configure Provider

# .env file
LLM_PROVIDER=anthropic
LLM_MODEL_NAME=claude-3-5-sonnet-20241022
LLM_API_KEY=sk-ant-...

3. Run Examples

# CLI
python example_cli.py

# Web service
python example_fastapi.py
# Visit http://localhost:8000/docs

Architecture Overview

This pattern uses a layered architecture:

Router/CLI → Service → AgentFactory → Agent
                ↓           ↓
            Tools ← ToolRegistry
                ↓
            StateStore

Key Components:

  • AgentFactory - Creates configured agents (Factory pattern)
  • AgentService - Orchestrates agent lifecycle
  • ToolRegistry - Centralized tool registration
  • ToolCollection - Dependency injection for tools
  • AgentState - Conversation history management
  • StateStore - State persistence
  • ModelProvider - Multi-provider abstraction

Core Patterns

1. Agent Factory Pattern

Create agents with different configurations:

from agent_factory import agent_factory, AgentType

# Use default configuration
agent = agent_factory.create_agent(
    agent_type=AgentType.GENERAL,
    model=model,
    tools=tools,
    state=state
)

# Register custom configuration
agent_factory.register_config(AgentConfig(
    agent_type=AgentType.SPECIALIZED,
    system_prompt="You are a specialized assistant...",
    tool_names=["tool1", "tool2"],  # Filter tools
    model_settings={"temperature": 0.0}
))

2. Tool Registration

Register tools with metadata:

from tool_registry import tool_registry, ToolCategory

@tool_registry.register(
    name="search_database",
    category=ToolCategory.DATA,
    description="Search the database for records",
    requires_approval=False,
    tags={"database", "search"}
)
async def search_database(query: str) -> str:
    """Search database with query"""
    return f"Results for: {query}"

3. Dependency Injection

Tools with service dependencies:

# Define tool with service parameter
@tool_registry.register(...)
async def query_db(db_service: DatabaseService, query: str) -> str:
    """Query database (db_service injected automatically)"""
    return await db_service.execute(query)

# ToolCollection binds the service
@dataclass
class ToolCollection:
    database_service: DatabaseService

    def get_all_tools(self):
        # Automatically binds db_service to tools
        # LLM only sees: query_db(query: str)
        return self._create_bound_tools()

See references/dependency-injection.md for complete guide

4. Streaming Responses

Stream text with tool call tracking:

async def stream_chat(self, prompt: str) -> AsyncIterable[str]:
    """Stream agent responses"""
    agent = self._create_agent()

    async with agent.run_stream(prompt) as result:
        async for chunk in result.stream_text(delta=True):
            if chunk:
                yield chunk
                await asyncio.sleep(0)  # Force flush

See references/streaming.md for SSE implementation

5. Multi-Provider Support

Switch between LLM providers:

from model_provider import ModelProvider

# Anthropic
model = ModelProvider.ANTHROPIC.create(
    model_name="claude-3-5-sonnet-20241022",
    api_key="sk-ant-..."
)

# OpenAI
model = ModelProvider.OPENAI.create(
    model_name="gpt-4",
    api_key="sk-..."
)

# Ollama (local)
model = ModelProvider.OLLAMA.create(
    model_name="llama3.2",
    base_url="http://localhost:11434/v1"
)

See references/providers.md for all providers

Common Workflows

Building a Web Service

  1. Scaffold project with web example:
python scripts/scaffold_agent.py my_service --web
  1. Customize service.py with your business logic
  2. Add tools in tools.py:
@tool_registry.register(...)
async def my_tool(param: str) -> str:
    return f"Processed: {param}"
  1. Update example_fastapi.py with your endpoints
  2. Run:
uvicorn example_fastapi:app --reload

Building a CLI Application

  1. Scaffold project with CLI example:
python scripts/scaffold_agent.py my_cli --cli
  1. Customize agent configuration in agent_factory.py
  2. Add tools for your domain
  3. Run:
python example_cli.py

Adding Service Dependencies

  1. Define your service:
@dataclass
class MyService:
    config: dict

    async def process(self, data: str) -> str:
        return f"Processed: {data}"
  1. Add tools using the service:
@tool_registry.register(...)
async def process_data(service: MyService, data: str) -> str:
    return await service.process(data)
  1. Update ToolCollection:
@dataclass
class ToolCollection:
    my_service: MyService

    def get_all_tools(self):
        # Automatically binds my_service
        return self._create_bound_tools()
  1. Initialize in service layer:
def _create_tools(self):
    my_service = MyService(config={...})
    return ToolCollection(my_service=my_service)

Implementing Streaming with SSE

  1. Define SSE message types in schema.py:
class SSEChunkMessage(BaseModel):
    type: Literal["chunk"] = "chunk"
    content: str
  1. Update service.py to yield SSE messages:
async def stream_chat(self, prompt: str):
    async with agent.run_stream(prompt) as result:
        async for chunk in result.stream_text(delta=True):
            yield SSEChunkMessage(content=chunk).model_dump_json()
            await asyncio.sleep(0)
  1. Add SSE wrapper in utils.py:
async def wrap_sse_stream(source):
    async for chunk in source:
        yield f"data: {chunk}\n\n"
        await asyncio.sleep(0)
  1. Use in FastAPI:
@app.post("/chat")
async def chat(prompt: str):
    text_stream = service.stream_chat(prompt)
    sse_stream = wrap_sse_stream(text_stream)
    return StreamingResponse(
        sse_stream,
        media_type="text/event-stream"
    )

Reference Documentation

For detailed implementation guides:

  • architecture.md - Complete architectural patterns, component responsibilities, data flow, and extension points
  • dependency-injection.md - Deep dive into DI pattern with signature manipulation, multiple services, and testing
  • streaming.md - Streaming implementation, SSE formatting, tool call tracking, and client integration
  • providers.md - Multi-provider support, configuration, model selection, and cost optimization

Customization Guide

Adding New Agent Types

  1. Define enum value in agent_factory.py:
class AgentType(str, Enum):
    GENERAL = "general"
    SPECIALIZED = "specialized"
  1. Register configuration:
agent_factory.register_config(AgentConfig(
    agent_type=AgentType.SPECIALIZED,
    system_prompt="Custom prompt...",
    tool_names=["specific_tool"],
    model_settings={"temperature": 0.0}
))

Adding New Tool Categories

  1. Extend ToolCategory in tool_registry.py:
class ToolCategory(str, Enum):
    UTILITY = "utility"
    DATA = "data"
    CUSTOM = "custom"  # New category
  1. Register tools with new category:
@tool_registry.register(
    name="custom_tool",
    category=ToolCategory.CUSTOM,
    description="Custom functionality"
)
async def custom_tool() -> str:
    return "Custom result"

Implementing Custom State Storage

Replace in-memory storage with Redis/DB:

class RedisStateStore(StateStore):
    def __init__(self, redis_client):
        self.redis = redis_client

    async def save(self, state: AgentState):
        await self.redis.set(
            state.conversation_id,
            state.to_json(),
            ex=86400
        )

    async def load(self, conversation_id: str):
        data = await self.redis.get(conversation_id)
        return AgentState.from_json(data) if data else None

Best Practices

  1. Use environment variables for configuration (API keys, model names)
  2. Implement proper error handling in tools and service layer
  3. Set usage limits to prevent infinite tool loops (UsageLimits(request_limit=10))
  4. Force flush when streaming with await asyncio.sleep(0)
  5. Track tool execution by monitoring result.all_messages()
  6. Test with multiple providers to ensure compatibility
  7. Use type hints throughout for better IDE support
  8. Log important events for debugging and monitoring
  9. Validate tool inputs with Pydantic models
  10. Handle state persistence properly for conversation continuity

Troubleshooting

Tools not being called:

  • Check tool descriptions are clear
  • Verify tool signatures are correct
  • Ensure tools are registered before agent creation
  • Check provider supports function calling

Streaming not real-time:

  • Add await asyncio.sleep(0) after each yield
  • Check SSE headers (disable buffering)
  • Verify client is consuming stream properly

Service dependencies not working:

  • Verify first parameter type annotation matches service type
  • Check _bind_service is called for the tool
  • Ensure signature is updated after binding

State not persisting:

  • Verify state_store.save() is called after response
  • Check state store implementation
  • Ensure conversation_id is passed correctly

Resources

scripts/

scaffold_agent.py - Generates complete agent project structure with all core modules, examples, and configuration files. Run with --minimal, --web, or --cli flags to customize output.

references/

Detailed implementation guides:

  • architecture.md - Layered architecture, component responsibilities, design patterns
  • dependency-injection.md - Service injection pattern with signature manipulation
  • streaming.md - Real-time streaming, SSE, tool call tracking
  • providers.md - Multi-provider configuration and usage

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

27.95%
按下载量换算41

Gemini CLI

23.36%
按下载量换算34

Antigravity

17.55%
按下载量换算26

OpenCode

12.93%
按下载量换算19

windsurf

7.9%
按下载量换算12

github-copilot

3.11%
按下载量换算5

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

未通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills