Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:PrefectHQ Prefect PrefectAgent Wrapper

From Leeroopedia


Metadata
Sources Prefect, pydantic-ai Prefect
Domains AI_Agents, Fault_Tolerance
Last Updated 2026-02-09 00:00 GMT

Overview

Concrete wrapper for adding Prefect durable execution to pydantic-ai agents provided by the pydantic-ai library.

Description

PrefectAgent wraps a pydantic-ai Agent to provide durable execution. It accepts the base agent plus TaskConfig objects for model (LLM) calls and tool calls. Each LLM interaction becomes a retryable Prefect task; each tool call becomes a separate retryable task. This is a Wrapper Doc since PrefectAgent is from the external pydantic-ai package.

Code Reference

PrefectAgent(
    agent,
    model_task_config=TaskConfig(
        retries=3,
        retry_delay_seconds=[1.0, 2.0, 4.0],
        timeout_seconds=60.0,
    ),
    tool_task_config=TaskConfig(
        retries=2,
        retry_delay_seconds=[0.5, 1.0],
    ),
)

I/O Contract

Inputs

  • agent (Agent, required) — Base pydantic-ai agent
  • model_task_config (TaskConfig, optional) — Retry/timeout configuration for LLM calls
  • tool_task_config (TaskConfig, optional) — Retry/timeout configuration for tool calls

Outputs

  • PrefectAgent[DepsType, OutputType] — Wrapped agent with durable execution

Usage Example

from pydantic_ai import Agent
from pydantic_ai.durable_exec.prefect import PrefectAgent, TaskConfig

agent = Agent("openai:gpt-4o", output_type=DataAnalysis, deps_type=pd.DataFrame, tools=[...])

durable_agent = PrefectAgent(
    agent,
    model_task_config=TaskConfig(retries=3, retry_delay_seconds=[1.0, 2.0, 4.0], timeout_seconds=60.0),
    tool_task_config=TaskConfig(retries=2, retry_delay_seconds=[0.5, 1.0]),
)

# Use like the original agent
result = await durable_agent.run("Analyze this dataset.", deps=df)
print(result.output)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment