๊ฐ€์ž… ํ›„ ์ดˆ๋Œ€ ๋งํฌ๋ฅผ ๊ณต์œ ํ•˜๋ฉด ๋™์˜์ƒ ์žฌ์ƒ ๋ฐ ์ดˆ๋Œ€ ๋ณด์ƒ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture
๊ฐ€์ž… May 2026
240 ํŒ”๋กœ์ž‰ ์ค‘    207 ํŒฌ
# Practical and Useful Patterns for OpenAI Agent SDK ๐ŸŒ Stop praying that your LLM returns valid JSON. With output_type, you get type-safe structured data every time -- no more broken JSON headaches. Simply specify a Pydantic model, dataclass, or TypedDict as output_type, and your agent's output is automatically validated structured data. ๐Ÿ“Œ Title: Agents -- Output types ๐Ÿ”— URL: ๐Ÿงฉ Overview Setting the `output_type` parameter on an Agent enforces Structured Outputs from the LLM. You can specify a Pydantic BaseModel, dataclass, or TypedDict, and the output is automatically parsed and validated. This lets downstream code safely work with structured data. When output_type is set, the agent's final output becomes an object of the specified type rather than plain text. ๐Ÿ›  How to Use Define a `CalendarEvent` class extending `BaseModel` with fields `name: str`, `date: str`, and `participants: list[str]`, then set `output_type=CalendarEvent` on the `Agent`. When you call ` ...)`, ` is returned as a `CalendarEvent` instance, allowing type-safe access to ` and `event.participants`. ๐Ÿ— Practical Usage Patterns **Extract Calendar Events from Emails and Register via API** A pipeline that passes structured output directly to an external API. Run ` email_body)` to get ` as a `CalendarEvent`, then pass it directly to `calendar_api.create_event(title= date= attendees=event.participants)` without any manual parsing. **Enum Output for Branch Orchestration** Return classification as an enum and use code to deterministically branch. Define `TicketCategory(str, Enum)` with values `billing`, `technical`, and `general`, then create a `Classification(BaseModel)` with `category: TicketCategory` and `confidence: float`. Set `output_type=Classification` on the `Agent`, run it, and use a `match` statement on ` to deterministically route to `handoff_to_billing`, `handoff_to_engineering`, or `handoff_to_general`. **Type Guarantees for Business-Critical Processing** For workflows where broken JSON is absolutely unacceptable, Structured Outputs serve as a safety net. Define `InvoiceData(BaseModel)` with fields `invoice_number: str`, `amount: float`, `currency: str`, `due_date: str`, and `line_items: list[dict[str, str | float]]`, then set `output_type=InvoiceData` on the `Agent` to guarantee type-safe structured extraction of invoice data. ๐Ÿ’ก Use Cases ๐Ÿ“ง Extract CalendarEvent(name, date, participants) from emails and auto-register via calendar API ๐Ÿท Classify support tickets with Enum output and deterministically route by category in code ๐Ÿ’ฐ Type-safe structured extraction from invoices and contracts where broken JSON is unacceptable ๐Ÿ“Š Convert free-text survey responses into structured data and feed directly into analytics pipelines โš ๏ธ Caveats - When output_type is set, the agent's final output is always that type. It cannot return plain text responses, so omit output_type if you need text replies. - Overly complex nested structures can reduce LLM output accuracy. Keep structures as flat as possible. - Use Optional fields appropriately to allow None when the LLM cannot find certain information. โœจ With output_type, you can plug LLM outputs directly into business logic. Move from "parse and pray" to "guarantee with types" -- a significant step forward in agent development! #OpenAIAgentSDK# #AIAgent#
๋” ๋ณด๊ธฐ