Skip to content

Mohibalikhan/Agent_Output_type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Agents as Output_type in Sdk

🔹 Step 1: Problem samjho

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.

🔹 Step 2: Solution → output_type

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.

1. Define structured output with dataclass

@dataclass
class WeatherReport:
city: str
temperature: float
condition: str

2. Agent with output_type

weather_agent = Agent(
    name="Weather Agent",
    instructions="Provide weather details for a given city.",
    output_type=WeatherReport
)

👉 Ab agent hamesha apna jawab WeatherReport ke structure me dega — clean, reliable, structured.

🔹 Step 4: Benefits

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.

🔹 Step 5: Simple Analogy

  • 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"

About

Dataclasses as Output Type in AI Agents

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages