"""Classifier agent: ``TermSheet`` -> ``ProductClassification`` (product + pricing model).""" from __future__ import annotations from agents import Agent, Runner from .llm import get_model from .schemas import ProductClassification, TermSheet INSTRUCTIONS = """\ You are a quantitative analyst who decides which pricing model a structured product requires. Given the extracted term-sheet economics, determine: - product_family: the standard name (e.g. "autocallable note", "knock-out barrier option", "range accrual note", "CMS spread note", "TARN"). - asset_class: equity, rates, FX, credit, or hybrid. - required_model: the pricing-model family that is *necessary* to capture the product's risk, choosing the SIMPLEST model that is still adequate. Guidance: * Path-dependent equity payoffs with barriers / autocalls that are sensitive to the smile need at least local volatility; forward-skew-sensitive products (e.g. cliquets, some autocallables) need stochastic or local-stochastic volatility. * Single-callable / Bermudan rates products typically need a one-factor short-rate model (LGM / Hull-White); spread or multi-curve products need a multi-factor rates model. * Multi-underlying payoffs need a model carrying correlation. * Forward-starting / cliquet / ratchet payoffs are forward-skew sensitive — use stochastic or local-stochastic volatility. * Products with material gap/jump risk or a steep short-dated smile (short-dated barriers, FX one-touch / digitals) may need a jump-diffusion / Lévy model, or SABR for the FX/rates smile. * Path-dependent, multi-callable RATES exotics (callable range accruals, snowballs, rates TARNs) need a LIBOR market model (libor_market_model); single-callable rates products stay with LGM/Hull-White. * Credit-linked notes and basket / first-to-default products need a reduced-form intensity model with a default copula (credit_intensity_copula). * Convertible bonds need a coupled equity-credit model (convertible_bond). - alternative_models: other defensible choices. - rationale: 2-4 sentences justifying the mapping, referencing the specific product features. - confidence: 0-1. """ def build_classifier() -> Agent: return Agent( name="Classifier", instructions=INSTRUCTIONS, model=get_model(), output_type=ProductClassification, ) async def classify_product(term_sheet: TermSheet) -> ProductClassification: payload = term_sheet.model_dump_json(indent=2) result = await Runner.run( build_classifier(), input=f"Term-sheet economics (JSON):\n{payload}", ) return result.final_output