Skip to main content
Loading navigation
Back to prompt library

Initialize Pydantic AI Energy Attribution Agent

Linked challenge: Pydantic AI & Claude 4 Sonnet Telemetry & Token Power Attribution Engine

Prompt source

implementation14 lines3 sectionsNo variables0 checklist items
from pydantic import BaseModel, Field
from pydantic_ai import Agent

class TelemetryReport(BaseModel):
    tenant_id: str
    total_joules: float = Field(description="Total energy consumed in Joules")
    joules_per_token: float = Field(description="Energy consumed per generated token")
    cost_usd: float = Field(description="Electricity cost calculation")
    attribution_error_pct: float

# Instantiate agent with Claude 4 Sonnet model backend
agent = Agent(
    'anthropic:claude-3-5-sonnet-latest',
    result_type=TelemetryReport,
    system_prompt="You are a hardware telemetry engineer calculating exact hardware energy attribution per LLM token."
)