from pydantic import BaseModel, Field
from typing import List
from seekrai import SeekrFlow
# Define nested objects first
class ReviewerInfo(BaseModel):
name: str
verified_purchase: bool
review_date: str
class ProductSpecs(BaseModel):
brand: str
model: str
price: float
category: str
# Main object that includes nested objects
class ProductReview(BaseModel):
product_name: str = Field(description="The full product name as listed")
specs: ProductSpecs = Field(description="Technical specifications of the product")
reviewer: ReviewerInfo = Field(description="Information about the reviewer")
pros: List[str] = Field(description="List of positive aspects, maximum 3 items")
cons: List[str] = Field(description="List of negative aspects, maximum 3 items")
recommended: bool = Field(description="Whether the reviewer recommends this product")
# Use structured output with your agent
result = client.agents.runs.run(
agent_id="your-agent-id",
thread_id=thread.id,
response_format=ProductReview
)
# Agent will return nested data matching this structure:
# {
# "product_name": "Wireless Headphones",
# "specs": {
# "brand": "Sony",
# "model": "WH-1000XM4",
# "price": 299.99,
# "category": "Electronics"
# },
# "reviewer": {
# "name": "John Smith",
# "verified_purchase": true,
# "review_date": "2024-01-15"
# },
# "pros": ["Great sound quality", "Long battery life"],
# "cons": ["Expensive", "Heavy"],
# "recommended": true
# }