Jab hum AI agent banate hain, to uska jawab aksar free text hota hai. Example:
Agent Reply: "The weather in Karachi is sunny, 32°C."
Lekin agar hume ye data structured form me chahiye (jaise JSON ya object), to text parsing mushkil ho jata hai.
Agents SDK (jaise OpenAI Agents) me tum output_type define kar sakte ho. Ye batata hai ki agent ka output kis structure me ho.
Aur uske liye Python ka dataclass ek simple aur powerful option hai.
@dataclass
class WeatherReport:
city: str
temperature: float
condition: str
weather_agent = Agent(
name="Weather Agent",
instructions="Provide weather details for a given city.",
output_type=WeatherReport
)
Structured Data – Output ko parse karna easy ho jata hai.
Validation – Agar agent galat type ka data bheje to error aayega.
Interoperability – Direct DB entry, API response, ya dashboard me use kar sakte ho.
-
Normal agent output = jaise ek banda tumhe kahani suna de.
-
output_type + dataclass = jaise banda tumhe form fill karke de (har field clear aur fix jagah pe). "# Agent_Output_type" "# Agent_Output_type" "# Agent_Output_type"