{"id":27685,"date":"2026-08-14T10:35:41","date_gmt":"2026-08-14T10:35:41","guid":{"rendered":"https:\/\/umang.pk\/2026\/08\/14\/pydantic-ai-%da%a9%d8%a7-%d8%a7%d8%b3%d8%aa%d8%b9%d9%85%d8%a7%d9%84-%da%a9%d8%b1%d8%aa%db%92-%db%81%d9%88%d8%a6%db%92-%d9%be%d8%b1%d9%88%da%88%da%a9%d8%b4%d9%86-%da%af%d8%b1%db%8c%da%88-%d8%a7%db%8c\/"},"modified":"2026-08-14T10:35:41","modified_gmt":"2026-08-14T10:35:41","slug":"pydantic-ai-%da%a9%d8%a7-%d8%a7%d8%b3%d8%aa%d8%b9%d9%85%d8%a7%d9%84-%da%a9%d8%b1%d8%aa%db%92-%db%81%d9%88%d8%a6%db%92-%d9%be%d8%b1%d9%88%da%88%da%a9%d8%b4%d9%86-%da%af%d8%b1%db%8c%da%88-%d8%a7%db%8c","status":"publish","type":"post","link":"https:\/\/umang.pk\/ur\/2026\/08\/14\/pydantic-ai-%da%a9%d8%a7-%d8%a7%d8%b3%d8%aa%d8%b9%d9%85%d8%a7%d9%84-%da%a9%d8%b1%d8%aa%db%92-%db%81%d9%88%d8%a6%db%92-%d9%be%d8%b1%d9%88%da%88%da%a9%d8%b4%d9%86-%da%af%d8%b1%db%8c%da%88-%d8%a7%db%8c\/","title":{"rendered":"Pydantic AI \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u06af\u0631\u06cc\u0688 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06cc\u0633\u06d2 \u0628\u0646\u0627\u06cc\u0627 \u062c\u0627\u0626\u06d2\u06d4"},"content":{"rendered":"\n<div id=\"\">\n<p>\u0645\u0642\u0627\u0645\u06cc LLM SDK \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 AI \u0627\u06cc\u062c\u0646\u0679\u0648\u06ba \u06a9\u06cc \u062a\u0639\u0645\u06cc\u0631 \u0627\u0633 \u0648\u0642\u062a \u062a\u06a9 \u067e\u0631\u0648\u0679\u0648 \u0679\u0627\u0626\u067e\u0646\u06af \u06a9\u06d2 \u0644\u06cc\u06d2 \u0628\u06c1\u062a\u0631\u06cc\u0646 \u06c1\u06d2 \u062c\u0628 \u062a\u06a9 \u06a9\u06c1 \u0622\u067e \u06a9\u0648 \u0633\u0627\u062e\u062a\u06cc \u0622\u0624\u0679 \u067e\u0679\u060c \u0642\u0627\u0628\u0644 \u062c\u0627\u0646\u0686 \u06a9\u0648\u0688\u060c \u0627\u0648\u0631 \u067e\u06cc\u062f\u0627\u0648\u0627\u0631\u06cc \u0627\u0633\u062a\u062d\u06a9\u0627\u0645 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u0646\u06c1 \u06c1\u0648\u06d4<\/p>\n<p>\u062e\u0644\u0627 \u062e\u0648\u062f \u06a9\u0648 \u067e\u06cc\u0634\u06cc\u0646 \u06af\u0648\u0626\u06cc \u06a9\u06d2 \u0637\u0631\u06cc\u0642\u0648\u06ba \u0633\u06d2 \u0638\u0627\u06c1\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0628 \u062c\u0628 \u06a9\u06c1 \u0622\u067e \u06a9\u0627 \u0646\u0648\u0679 \u0628\u06a9 \u06a9\u0648\u0688 \u06a9\u0627\u0645 \u06a9\u0631 \u0631\u06c1\u0627 \u06c1\u06d2\u060c \u0622\u0626\u06cc\u06d2 \u0627\u0633\u06d2 \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0645\u06cc\u06ba \u0645\u0646\u062a\u0642\u0644 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u067e\u06cc\u0686 \u06a9\u0631\u0646\u0627 \u0634\u0631\u0648\u0639 \u06a9\u0631\u06cc\u06ba\u06d4 json.loads \u06a9\u06d2 \u0627\u0631\u062f \u06af\u0631\u062f \u0627\u06cc\u06a9 \u06a9\u0648\u0634\u0634\/exc\u060c \u0645\u0627\u0631\u06a9 \u0688\u0627\u0624\u0646 \u06c1\u06cc\u062c\u0632 \u06a9\u0648 \u06c1\u0679\u0627\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0645\u062f\u062f\u06af\u0627\u0631\u060c \u0641\u06cc\u0644\u0688 \u06a9\u06cc \u0627\u0642\u0633\u0627\u0645 \u06a9\u0648 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0686\u0646\u062f \u0627\u06af\u0631 \u0628\u06cc\u0627\u0646\u0627\u062a\u060c \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0644\u0648\u067e\u060c \u0627\u0648\u0631 \u06a9\u0627\u0644 \u0627\u06cc\u0628\u0644\u0632 \u067e\u0631 \u0679\u0648\u0644 \u06a9\u06d2 \u0646\u0627\u0645\u0648\u06ba \u06a9\u0627 \u0646\u0642\u0634\u06c1 \u0628\u0646\u0627\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0688\u0633\u067e\u06cc\u0686 \u0641\u0646\u06a9\u0634\u0646\u06d4 \u0627\u0646 \u0645\u06cc\u06ba \u0633\u06d2 \u06a9\u0648\u0626\u06cc \u0628\u06be\u06cc \u0627\u067e\u0646\u06d2 \u0622\u067e \u0645\u06cc\u06ba \u0645\u0634\u06a9\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be\u060c \u0648\u06c1 \u06a9\u0648\u0688 \u0628\u06cc\u0633 \u06a9\u0627 \u0628\u0691\u0627 \u062d\u0635\u06c1 \u0628\u0646 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0635\u0644 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06cc \u0645\u0646\u0637\u0642 \u06af\u0644\u0648 \u06a9\u06d2 \u0646\u06cc\u0686\u06d2 \u063a\u0627\u0626\u0628 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633 \u0645\u0636\u0645\u0648\u0646 \u0645\u06cc\u06ba\u060c \u06c1\u0645 \u0686\u06be \u0645\u0633\u0627\u0626\u0644 \u06a9\u0648 \u0627\u0633 \u062a\u0631\u062a\u06cc\u0628 \u0633\u06d2 \u062f\u06cc\u06a9\u06be\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u0648\u06c1 \u06a9\u0633 \u062a\u0631\u062a\u06cc\u0628 \u0633\u06d2 \u067e\u06cc\u062f\u0627 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u06cc\u06c1 \u0638\u0627\u06c1\u0631 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 Pydantic AI \u06a9\u0633 \u0637\u0631\u062d \u06a9\u0648\u0688 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u06c1\u0631 \u0645\u0633\u0626\u0644\u06d2 \u06a9\u0648 \u062d\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<ol>\n<li>\n<p>\u063a\u06cc\u0631 \u0633\u0627\u062e\u062a\u06c1 \u0622\u0624\u0679 \u067e\u0679 \u06a9\u0648 \u06a9\u0645\u0632\u0648\u0631 \u062a\u062c\u0632\u06cc\u06c1 \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06d2\u06d4 \u0622\u0624\u0679 \u067e\u0679 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0627\u0646\u06af\u0631\u06cc\u0632\u06cc \u067e\u0631\u0627\u0645\u067e\u0679 \u0633\u0679\u0631\u0646\u06af \u0645\u06cc\u06ba \u06c1\u06d2 \u062c\u0648 \u0627\u0633 \u0644\u063a\u062a \u0633\u06d2 \u0648\u0627\u0628\u0633\u062a\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u062c\u0633 \u06a9\u06cc \u0622\u067e \u06a9\u0648\u0688 \u06a9\u06cc \u062a\u0648\u0642\u0639 \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<li>\n<p>\u0679\u0648\u0644 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641\u06cc\u06ba \u0628\u0648\u0627\u0626\u0644\u0631 \u067e\u0644\u06cc\u0679 \u0633\u06d2 \u0628\u06be\u0631\u06cc \u06c1\u0648\u0626\u06cc \u06c1\u06cc\u06ba\u06d4 \u06c1\u0627\u062a\u06be \u0633\u06d2 \u0644\u06a9\u06be\u06d2 \u06c1\u0648\u0626\u06d2 JSON \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u06cc 70 \u0644\u0627\u0626\u0646\u0648\u06ba \u062a\u06a9 \u0627\u0648\u0631 \u062a\u06cc\u0646 \u0679\u0648\u0644\u0632 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0688\u0633\u067e\u06cc\u0686 \u06a9\u0648\u0688 \u06a9\u06d2 \u0633\u0627\u062a\u06be\u060c \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0627\u0648\u0631 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u06d2 \u062f\u0633\u062a\u062e\u0637\u0648\u06ba \u06a9\u0648 \u0645\u0637\u0627\u0628\u0642\u062a \u067e\u0630\u06cc\u0631 \u0631\u06a9\u06be\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0686\u06be \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<li>\n<p>\u0631\u0646 \u0679\u0627\u0626\u0645 \u0633\u06cc\u0627\u0642 \u0648 \u0633\u0628\u0627\u0642 \u06a9\u0648 \u0645\u0646\u062a\u0642\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u0635\u0627\u0641 \u0637\u0631\u06cc\u0642\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u062c\u0628 \u0627\u06cc\u06a9 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06a9\u0633\u06cc \u0679\u0648\u0644 \u06a9\u0648 \u06a9\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u06cc\u06c1 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u0646\u06a9\u0634\u0646 \u06cc\u0627 \u06cc\u0648\u0632\u0631 \u0622\u0626\u06cc \u0688\u06cc \u06a9\u0648 \u0639\u0627\u0644\u0645\u06cc \u06cc\u0627 \u0628\u0646\u062f\u0634 \u062a\u06a9 \u067e\u06c1\u0646\u0686\u0627\u0626\u06d2 \u0628\u063a\u06cc\u0631 \u067e\u0627\u0633 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u0627\u06d4<\/p>\n<\/li>\n<li>\n<p>\u0679\u06cc\u0633\u0679 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u062d\u0642\u06cc\u0642\u06cc LLM \u06a9\u0627\u0644 \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06d2\u06d4 \u062a\u0645\u0627\u0645 \u0679\u06cc\u0633\u0679\u0648\u06ba \u067e\u0631 \u067e\u06cc\u0633\u06c1 \u062e\u0631\u0686 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u0633\u06cc\u06a9\u0646\u0688 \u0644\u06af\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0646\u06cc\u0679 \u0648\u0631\u06a9 \u062a\u06a9 \u0631\u0633\u0627\u0626\u06cc \u062f\u0631\u06a9\u0627\u0631 \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0641\u0644\u06cc\u06a9\u0633 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<li>\n<p>\u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u0645\u0646\u0637\u0642 \u062f\u0633\u062a\u06cc \u06c1\u06d2\u06d4 \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u0622\u067e \u0627\u067e\u0646\u06d2 \u062a\u0639\u06cc\u0646\u0627\u062a \u06a9\u0631\u062f\u06c1 \u06c1\u0631 \u0627\u06cc\u062c\u0646\u0679 \u067e\u0631 \u0648\u06c1\u06cc \u062a\u0648\u062b\u06cc\u0642\/\u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634\/\u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u067e\u06cc\u0679\u0631\u0646 \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0628\u0646\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<li>\n<p>\u0645\u0627\u0688\u0644\u0632 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u0627\u067e\u0646\u06d2 \u0627\u0646\u0679\u06cc\u06af\u0631\u06cc\u0634\u0646 \u06a9\u0648\u0688 \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u06a9\u06be\u0646\u0627\u06d4 \u06c1\u0631 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0646\u0646\u062f\u06c1 \u06a9\u06cc SDK \u0638\u0627\u06c1\u0631\u06cc \u0634\u06a9\u0644\u060c \u0679\u0648\u0644 \u0641\u0627\u0631\u0645\u06cc\u0679\u060c \u0627\u0648\u0631 \u0631\u062f\u0639\u0645\u0644 \u06a9\u0627 \u0688\u06be\u0627\u0646\u0686\u06c1 \u0645\u062e\u062a\u0644\u0641 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<\/ol>\n<p>\u06c1\u0645 \u0627\u06cc\u06a9 \u0686\u0644\u062a\u06cc \u06c1\u0648\u0626\u06cc \u0645\u062b\u0627\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba \u06af\u06d2: \u0631\u0633\u06cc\u062f \u062a\u062c\u0632\u06cc\u06c1 \u0627\u06cc\u062c\u0646\u0679\u06d4 \u06cc\u06c1 \u0627\u0635\u0644 \u0631\u0633\u06cc\u062f \u06a9\u0627 \u0645\u062a\u0646 \u0644\u06cc\u062a\u0627 \u06c1\u06d2 (\u062a\u0635\u0648\u06cc\u0631 \u06a9\u0648 \u0645\u062a\u0646 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0627\u0633\u06a9\u06cc\u0646 \u06a9\u0631\u06a9\u06d2 \u062d\u0627\u0635\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2)\u060c \u0645\u0631\u0686\u0646\u0679 \u06a9\u06cc\u0679\u06cc\u06af\u0631\u06cc\u0632 \u0627\u0648\u0631 \u0627\u06cc\u06a9\u0633\u0686\u06cc\u0646\u062c \u0631\u06cc\u0679 \u062f\u06cc\u06a9\u06be\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0679\u0648\u0644 \u06a9\u0648 \u06a9\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u0622\u0628\u0627\u062f\u06cc \u0648\u0627\u0644\u0627 \u062e\u0644\u0627\u0635\u06c1 (\u0645\u0631\u0686\u0646\u0679\u060c \u062e\u0631\u0686 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0632\u0645\u0631\u06c1\u060c \u0622\u0626\u0679\u0645\u0627\u0626\u0632\u0688 \u0628\u0631\u06cc\u06a9 \u0688\u0627\u0624\u0646 \u0627\u0648\u0631 \u0627\u0639\u062a\u0645\u0627\u062f \u06a9\u0627 \u0627\u0633\u06a9\u0648\u0631) \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0633\u06d2 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u0628\u062c\u0679 \u0688\u06cc\u0634 \u0628\u0648\u0631\u0688 \u06cc\u0627 \u0627\u062e\u0631\u0627\u062c\u0627\u062a \u06a9\u06d2 \u0679\u0648\u0644 \u0645\u06cc\u06ba \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0633\u0679\u0631\u06a9\u0686\u0631\u0688 \u0627\u0646 \u067e\u0679\u060c \u0633\u0648\u0627\u0644\u0627\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0679\u0648\u0644 \u06a9\u0627\u0644\u0632\u060c \u0688\u0627\u0624\u0646 \u0627\u0633\u0679\u0631\u06cc\u0645 \u0633\u0633\u0679\u0645\u0632 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0679\u0627\u0626\u067e \u0634\u062f\u06c1 \u0622\u0624\u0679 \u067e\u0679\u06d4 \u0648\u06c1 \u0645\u0633\u0627\u0626\u0644 \u062c\u0648 \u0633\u0637\u062d\u06cc \u0637\u0648\u0631 \u067e\u0631 \u06a9\u0627\u0641\u06cc \u0639\u0627\u0645 \u0645\u0639\u0644\u0648\u0645 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba \u0648\u06c1 \u0645\u0627\u0646\u0648\u0633 \u0645\u0639\u0644\u0648\u0645 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0622\u062e\u0631 \u0645\u06cc\u06ba\u060c \u0622\u067e \u06a9\u06d2 \u067e\u0627\u0633 \u0679\u0627\u0626\u067e \u0634\u062f\u06c1 \u0622\u0624\u0679 \u067e\u0679 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u06cc\u06a9 \u0648\u0631\u06a9\u0646\u06af \u0627\u06cc\u062c\u0646\u0679\u060c \u0627\u0646\u062d\u0635\u0627\u0631 \u0627\u0646\u062c\u06cc\u06a9\u0634\u0646 \u0679\u0648\u0644\u060c \u062e\u0648\u062f\u06a9\u0627\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634\u0648\u06ba \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06a9\u0627\u0631\u0648\u0628\u0627\u0631\u06cc \u0627\u0635\u0648\u0644 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642\u060c \u0627\u0648\u0631 \u0628\u063a\u06cc\u0631 \u06a9\u0633\u06cc API \u06a9\u0644\u06cc\u062f \u06a9\u06d2 \u0645\u0644\u06cc \u0633\u06cc\u06a9\u0646\u0688 \u0645\u06cc\u06ba \u0686\u0644\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0679\u06cc\u0633\u0679\u0648\u06ba \u06a9\u0627 \u0627\u06cc\u06a9 \u0645\u062c\u0645\u0648\u0639\u06c1 \u06c1\u0648\u06af\u0627\u06d4<\/p>\n<h2 id=\"heading-table-of-contents\">\u0627\u0646\u0688\u06cc\u06a9\u0633<\/h2>\n<h2 id=\"heading-a-quick-word-on-pydantic-ai\">Pydantic AI \u06a9\u06cc \u0627\u06cc\u06a9 \u0645\u062e\u062a\u0635\u0631 \u062a\u0641\u0635\u06cc\u0644<\/h2>\n<p>Pydantic \u0627\u06cc\u06a9 Python \u067e\u0631 \u0645\u0628\u0646\u06cc \u0688\u06cc\u0679\u0627 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u0644\u0627\u0626\u0628\u0631\u06cc\u0631\u06cc \u06c1\u06d2\u06d4 \u0622\u067e \u0627\u067e\u0646\u06d2 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u0648 \u0679\u0627\u0626\u067e \u0627\u0634\u0627\u0631\u06d2 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u06cc\u06a9 \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 \u0627\u0632\u06af\u0631 \u06a9\u0644\u0627\u0633 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0628\u06cc\u0627\u0646 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 Pydantic \u0627\u0633\u06d2 \u0631\u0646 \u0679\u0627\u0626\u0645 \u067e\u0631 \u0646\u0627\u0641\u0630 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u0639\u0646\u06cc\u060c \u06cc\u06c1 \u0627\u0646 \u0642\u0633\u0645\u0648\u06ba \u06a9\u0648 \u0645\u062c\u0628\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0648 \u0627\u06c1\u0644 \u06c1\u06cc\u06ba\u060c \u062c\u0648 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba \u0627\u0646 \u06a9\u0648 \u0645\u0633\u062a\u0631\u062f \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u060c \u0627\u0648\u0631 \u062f\u0631\u0633\u062a \u063a\u0644\u0637\u06cc \u06a9\u0648 \u0628\u0691\u06be\u0627\u062a\u06cc \u06c1\u06d2 \u062c\u0648 \u0646\u0627\u06af\u0648\u0627\u0631 \u0641\u06cc\u0644\u0688\u0632 \u06a9\u0627 \u0646\u0627\u0645 \u062f\u06cc\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-plaintext\">  from pydantic import BaseModel, Field\n\n  class Item(BaseModel):\n      name: str\n      amount: float = Field(gt=0)\n\n  Item(name=\"Espresso\", amount=\"2.50\")  # \u2192 amount=2.5, coerced\n  Item(name=\"Espresso\", amount=-1)      # \u2192 ValidationError: amount must be > 0\n<\/code><\/pre>\n<p>Pydantic AI \u0627\u06cc\u06a9 \u0627\u06cc\u062c\u0646\u0679 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06c1\u06d2 \u062c\u0648 LLM \u06a9\u06cc \u062d\u062f\u0648\u062f \u06a9\u0648 \u0633\u0646\u0628\u06be\u0627\u0644\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u0645\u0627\u0688\u0644 \u06a9\u0648 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0646\u0646\u062f\u06c1 \u06a9\u06cc \u0688\u06cc\u0641\u0627\u0644\u0679 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06cc\u06ba \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u0646\u0627\u060c \u062c\u0648 \u0648\u0627\u067e\u0633 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2 \u0627\u0633\u06d2 \u067e\u0627\u0631\u0633 \u06a9\u0631\u0646\u0627 \u0627\u0648\u0631 \u0627\u0633 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u0646\u0627\u060c \u0641\u0646\u06a9\u0634\u0646 \u06a9\u06d2 \u062f\u0633\u062a\u062e\u0637\u0648\u06ba \u0633\u06d2 \u0679\u0648\u0644 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641\u06cc\u06ba \u062a\u06cc\u0627\u0631 \u06a9\u0631\u0646\u0627\u060c \u0627\u0646\u062d\u0635\u0627\u0631 \u06a9\u0648 \u0627\u0646\u062c\u06cc\u06a9\u0634\u0646 \u0644\u06af\u0627\u0646\u0627\u060c \u0627\u0648\u0631 \u0627\u06af\u0631 \u062a\u0648\u062b\u06cc\u0642 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2 \u062a\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u0627\u06d4 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06cc \u0645\u0646\u0637\u0642 Python \u0645\u06cc\u06ba \u0631\u06a9\u06be\u06cc \u06af\u0626\u06cc \u06c1\u06d2\u06d4 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u062f\u0648 \u0637\u0631\u0641\u06c1 \u062a\u0631\u062c\u0645\u06c1 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-prerequisites\">\u0634\u0631\u0637\u06cc\u06ba<\/h2>\n<p>\u06cc\u06c1 \u0645\u0636\u0645\u0648\u0646 \u0641\u0631\u0636 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u0622\u067e \u062f\u0631\u062c \u0630\u06cc\u0644 \u0633\u06d2 \u0648\u0627\u0642\u0641 \u06c1\u06cc\u06ba:<\/p>\n<ul>\n<li>\n<p><strong>Python 3.10+<\/strong> &#8211; \u0627\u0634\u0627\u0631\u06d2 \u0679\u0627\u0626\u067e \u06a9\u0631\u06cc\u06ba\u060c \u0688\u06cc\u0679\u0627 \u06a9\u0644\u0627\u0633\u0632\u060c async\/await<\/p>\n<\/li>\n<li>\n<p><strong>LLM API \u0628\u0646\u06cc\u0627\u062f\u06cc \u0628\u0627\u062a\u06cc\u06ba<\/strong> \u2014 OpenAI\u060c Anthropic\u060c \u06cc\u0627 \u0627\u0633\u06cc \u0637\u0631\u062d \u06a9\u06d2 SDKs \u06a9\u0648 \u06a9\u0645 \u0627\u0632 \u06a9\u0645 \u0686\u0646\u062f \u06a9\u0627\u0644\u06cc\u06ba \u06a9\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>\u0627\u06cc\u062c\u0646\u0679 \u06a9\u0627 \u062a\u0635\u0648\u0631<\/strong> &#8211; \u0633\u0645\u062c\u06be\u06cc\u06ba \u06a9\u06c1 AI \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06cc\u0627 \u06c1\u06d2 (LLM + \u0679\u0648\u0644\u0632 + \u0627\u0646\u0641\u0631\u0646\u0633 \u0644\u0648\u067e)\u06d4 \u0627\u06af\u0631 \u0646\u06c1\u06cc\u06ba\u060c \u062a\u0648 AI \u0627\u06cc\u062c\u0646\u0679 &#8211; \u0628\u0644\u0688\u0631 \u06af\u0627\u0626\u06cc\u0688 \u0633\u06d2 \u0634\u0631\u0648\u0639 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<\/ul>\n<p>Pydantic AI \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06a9\u0633\u06cc \u067e\u06cc\u0634\u06af\u06cc \u062a\u062c\u0631\u0628\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u06c1\u0645 \u0632\u0645\u06cc\u0646 \u0633\u06d2 \u062a\u0639\u0645\u06cc\u0631 \u06a9\u0631\u06cc\u06ba \u06af\u06d2\u06d4<\/p>\n<h2 id=\"heading-the-problem-building-agents-without-a-framework\">\u0645\u0633\u0626\u0644\u06c1: \u0628\u063a\u06cc\u0631 \u06a9\u0633\u06cc \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06a9\u06d2 \u0627\u06cc\u062c\u0646\u0679\u0648\u06ba \u06a9\u06cc \u062a\u0639\u0645\u06cc\u0631<\/h2>\n<p>\u0627\u0646 \u0645\u0633\u0627\u0626\u0644 \u06a9\u0648 \u0628\u06c1\u062a\u0631 \u0637\u0648\u0631 \u067e\u0631 \u0627\u062c\u0627\u06af\u0631 \u06a9\u0631\u0646\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u06c1\u0645 \u0627\u06cc\u06a9 \u0686\u0644\u062a\u06cc \u06c1\u0648\u0626\u06cc \u0645\u062b\u0627\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba \u06af\u06d2 \u062c\u0633\u06d2 \u0631\u0633\u06cc\u062f \u062a\u062c\u0632\u06cc\u06c1 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06c1\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0627\u0635\u0644 \u0631\u0633\u06cc\u062f \u06a9\u0627 \u0645\u062a\u0646 \u0644\u06cc\u062a\u0627 \u06c1\u06d2 (\u062a\u0635\u0648\u06cc\u0631 \u06a9\u0648 \u0645\u062a\u0646 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0627\u0633\u06a9\u06cc\u0646 \u06a9\u0631\u06a9\u06d2 \u062d\u0627\u0635\u0644 \u06a9\u0631\u062f\u06c1 \u0645\u062a\u0646)\u060c \u0627\u062e\u0631\u0627\u062c\u0627\u062a \u06a9\u06cc \u062f\u0631\u062c\u06c1 \u0628\u0646\u062f\u06cc \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0627\u062c\u0631 \u06a9\u06cc \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u06a9\u0648 \u062a\u0644\u0627\u0634 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u0645\u0646\u0638\u0645 \u062e\u0644\u0627\u0635\u06c1 \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0622\u067e \u06a9\u0648 \u0628\u06cc\u0686\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u0627 \u0646\u0627\u0645\u060c \u0627\u062e\u0631\u0627\u062c\u0627\u062a \u06a9\u06d2 \u0632\u0645\u0631\u06d2\u060c \u0622\u0626\u0679\u0645\u0627\u0626\u0632\u0688 \u0628\u0631\u06cc\u06a9 \u0688\u0627\u0624\u0646\u060c \u0627\u0648\u0631 \u0679\u0631\u0633\u0679 \u0633\u06a9\u0648\u0631 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u0688\u0627\u0624\u0646 \u0627\u0633\u0679\u0631\u06cc\u0645 \u0633\u0633\u0679\u0645\u0632 (\u0628\u062c\u0679 \u0688\u06cc\u0634 \u0628\u0648\u0631\u0688\u0632\u060c \u0644\u0627\u06af\u062a \u06a9\u06cc \u0627\u0637\u0644\u0627\u0639 \u062f\u06cc\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0679\u0648\u0644\u0632) \u0627\u0633 \u0633\u0627\u062e\u062a\u06cc \u0622\u0624\u0679 \u067e\u0679 \u06a9\u0648 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u06cc\u06c1 \u0627\u06cc\u06a9 \u0639\u0627\u0645 \u062d\u0642\u06cc\u0642\u06cc \u062f\u0646\u06cc\u0627 \u06a9\u0627 \u0646\u0645\u0648\u0646\u06c1 \u06c1\u06d2: \u0633\u0627\u062e\u062a\u06c1 \u0627\u0646 \u067e\u0679\u060c \u0633\u0648\u0627\u0644 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0679\u0648\u0644 \u06a9\u0627\u0644\u060c \u0688\u0627\u0624\u0646 \u0627\u0633\u0679\u0631\u06cc\u0645 \u0633\u0633\u0679\u0645 \u0645\u06cc\u06ba \u0627\u0646 \u067e\u0679 \u0622\u0624\u0679 \u067e\u0679\u06d4 \u0622\u0626\u06cc\u06d2 \u0627\u06cc\u06a9 \u0646\u0638\u0631 \u0688\u0627\u0644\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u0627\u06cc\u06a9 \u062e\u0627\u0645 OpenAI SDK \u06a9\u0627\u0644 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0639\u0645\u0627\u0631\u062a \u06a9\u06cc\u0633\u06cc \u062f\u06a9\u06be\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-problem-1-unstructured-outputs-require-brittle-parsing\">\u0645\u0633\u0626\u0644\u06c1 1: \u063a\u06cc\u0631 \u0633\u0627\u062e\u062a\u06c1 \u0622\u0624\u0679 \u067e\u0679 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0645\u0632\u0648\u0631 \u062a\u062c\u0632\u06cc\u06c1 \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06d2\u06d4<\/h2>\n<p>\u0628\u0646\u06cc\u0627\u062f\u06cc \u0637\u0648\u0631 \u067e\u0631\u060c LLM \u06a9\u06d2 \u0633\u0627\u062a\u06be \u062a\u0645\u0627\u0645 \u062a\u0639\u0627\u0645\u0644\u0627\u062a \u0679\u06cc\u06a9\u0633\u0679 \u0627\u0646 \u067e\u0679\u060c \u0679\u06cc\u06a9\u0633\u0679 \u0622\u0624\u0679 \u067e\u0679 \u06c1\u06cc\u06ba\u06d4 \u0622\u067e \u06a9\u06d2 \u0645\u0627\u0688\u0644 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u067e\u0648\u0631\u0627 \u0645\u0639\u0627\u06c1\u062f\u06c1 (\u0627\u0646 \u067e\u0679 \u0688\u06cc\u0679\u0627\u060c \u0627\u06c1\u062f\u0627\u0641\u060c \u0627\u0648\u0631 \u0645\u0637\u0644\u0648\u0628\u06c1 \u0622\u0624\u0679 \u067e\u0679 \u0641\u0627\u0631\u0645\u06cc\u0679) \u0627\u06cc\u06a9 \u0679\u06cc\u06a9\u0633\u0679 \u067e\u0631\u0627\u0645\u067e\u0679 \u0645\u06cc\u06ba \u0645\u0648\u062c\u0648\u062f \u06c1\u06d2\u06d4 \u062f\u0631\u0633\u062a\u06af\u06cc \u06a9\u0648 \u0646\u0627\u0641\u0630 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0648\u0626\u06cc \u0627\u0633\u06a9\u06cc\u0645\u0627\u060c \u0679\u0627\u0626\u067e \u0633\u0633\u0679\u0645\u060c \u06cc\u0627 \u06a9\u0645\u067e\u0627\u0626\u0644\u0631 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0627\u0646\u06af\u0631\u06cc\u0632\u06cc \u0645\u06cc\u06ba \u0628\u06cc\u0627\u0646 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0622\u067e \u06a9\u06cc\u0627 \u0686\u0627\u06c1\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0627\u0645\u06cc\u062f \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u0645\u0627\u0688\u0644 \u0627\u0633 \u06a9\u06d2 \u0645\u0637\u0627\u0628\u0642 \u06c1\u0648\u06af\u0627\u06d4<\/p>\n<p>OpenAI SDK \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u06cc\u06c1\u0627\u06ba \u0627\u06cc\u06a9 \u0622\u0633\u0627\u0646 \u0639\u0645\u0644 \u06c1\u06d2: \u0633\u0633\u0679\u0645 \u067e\u0631\u0627\u0645\u067e\u0679\u0633 \u0627\u0646 \u067e\u0679 \u0633\u06cc\u0627\u0642 \u0648 \u0633\u0628\u0627\u0642\u060c \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc \u06a9\u06cc \u06c1\u062f\u0627\u06cc\u0627\u062a \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c <em>\u0627\u0648\u0631<\/em> \u0622\u0624\u0679 \u067e\u0679 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u062a\u0645\u0627\u0645 \u0645\u062a\u0646 \u06a9\u06d2 \u0627\u06cc\u06a9 \u062d\u0635\u06d2 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0638\u0627\u06c1\u0631 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-python\">import json\nfrom openai import OpenAI\n\nclient = OpenAI()\n\ndef analyze_receipt(receipt_text: str) -> dict:\n    response = client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[\n            {\"role\": \"system\", \"content\": \"\"\"Analyze this receipt and return JSON:\n{\n    \"merchant\": \"string\",\n    \"category\": \"one of: food, transport, utilities, entertainment, shopping, other\",\n    \"total\": float,\n    \"currency\": \"string\",\n    \"items\": [{\"name\": \"string\", \"amount\": float}],\n    \"is_business_expense\": bool,\n    \"confidence\": float between 0 and 1\n}\"\"\"},\n            {\"role\": \"user\", \"content\": receipt_text}\n        ]\n    )\n\n    raw = response.choices[0].message.content\n\n    # Parse the response\n    try:\n        if raw.startswith(\"```\"):\n            raw = raw.split(\"\\n\", 1)[1].rsplit(\"```\", 1)[0]\n        result = json.loads(raw)\n    except json.JSONDecodeError:\n        raise ValueError(f\"LLM returned invalid JSON: {raw[:200]}\")\n\n    # Validate fields manually\n    allowed_categories = {\"food\", \"transport\", \"utilities\", \"entertainment\", \"shopping\", \"other\"}\n    if result.get(\"category\") not in allowed_categories:\n        result[\"category\"] = \"other\"\n\n    return result\n<\/code><\/pre>\n<p>\u06a9\u0648\u0688 \u0635\u0627\u0641 \u06c1\u06d2\u060c \u067e\u0691\u06be\u0646\u06d2 \u0645\u06cc\u06ba \u0622\u0633\u0627\u0646 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0645\u06cc\u0631\u06d2 \u0644\u06cc\u067e \u0679\u0627\u067e \u067e\u0631 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0644\u06cc\u06a9\u0646 \u0628\u0646\u06cc\u0627\u062f\u06cc \u0645\u0633\u0626\u0644\u06c1 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0627\u06cc\u0644 \u0627\u06cc\u0644 \u0627\u06cc\u0645 (\u0627\u0646 \u067e\u0679\u060c \u0679\u0627\u0631\u06af\u0679 \u0627\u0648\u0631 \u0622\u0624\u0679 \u067e\u0679 \u0641\u0627\u0631\u0645\u06cc\u0679) \u06a9\u06d2 \u0633\u0627\u062a\u06be \u067e\u0648\u0631\u0627 \u0645\u0639\u0627\u06c1\u062f\u06c1 \u063a\u06cc\u0631 \u0633\u0627\u062e\u062a\u06c1 \u062a\u0627\u0631 \u0645\u06cc\u06ba \u06c1\u06d2\u06d4 \u06a9\u0633\u06cc \u0628\u06be\u06cc \u0641\u0631\u06cc\u0642 \u06a9\u06cc \u0637\u0631\u0641 \u0633\u06d2 \u0645\u0639\u0627\u06c1\u062f\u06d2 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u0646\u0641\u0627\u0630 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<p>\u062c\u06cc\u0633\u0627 \u06a9\u06c1 \u06c1\u0645 \u0627\u0633\u06d2 \u067e\u06cc\u062f\u0627\u0648\u0627\u0631 \u0645\u06cc\u06ba \u062f\u06be\u06a9\u06cc\u0644\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0645\u0633\u0627\u0626\u0644 \u0633\u0627\u0645\u0646\u06d2 \u0622\u0646\u0627 \u0634\u0631\u0648\u0639 \u06c1\u0648 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<ul>\n<li>\n<p><strong>\u0641\u0648\u0631\u06cc <em>\u06c1\u06d2<\/em> \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0627\u0646\u06af\u0631\u06cc\u0632\u06cc \u0645\u06cc\u06ba \u06c1\u06d2\u06d4<\/strong> \u0633\u0633\u0679\u0645 \u067e\u0631\u0627\u0645\u067e\u0679 \u0642\u062f\u0631\u062a\u06cc \u0632\u0628\u0627\u0646 \u0645\u06cc\u06ba \u0622\u0624\u0679 \u067e\u0679 \u0641\u0627\u0631\u0645\u06cc\u0679 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u06cc\u0633\u06cc \u06a9\u0648\u0626\u06cc \u0686\u06cc\u0632 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u062c\u0648 \u0627\u0633 \u0648\u0636\u0627\u062d\u062a \u06a9\u0648 \u0627\u0633 \u0633\u06d2 \u062c\u0648\u0691\u062a\u06cc \u06c1\u0648: <code>dict<\/code> \u0622\u067e \u06a9\u0627 \u06a9\u0648\u0688 \u062f\u0631\u062d\u0642\u06cc\u0642\u062a \u062a\u0648\u0642\u0639 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: \u0627\u06af\u0631 \u0622\u067e \u067e\u0631\u0627\u0645\u067e\u0679 \u0645\u06cc\u06ba \u06a9\u0648\u0626\u06cc \u0641\u06cc\u0644\u0688 \u0634\u0627\u0645\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0688\u0627\u0624\u0646 \u0627\u0633\u0679\u0631\u06cc\u0645 \u067e\u0631\u0648\u0633\u06cc\u0633\u0646\u06af \u06a9\u0648 \u0628\u06be\u0648\u0644 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u062a\u0648 \u0622\u067e \u06a9\u0648 \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u062a\u06a9 \u06a9\u0648\u0626\u06cc \u063a\u0644\u0637\u06cc \u0646\u06c1\u06cc\u06ba \u0645\u0644\u06d2 \u06af\u06cc\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>LLM \u06c1\u0645\u06cc\u0634\u06c1 \u0635\u0627\u0641 JSON \u0648\u0627\u067e\u0633 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/strong> \u0622\u0624\u0679 \u067e\u0679 \u06a9\u0648 \u0627\u0633 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0644\u067e\u06cc\u0679\u06cc\u06ba: <code>```json ```<\/code> \u0628\u0627\u0691 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\/\u0628\u0639\u062f \u0645\u06cc\u06ba \u0648\u0636\u0627\u062d\u062a\u06cc \u0645\u062a\u0646 \u0634\u0627\u0645\u0644 \u06a9\u0631\u06cc\u06ba\u060c \u0679\u0631\u06cc\u0644\u0646\u06af \u06a9\u0648\u0645\u0627 \u0634\u0627\u0645\u0644 \u06a9\u0631\u06cc\u06ba\u060c \u06cc\u0627 \u0679\u0627\u0626\u0645 \u0622\u0624\u0679 \u067e\u0631 \u062c\u0632\u0648\u06cc \u062c\u0648\u0627\u0628 \u062f\u06cc\u06ba\u06d4 \u067e\u0627\u0631\u0633\u0646\u06af \u06a9\u0648\u0688 \u0627\u06cc\u06a9 \u06a9\u06cc\u0633 (\u0628\u0627\u0691) \u06a9\u0648 \u0633\u0646\u0628\u06be\u0627\u0644\u062a\u0627 \u06c1\u06d2 \u0644\u06cc\u06a9\u0646 \u062f\u0648\u0633\u0631\u06d2 \u06a9\u0648 \u0646\u06c1\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>\u06a9\u0648\u0626\u06cc \u062d\u0642\u06cc\u0642\u06cc \u062a\u0635\u062f\u06cc\u0642 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/strong> \u06c1\u06d2 <code>total<\/code> \u06a9\u06cc\u0627 \u06cc\u06c1 \u0627\u0635\u0644 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0646\u0645\u0628\u0631 \u06c1\u06d2 \u06cc\u0627 \u0627\u06cc\u0644 \u0627\u06cc\u0644 \u0627\u06cc\u0645 \u0646\u06d2 \u0633\u0679\u0631\u0646\u06af \u0648\u0627\u067e\u0633 \u06a9\u06cc \u06c1\u06d2\u061f <code>\"$45.99\"<\/code>? \u06c1\u06d2 <code>confidence<\/code> \u06a9\u06cc\u0627 \u06cc\u06c1 0 \u0627\u0648\u0631 1 \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u06c1\u06d2 \u06cc\u0627 \u0627\u0633\u06d2 \u0648\u0627\u067e\u0633 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u061f <code>95<\/code> (\u0641\u06cc\u0635\u062f)\u061f \u06c1\u06d2 <code>items<\/code> \u06a9\u06cc\u0627 \u0641\u06c1\u0631\u0633\u062a \u0645\u06cc\u06ba \u0635\u062d\u06cc\u062d \u06a9\u0644\u06cc\u062f\u0648\u06ba \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0644\u063a\u0627\u062a \u0645\u0648\u062c\u0648\u062f \u06c1\u06cc\u06ba\u061f \u0622\u067e \u06a9\u0648 \u06cc\u06c1 \u0633\u0628 \u062f\u0633\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u0627 \u06c1\u0648\u06af\u0627\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>\u0646\u0627\u06a9\u0627\u0645\u06cc \u062e\u0627\u0645\u0648\u0634 \u06cc\u0627 \u0645\u06c1\u0644\u06a9 \u06c1\u0648\u0633\u06a9\u062a\u06cc \u06c1\u06d2\u06d4<\/strong> \u0632\u0645\u0631\u06c1 \u0645\u062a\u0628\u0627\u062f\u0644 (<code>result[\"category\"] = \"other\"<\/code>) \u0627\u0646 \u0645\u0633\u0627\u0626\u0644 \u06a9\u0648 \u0686\u06be\u067e\u0627\u062a\u0627 \u06c1\u06d2 \u062c\u0646 \u06a9\u06cc \u0648\u062c\u06c1 \u0633\u06d2 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06cc \u0686\u0627\u06c1\u0626\u06d2\u06d4 \u06a9\u06c1 <code>json.loads<\/code> \u0627\u06af\u0631 \u06cc\u06c1 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u062a\u0648\u060c \u0628\u062d\u0627\u0644\u06cc \u06a9\u06d2 \u0631\u0627\u0633\u062a\u06d2 \u06a9\u06d2 \u0628\u063a\u06cc\u0631 \u0627\u06cc\u06a9 \u0627\u0633\u062a\u062b\u0646\u0627 \u0627\u0679\u06be\u0627\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<\/ul>\n<p>\u0622\u067e \u06a9\u0648 \u0648\u0627\u0642\u0639\u06cc \u062c\u0633 \u0686\u06cc\u0632 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2 \u0648\u06c1 \u067e\u0631\u0627\u0645\u067e\u0679 \u0633\u0679\u0631\u0646\u06af \u06a9\u06cc \u0627\u0646\u06af\u0631\u06cc\u0632\u06cc \u0648\u0636\u0627\u062d\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u0628\u0644\u06a9\u06c1 \u0622\u067e \u06a9\u06d2 \u06a9\u0648\u0688 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0628\u0627\u0631 \u0627\u0646 \u067e\u0679 \u0688\u06cc\u0679\u0627 \u0633\u0679\u0631\u06a9\u0686\u0631 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0622\u0624\u0679 \u067e\u0679 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0627\u06cc\u06a9 \u0637\u0631\u06cc\u0642\u06c1 \u06c1\u06d2\u06d4 \u0633\u06a9\u06cc\u0645\u0627 LLM \u0627\u0648\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u0648\u0688 \u062f\u0648\u0646\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2 \u0633\u0686\u0627\u0626\u06cc \u06a9\u0627 \u0648\u0627\u062d\u062f \u0630\u0631\u06cc\u0639\u06c1 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u06c1\u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0627\u06cc\u0633\u06d2 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06a9\u06cc \u0628\u06be\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2 \u062c\u0648 \u0642\u0633\u0645 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641\u0648\u06ba \u06a9\u06d2 \u062e\u0644\u0627\u0641 LLM \u06a9\u06d2 \u0631\u062f\u0639\u0645\u0644 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u06d2\u060c \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u0648 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0646\u0627\u0641\u0630 \u06a9\u0631\u06d2 \u0627\u0648\u0631 \u0645\u0645\u0627\u062b\u0644\u062a \u0646\u06c1 \u06c1\u0648\u0646\u06d2 \u06a9\u06cc \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba \u0645\u0646\u0627\u0633\u0628 \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u0628\u0691\u06be\u0627\u0626\u06d2\u06d4<\/p>\n<p>\u0622\u062e\u0631 \u0645\u06cc\u06ba\u060c \u06c1\u0645\u06cc\u06ba \u0628\u063a\u06cc\u0631 \u06a9\u0633\u06cc \u062f\u0633\u062a\u06cc \u0645\u0646\u0637\u0642 \u06a9\u06d2 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u0646\u0627\u06a9\u0627\u0645\u06cc\u0648\u06ba \u067e\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4 \u0627\u06af\u0631 \u0622\u0624\u0679 \u067e\u0679 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0633\u06d2 \u0645\u0645\u0627\u062b\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u062a\u0648\u060c LLM \u0645\u06cc\u06ba \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u062e\u0631\u0627\u0628\u06cc \u06a9\u06d2 \u067e\u06cc\u063a\u0627\u0645\u0627\u062a \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0688\u0633\u067e\u0644\u06d2 \u06a9\u0631\u06cc\u06ba \u062a\u0627\u06a9\u06c1 \u0622\u067e \u062e\u0648\u062f \u06a9\u0648 \u062f\u0631\u0633\u062a \u06a9\u0631 \u0633\u06a9\u06cc\u06ba\u06d4<\/p>\n<p>\u06cc\u0639\u0646\u06cc \u0622\u0624\u0679 \u067e\u0679 \u0641\u0627\u0631\u0645\u06cc\u0679 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2: <em>\u0645\u0639\u0627\u06c1\u062f\u06c1<\/em> \u0627\u06cc\u06a9 \u0642\u0633\u0645 \u06a9\u06d2 \u0646\u0638\u0627\u0645 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0627\u0638\u06c1\u0627\u0631 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u06d4 <em>\u062a\u062c\u0648\u06cc\u0632<\/em> \u0627\u0646\u06af\u0631\u06cc\u0632\u06cc \u0645\u06cc\u06ba \u0628\u06cc\u0627\u0646 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-how-pydantic-ai-solves-this\">Pydantic AI \u0627\u0633 \u0645\u0633\u0626\u0644\u06d2 \u06a9\u0648 \u06a9\u06cc\u0633\u06d2 \u062d\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>Pydantic AI \u0622\u067e \u06a9\u0648 \u0627\u067e\u0646\u06d2 \u0622\u0624\u0679 \u067e\u0679 \u06a9\u0648 Pydantic \u0645\u0627\u0688\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0628\u06cc\u0627\u0646 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u062c\u0646\u0631\u06cc\u0634\u0646\u060c \u067e\u0631\u0627\u0645\u067e\u0679 \u0627\u0646\u062c\u06cc\u06a9\u0634\u0646\u060c JSON \u067e\u0627\u0631\u0633\u0646\u06af\u060c \u062a\u0648\u062b\u06cc\u0642 \u0627\u0648\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634\u0648\u06ba \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0648\u0631 \u06cc\u06c1 \u0633\u0628 \u0627\u06cc\u06a9 \u0645\u0627\u0688\u0644 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641 \u0633\u06d2 \u0645\u0627\u062e\u0648\u0630 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-python\">from pydantic import BaseModel, Field\nfrom pydantic_ai import Agent\nfrom enum import Enum\n\n\nclass SpendingCategory(str, Enum):\n    FOOD = \"food\"\n    TRANSPORT = \"transport\"\n    UTILITIES = \"utilities\"\n    ENTERTAINMENT = \"entertainment\"\n    SHOPPING = \"shopping\"\n    OTHER = \"other\"\n\n\nclass LineItem(BaseModel):\n    name: str\n    amount: float\n\n\nclass ReceiptAnalysis(BaseModel):\n    merchant: str\n    category: SpendingCategory\n    total: float = Field(gt=0)\n    currency: str = Field(min_length=3, max_length=3)\n    items: list[LineItem]\n    is_business_expense: bool\n    confidence: float = Field(ge=0, le=1)\n\n\nreceipt_agent = Agent(\n    \"openai:gpt-4o\",\n    output_type=ReceiptAnalysis,\n    system_prompt=\"Analyze the provided receipt and extract structured details.\",\n)\n\nresult = receipt_agent.run_sync(\"CAFE PARIS\\n\u20ac12.50\\nCroissant x2 \u20ac5.00\\nEspresso \u20ac2.50\\nCroque Monsieur \u20ac5.00\")\nprint(result.output)\n# merchant=\"CAFE PARIS\" category=<spendingcategory.food:> total=12.5 ...\n<\/spendingcategory.food:><\/code><\/pre>\n<p>\u062a\u0648 \u06cc\u06c1\u0627\u06ba \u06a9\u06cc\u0627 \u0641\u0631\u0642 \u06c1\u06d2\u061f<\/p>\n<p>\u0633\u0628 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u060c \u0627\u06cc\u06a9 \u0633\u06a9\u06cc\u0645\u0627 \u0627\u06cc\u06a9 \u0645\u0627\u0688\u0644 \u06c1\u06d2. <code>ReceiptAnalysis<\/code> \u0641\u06cc\u0644\u0688\u0632\u060c \u0627\u0642\u0633\u0627\u0645 \u0627\u0648\u0631 \u0631\u06a9\u0627\u0648\u0679\u0648\u06ba \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u06cc\u06ba\u06d4 Pydantic AI \u0627\u0633\u06d2 LLM \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0648\u0632\u0648\u06ba JSON \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0645\u06cc\u06ba \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u06a9\u06d2 \u062e\u0644\u0627\u0641 \u062c\u0648\u0627\u0628 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0627\u06cc\u06a9 \u062a\u0639\u0631\u06cc\u0641 \u06c1\u06d2 \u062c\u0648 \u06c1\u0631 \u062c\u06af\u06c1 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u062f\u0648\u0633\u0631\u0627\u060c \u06a9\u0648\u0688 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u062a\u062c\u0632\u06cc\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0627\u067e\u0646\u06cc \u0645\u0627\u0631\u06a9 \u0688\u0627\u0648\u0646 \u0628\u0627\u0691 \u06a9\u0648 \u0646\u06c1 \u06c1\u0679\u0627\u0626\u06cc\u06ba\u060c \u06c1\u0645\u06cc\u06ba \u06a9\u0627\u0644 \u06a9\u0631\u06cc\u06ba\u06d4 <code>json.loads<\/code>\u06cc\u0627 \u067e\u06a9\u0691\u0648 <code>JSONDecodeError<\/code>. \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u0627\u0633 \u0633\u0628 \u06a9\u0627 \u062e\u06cc\u0627\u0644 \u0631\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633 \u06a9\u06d2 \u0639\u0644\u0627\u0648\u06c1\u060c \u062a\u0635\u062f\u06cc\u0642 \u062d\u0642\u06cc\u0642\u06cc \u06c1\u06d2. <code>Field(ge=0, le=1)<\/code> \u06a9\u0648 <code>confidence<\/code> \u06a9\u06cc \u0642\u062f\u0631 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 <code>95<\/code> \u0627\u0633\u06d2 \u0645\u0633\u062a\u0631\u062f \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u062e\u0627\u0645\u0648\u0634\u06cc \u0633\u06d2 \u0642\u0628\u0648\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 <code>SpendingCategory<\/code> Enum \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u0645\u062a\u0628\u0627\u062f\u0644 \u0645\u0627\u0633\u06a9\u0646\u06af \u06a9\u06d2 \u0628\u063a\u06cc\u0631 \u0635\u0631\u0641 \u062f\u0631\u0633\u062a \u0632\u0645\u0631\u06d2 \u06c1\u06cc \u0642\u0628\u0648\u0644 \u06a9\u06cc\u06d2 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0622\u062e\u0631 \u0645\u06cc\u06ba\u060c \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634\u06cc\u06ba \u062e\u0648\u062f\u06a9\u0627\u0631 \u06c1\u06cc\u06ba\u06d4 \u0627\u06af\u0631 LLM \u0622\u0624\u0679 \u067e\u0679 \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0648 \u062a\u0648\u062b\u06cc\u0642 \u0645\u06cc\u06ba \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c Pydantic AI \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u0645\u0627\u0688\u0644 \u06a9\u0648 \u0648\u0627\u067e\u0633 \u0628\u06be\u06cc\u062c\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633\u06d2 \u062e\u0648\u062f \u0679\u06be\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u062f\u0633\u062a\u06cc \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u0644\u0648\u067e \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 \u0641\u0646\u06a9\u0634\u0646 <code>ReceiptAnalysis<\/code> \u0622\u0628\u062c\u06cc\u06a9\u0679: \u0628\u06be\u0631\u0627 \u06c1\u0648\u0627 \u0627\u0648\u0631 \u062a\u0635\u062f\u06cc\u0642 \u0634\u062f\u06c1\u060c IDE \u062e\u0648\u062f\u06a9\u0627\u0631 \u062a\u06a9\u0645\u06cc\u0644 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0648\u0632\u0648\u06ba\u06d4 \u0646\u06c1\u06cc\u06ba <code>dict<\/code> \u0645\u062c\u06be\u06d2 \u0627\u0645\u06cc\u062f \u06c1\u06d2 \u06a9\u06c1 \u0622\u067e \u06a9\u06d2 \u067e\u0627\u0633 \u0635\u062d\u06cc\u062d \u0686\u0627\u0628\u06cc \u06c1\u06d2\u06d4<\/p>\n<h4 id=\"heading-what-happens-beneath-the-surface\">\u0633\u0637\u062d \u06a9\u06d2 \u0646\u06cc\u0686\u06d2 \u06a9\u06cc\u0627 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/h4>\n<p>\u062a\u0639\u0631\u06cc\u0641 \u06a9\u0631\u062a\u06d2 \u0648\u0642\u062a <code>output_type=ReceiptAnalysis<\/code>Pydantic AI \u06c1\u0631 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06d2 \u0639\u0645\u0644 \u0645\u06cc\u06ba \u06a9\u0626\u06cc \u0627\u06c1\u0645 \u06a9\u0627\u0645 \u0627\u0646\u062c\u0627\u0645 \u062f\u06cc\u062a\u0627 \u06c1\u06d2:<\/p>\n<p>\u0631\u0627\u0633\u062a\u06d2 \u0645\u06cc\u06ba\u060c \u06c1\u0645 Pydantic \u0645\u0627\u0688\u0644 \u0633\u06d2 JSON \u0627\u0633\u06a9\u06cc\u0645\u0627 \u062a\u06cc\u0627\u0631 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0627\u0633\u06d2 LLM \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06cc\u06ba \u062f\u0627\u062e\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0645\u0627\u0688\u0644 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0646\u0646\u062f\u06c1 \u067e\u0631 \u0645\u0646\u062d\u0635\u0631 \u06c1\u06d2\u060c \u06cc\u06c1 \u0688\u06cc\u0641\u0627\u0644\u0679 \u0633\u0627\u062e\u062a\u06c1 \u0622\u0624\u0679 \u067e\u0679\/\u0679\u0648\u0644 \u06a9\u0627\u0644 \u0645\u06cc\u06a9\u0627\u0646\u0632\u0645 \u06c1\u0648 \u0633\u06a9\u062a\u0627 \u06c1\u06d2 (OpenAI&#8217;s <code>response_format<\/code>\u0627\u0646\u062a\u06be\u0631\u0648\u067e\u06a9 \u0648\u063a\u06cc\u0631\u06c1 \u06a9\u06d2 \u0627\u0648\u0632\u0627\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u06cc\u06ba) \u0627\u06cc\u0644 \u0627\u06cc\u0644 \u0627\u06cc\u0645 \u062c\u0627\u0646\u062a\u0627 \u06c1\u06d2\u06d4 <em>\u062f\u0631\u0633\u062a \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2<\/em> \u06cc\u06c1 \u06a9\u0633 \u0688\u06be\u0627\u0646\u0686\u06d2 \u0645\u06cc\u06ba \u062a\u06cc\u0627\u0631 \u06a9\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627\u061f<\/p>\n<p>\u0648\u0627\u067e\u0633\u06cc \u067e\u0631\u060c \u06c1\u0645 LLM \u0633\u06d2 \u062e\u0627\u0645 \u062c\u0648\u0627\u0628 \u0644\u06cc\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0633\u06d2 Pydantic \u0645\u0627\u0688\u0644 \u06a9\u06d2 \u062e\u0644\u0627\u0641 \u067e\u0627\u0631\u0633 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0645\u06a9\u0645\u0644 \u062a\u0648\u062b\u06cc\u0642 (\u0642\u0633\u0645 \u062c\u0628\u0631\u060c \u0641\u06cc\u0644\u0688 \u06a9\u06cc \u0631\u06a9\u0627\u0648\u0679\u06cc\u06ba\u060c \u0627\u0648\u0631 enum \u0645\u0645\u0628\u0631\u0634\u067e) \u0686\u0644\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u06af\u0631 \u062a\u0648\u062b\u06cc\u0642 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2\u060c \u062a\u0648 \u06cc\u06c1 \u0627\u06cc\u06a9 \u063a\u0644\u0637\u06cc \u06a9\u0627 \u067e\u06cc\u063a\u0627\u0645 \u0628\u0627\u062a \u0686\u06cc\u062a \u0645\u06cc\u06ba \u0648\u0627\u067e\u0633 \u0628\u06be\u06cc\u062c\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 LLM \u0633\u06d2 \u0622\u0624\u0679 \u067e\u0679 \u06a9\u0648 \u0679\u06be\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u06c1\u062a\u0627 \u06c1\u06d2 (\u062e\u0648\u062f\u06a9\u0627\u0631 \u0637\u0648\u0631 \u067e\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u06cc \u0642\u0627\u0628\u0644 \u062a\u0631\u062a\u06cc\u0628 \u062d\u062f \u062a\u06a9)\u06d4<\/p>\n<pre><code class=\"language-markdown\">\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502                    Pydantic AI \u2014 Structured Output Flow              \u2502\n\u2502                                                                      \u2502\n\u2502  \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510         \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510     \u2502\n\u2502  \u2502  Your Code     \u2502         \u2502  Pydantic AI Framework           \u2502     \u2502\n\u2502  \u2502                \u2502         \u2502                                  \u2502     \u2502\n\u2502  \u2502  output_type = \u2502\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\u2502  1. Generate JSON schema from    \u2502     \u2502\n\u2502  \u2502  ReceiptAnalysis         \u2502     ReceiptAnalysis model        \u2502     \u2502\n\u2502  \u2502                \u2502         \u2502                                  \u2502     \u2502\n\u2502  \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518         \u2502  2. Inject schema into LLM      \u2502     \u2502\n\u2502                             \u2502     request (provider-native     \u2502     \u2502\n\u2502                             \u2502     format: response_format,     \u2502     \u2502\n\u2502                             \u2502     tool_call, etc.)             \u2502     \u2502\n\u2502                             \u2502              \u2502                   \u2502     \u2502\n\u2502                             \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518     \u2502\n\u2502                                            \u25bc                         \u2502\n\u2502                             \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510     \u2502\n\u2502                             \u2502           LLM                    \u2502     \u2502\n\u2502                             \u2502  Sees schema \u2192 produces JSON     \u2502     \u2502\n\u2502                             \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518     \u2502\n\u2502                                            \u2502                         \u2502\n\u2502                                            \u25bc                         \u2502\n\u2502                             \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510     \u2502\n\u2502                             \u2502  Pydantic AI Framework           \u2502     \u2502\n\u2502                             \u2502                                  \u2502     \u2502\n\u2502                             \u2502  3. Parse raw LLM response       \u2502     \u2502\n\u2502                             \u2502  4. Validate against model:      \u2502     \u2502\n\u2502                             \u2502     - Type checks                \u2502     \u2502\n\u2502                             \u2502     - Field constraints (ge, le) \u2502     \u2502\n\u2502                             \u2502     - Enum membership            \u2502     \u2502\n\u2502                             \u2502              \u2502                   \u2502     \u2502\n\u2502                             \u2502         \u250c\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2510              \u2502     \u2502\n\u2502                             \u2502         \u2502         \u2502              \u2502     \u2502\n\u2502                             \u2502      PASS \u2713    FAIL \u2717            \u2502     \u2502\n\u2502                             \u2502         \u2502         \u2502              \u2502     \u2502\n\u2502                             \u2502         \u25bc         \u25bc              \u2502     \u2502\n\u2502                             \u2502  Return typed  Send validation   \u2502     \u2502\n\u2502                             \u2502  object        error back to LLM \u2502     \u2502\n\u2502                             \u2502                for self-correct   \u2502     \u2502\n\u2502                             \u2502                (auto-retry)       \u2502     \u2502\n\u2502                             \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518     \u2502\n\u2502                                            \u2502                         \u2502\n\u2502                                            \u25bc                         \u2502\n\u2502                             \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510     \u2502\n\u2502                             \u2502  Your Code receives:             \u2502     \u2502\n\u2502                             \u2502  result.output \u2192 ReceiptAnalysis \u2502     \u2502\n\u2502                             \u2502  (typed, validated, ready to use)\u2502     \u2502\n\u2502                             \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518     \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n<\/code><\/pre>\n<p>\u0622\u067e \u0627\u067e\u0646\u06d2 \u0645\u0639\u0627\u06c1\u062f\u06d2 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u0627\u06cc\u06a9 \u0628\u0627\u0631 \u0627\u0632\u06af\u0631 \u06a9\u06cc \u06a9\u0644\u0627\u0633 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 LLM \u0628\u0627\u0624\u0646\u0688\u0631\u06cc \u06a9\u06d2 \u062f\u0648\u0646\u0648\u06ba \u0627\u0637\u0631\u0627\u0641 \u067e\u0631 \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u0645\u0627\u0688\u0644 \u06a9\u0648 \u0628\u062a\u0627\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u06cc\u0627 \u067e\u06cc\u062f\u0627 \u06a9\u0631\u0646\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u06cc\u06c1 \u062a\u06cc\u0627\u0631 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0631\u0633\u06cc\u062f \u0627\u06cc\u062c\u0646\u0679\u0648\u06ba \u06a9\u0648 \u0641\u0631\u0648\u062e\u062a \u06a9\u0646\u0646\u062f\u06af\u0627\u0646 \u06a9\u06d2 \u0632\u0645\u0631\u06d2 \u062a\u0644\u0627\u0634 \u06a9\u0631\u0646\u06d2\u060c \u0634\u0631\u062d \u0645\u0628\u0627\u062f\u0644\u06c1 \u06a9\u06cc \u062c\u0627\u0646\u0686 \u067e\u0691\u062a\u0627\u0644 \u0627\u0648\u0631 \u0627\u062e\u0631\u0627\u062c\u0627\u062a \u06a9\u06cc \u062a\u0627\u0631\u06cc\u062e \u06a9\u06d2 \u0628\u0627\u0631\u06d2 \u0645\u06cc\u06ba \u0627\u0633\u062a\u0641\u0633\u0627\u0631 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0679\u0648\u0644\u0632 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u062e\u0627\u0645 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u0627\u0644 \u06a9\u06cc \u0637\u0631\u062d \u062f\u06a9\u06be\u062a\u06cc \u06c1\u06d2:<\/p>\n<pre><code class=\"language-python\">tools = [\n    {\n        \"type\": \"function\",\n        \"function\": {\n            \"name\": \"lookup_merchant_category\",\n            \"description\": \"Look up the spending category for a merchant name\",\n            \"parameters\": {\n                \"type\": \"object\",\n                \"properties\": {\n                    \"merchant_name\": {\n                        \"type\": \"string\",\n                        \"description\": \"The merchant name from the receipt\"\n                    }\n                },\n                \"required\": [\"merchant_name\"]\n            }\n        }\n    },\n    {\n        \"type\": \"function\",\n        \"function\": {\n            \"name\": \"get_exchange_rate\",\n            \"description\": \"Get current exchange rate between two currencies\",\n            \"parameters\": {\n                \"type\": \"object\",\n                \"properties\": {\n                    \"from_currency\": {\n                        \"type\": \"string\",\n                        \"description\": \"Source currency code (e.g., EUR)\"\n                    },\n                    \"to_currency\": {\n                        \"type\": \"string\",\n                        \"description\": \"Target currency code (e.g., USD)\"\n                    }\n                },\n                \"required\": [\"from_currency\", \"to_currency\"]\n            }\n        }\n    },\n    {\n        \"type\": \"function\",\n        \"function\": {\n            \"name\": \"get_spending_history\",\n            \"description\": \"Get spending totals by category for a date range\",\n            \"parameters\": {\n                \"type\": \"object\",\n                \"properties\": {\n                    \"category\": {\n                        \"type\": \"string\",\n                        \"description\": \"Spending category\"\n                    },\n                    \"days\": {\n                        \"type\": \"integer\",\n                        \"description\": \"Number of past days to query\"\n                    }\n                },\n                \"required\": [\"category\", \"days\"]\n            }\n        }\n    }\n]\n\n\n# Then you ALSO need to write the dispatch logic:\ndef handle_tool_call(tool_call):\n    name = tool_call.function.name\n    args = json.loads(tool_call.function.arguments)\n\n    if name == \"lookup_merchant_category\":\n        return lookup_merchant_category(args[\"merchant_name\"])\n    elif name == \"get_exchange_rate\":\n        return get_exchange_rate(args[\"from_currency\"], args[\"to_currency\"])\n    elif name == \"get_spending_history\":\n        return get_spending_history(args[\"category\"], args[\"days\"])\n    else:\n        raise ValueError(f\"Unknown tool: {name}\")\n<\/code><\/pre>\n<p>\u0645\u06cc\u06ba \u0646\u06d2 \u062a\u06cc\u0646 \u0679\u0648\u0644\u0632 \u06a9\u06d2 \u0644\u06cc\u06d2 JSON \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0627\u0648\u0631 \u0688\u0633\u067e\u06cc\u0686 \u06a9\u0648\u0688 \u06a9\u06cc \u062a\u0642\u0631\u06cc\u0628\u0627\u064b 70 \u0644\u0627\u0626\u0646\u06cc\u06ba \u0644\u06a9\u06be\u06cc\u06ba\u06d4 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0627\u0635\u0644 \u0641\u0646\u06a9\u0634\u0646 \u062f\u0633\u062a\u062e\u0637 \u0633\u06d2 \u0645\u0646\u0642\u0637\u0639 \u06c1\u06d2\u06d4 \u0627\u06af\u0631 \u0622\u067e \u06a9\u0633\u06cc \u0641\u0646\u06a9\u0634\u0646 \u0645\u06cc\u06ba \u067e\u06cc\u0631\u0627\u0645\u06cc\u0679\u0631 \u06a9\u0627 \u0646\u0627\u0645 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u0648 \u0627\u067e \u0688\u06cc\u0679 \u06a9\u0631\u0646\u0627 \u0628\u06be\u0648\u0644 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u062a\u0648 \u06cc\u06c1 \u0631\u0646 \u0679\u0627\u0626\u0645 \u067e\u0631 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0679\u0648\u0679 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4<\/p>\n<h3 id=\"heading-what-the-solution-should-look-like\">\u062d\u0644 \u06a9\u06cc\u0633\u0627 \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>\u0627\u0633 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2\u060c \u0679\u0648\u0644 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641 \u0641\u0646\u06a9\u0634\u0646 \u0633\u06d2 \u06c1\u06cc \u0627\u062e\u0630 \u06a9\u06cc \u062c\u0627\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u0627 \u0646\u0627\u0645\u060c \u0688\u0627\u06a9\u0633\u0679\u0631\u0646\u06af\u060c \u0627\u0648\u0631 \u0679\u0627\u0626\u067e \u06a9\u06d2 \u0627\u0634\u0627\u0631\u06d2 \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u06c1\u06cc \u0628\u06cc\u0627\u0646 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u0679\u0648\u0644 \u06a9\u06cc\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u06cc\u0627 \u062f\u0644\u0627\u0626\u0644 \u0644\u06cc\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0628\u06c1\u062a \u06c1\u0648 \u06af\u06cc\u0627\u06d4<\/p>\n<p>\u06cc\u06c1 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0645\u0637\u0627\u0628\u0642\u062a \u067e\u0630\u06cc\u0631 \u0628\u06be\u06cc \u0631\u06c1\u0646\u0627 \u0686\u0627\u06c1\u0626\u06d2\u06d4 \u067e\u06cc\u0631\u0627\u0645\u06cc\u0679\u0631 \u06a9\u0627 \u0646\u0627\u0645 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u0646\u0627 \u06cc\u0627 \u0627\u0633 \u06a9\u06cc \u0642\u0633\u0645 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u0646\u0627 \u062f\u0648\u0633\u0631\u06cc \u0641\u0627\u0626\u0644 \u06a9\u0648 \u0686\u06be\u0648\u0626\u06d2 \u0628\u063a\u06cc\u0631 LLM \u06a9\u0648 \u0628\u06be\u06cc\u062c\u06d2 \u06af\u0626\u06d2 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u0648 \u0627\u067e \u0688\u06cc\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0648\u0631 \u06a9\u0648\u0626\u06cc \u0634\u067e\u0646\u06af \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u0626\u06d2. \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06a9\u0648 \u0635\u062d\u06cc\u062d \u0641\u0646\u06a9\u0634\u0646 \u06a9\u0648 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u06a9\u0627\u0644 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u0626\u06d2\u06d4 \u06a9\u0627\u0644 \u0627\u06cc\u0628\u0644\u0632 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0648\u0626\u06cc \u062f\u0633\u062a\u06cc if\/elif \u0686\u06cc\u0646 \u0645\u06cc\u067e\u0646\u06af \u0633\u0679\u0631\u0646\u06af \u06a9\u06d2 \u0646\u0627\u0645 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-how-pydantic-ai-solves-this\">Pydantic AI \u0627\u0633 \u0645\u0633\u0626\u0644\u06d2 \u06a9\u0648 \u06a9\u06cc\u0633\u06d2 \u062d\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>Pydantic AI \u0645\u06cc\u06ba\u060c \u0679\u0648\u0644\u0632 \u0635\u0631\u0641 \u0688\u06cc\u06a9\u0648\u0631\u06cc\u0679\u0631\u0632 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u06d2 \u062f\u0633\u062a\u062e\u0637 \u0627\u0648\u0631 Docstring \u0633\u06d2 JSON \u0627\u0633\u06a9\u06cc\u0645\u0627 \u062a\u06cc\u0627\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0688\u0633\u067e\u06cc\u0686 \u06a9\u0648 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-python\">from pydantic_ai import Agent, RunContext\n\nreceipt_agent = Agent(\n    \"openai:gpt-4o\",\n    output_type=ReceiptAnalysis,\n    system_prompt=\"Analyze the provided receipt and extract structured details.\",\n)\n\n\n@receipt_agent.tool_plain\ndef lookup_merchant_category(merchant_name: str) -> str:\n    \"\"\"Look up the spending category for a merchant name.\"\"\"\n    # Your actual implementation\n    categories_db = {\"CAFE PARIS\": \"food\", \"UBER\": \"transport\", \"NETFLIX\": \"entertainment\"}\n    return categories_db.get(merchant_name.upper(), \"other\")\n\n\n@receipt_agent.tool_plain\ndef get_exchange_rate(from_currency: str, to_currency: str) -> float:\n    \"\"\"Get current exchange rate between two currencies.\"\"\"\n    # Your actual implementation \u2014 call an API, hit a cache, etc.\n    rates = {\"EUR_USD\": 1.08, \"GBP_USD\": 1.27}\n    return rates.get(f\"{from_currency}_{to_currency}\", 1.0)\n\n\n@receipt_agent.tool_plain\ndef get_spending_history(category: str, days: int) -> dict:\n    \"\"\"Get spending totals by category for a date range.\"\"\"\n    # Your actual implementation\n    return {\"category\": category, \"total\": 142.50, \"transaction_count\": 12}\n<\/code><\/pre>\n<p>\u0628\u0633\u06d4 \u06a9\u0648\u0626\u06cc JSON \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0644\u063a\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u06a9\u0648\u0626\u06cc \u0688\u0633\u067e\u06cc\u0686 \u0641\u0646\u06a9\u0634\u0646 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0648\u06c1\u06cc \u062a\u06cc\u0646 \u0679\u0648\u0644\u0632 ~70 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 ~25 \u0644\u0627\u0626\u0646 \u067e\u0631 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06a9\u06cc\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2:<\/p>\n<ul>\n<li>\n<p><strong>\u0642\u0633\u0645 \u06a9\u06d2 \u0627\u0634\u0627\u0631\u06d2 \u0633\u06d2 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u062a\u06cc\u0627\u0631 \u06a9\u0631\u06cc\u06ba:<\/strong> <code>merchant_name: str<\/code>    \u0628\u0646 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 <code>{\"type\": \"string\"}<\/code> JSON \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0645\u06cc\u06ba\u06d4 \u0688\u0627\u06a9\u0633\u0679\u0631\u0646\u06af \u0627\u06cc\u06a9 \u0679\u0648\u0644 \u06c1\u06d2\u06d4 <code>description<\/code>. \u067e\u06cc\u0631\u0627\u0645\u06cc\u0679\u0631 \u06a9\u06d2 \u0646\u0627\u0645 \u062c\u0627\u0626\u06cc\u062f\u0627\u062f \u06a9\u06d2 \u0646\u0627\u0645 \u0628\u0646 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u0633\u0628 \u0627\u0633 \u0633\u06d2 \u0627\u062e\u0630 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2 \u062c\u0648 \u0622\u067e \u067e\u06c1\u0644\u06d2 \u06c1\u06cc \u0644\u06a9\u06be \u0686\u06a9\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>\u0622\u0679\u0648 \u0688\u0633\u067e\u06cc\u0686:<\/strong> \u062c\u0628 LLM \u06a9\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code>get_exchange_rate<\/code>\u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u0633\u062c\u06d2 \u06c1\u0648\u0626\u06d2 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u06cc \u0637\u0631\u0641 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u0648\u0626\u06cc \u0633\u0679\u0631\u0646\u06af \u0645\u06cc\u0686\u0646\u06af \u0627\u0648\u0631 \u0645\u06cc\u0646\u0648\u0626\u0644 \u0645\u06cc\u067e\u0646\u06af \u0646\u06c1\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>\u0645\u0637\u0627\u0628\u0642\u062a \u067e\u0630\u06cc\u0631\u06cc \u06a9\u06cc \u0636\u0645\u0627\u0646\u062a:<\/strong> \u0646\u0627\u0645 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u06cc\u06ba <code>from_currency<\/code> \u06a9\u0648 <code>source_currency<\/code> \u06cc\u06c1 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u06d2 \u062f\u0633\u062a\u062e\u0637 \u0645\u06cc\u06ba \u0634\u0627\u0645\u0644 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0627\u06af\u0644\u06d2 \u0631\u0646 \u067e\u0631 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0627\u067e \u0688\u06cc\u0679 \u06c1\u0648\u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u0628\u06be\u0648\u0644\u0646\u06d2 \u06a9\u06cc \u06a9\u0648\u0626\u06cc \u062f\u0648\u0633\u0631\u06cc \u062c\u06af\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"heading-problem-3-no-clean-way-to-pass-runtime-context\">\u0645\u0633\u0626\u0644\u06c1 3: \u0631\u0646 \u0679\u0627\u0626\u0645 \u0633\u06cc\u0627\u0642 \u0648 \u0633\u0628\u0627\u0642 \u06a9\u0648 \u0645\u0646\u062a\u0642\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u0635\u0627\u0641 \u0637\u0631\u06cc\u0642\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/h2>\n<p>\u062e\u0648\u062f\u06a9\u0627\u0631 \u0688\u0633\u067e\u06cc\u0686 (\u0645\u0633\u0626\u0644\u06c1 2) \u06a9\u06d2 \u0633\u0627\u062a\u06be\u060c \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u0635\u0627\u0631\u0641 \u06a9\u06d2 \u0627\u0641\u0639\u0627\u0644 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0679\u0648\u0644 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u0648 \u06a9\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0686\u0648\u0646\u06a9\u06c1 \u0627\u0628 \u0622\u067e \u06a9\u0627 \u06a9\u0627\u0644 \u0633\u0627\u0626\u0679 \u067e\u0631 \u06a9\u0646\u0679\u0631\u0648\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u0627\u0633 \u0644\u06cc\u06d2 \u0622\u067e \u0628\u0633 \u0646\u06c1\u06cc\u06ba \u06af\u0632\u0631 \u0633\u06a9\u062a\u06d2\u06d4 <code>db<\/code> \u06cc\u0627 <code>user_id<\/code> \u0627\u06cc\u06a9 \u0627\u0636\u0627\u0641\u06cc \u062f\u0644\u06cc\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631\u06d4<\/p>\n<p>\u0627\u0648\u0631 \u06cc\u06c1 \u0648\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u062c\u0648 \u0627\u06cc\u0644 \u0627\u06cc\u0644 \u0627\u06cc\u0645 \u06a9\u0648 \u067e\u06cc\u0634 \u06a9\u0631\u0646\u0627 \u06c1\u06d2\u06d4 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0633\u0627\u0626\u06cc\u0688 \u0686\u06cc\u0646\u0644\u0632 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2 \u062a\u0627\u06a9\u06c1 \u0648\u06c1 \u0631\u0646 \u0679\u0627\u0626\u0645 \u0627\u0646\u062d\u0635\u0627\u0631 \u06a9\u0648 \u0627\u0646 \u0679\u0648\u0644\u0632 \u062a\u06a9 \u0645\u0646\u062a\u0642\u0644 \u06a9\u0631 \u0633\u06a9\u06d2 \u062c\u0646\u06c1\u06cc\u06ba \u06cc\u06c1 \u0622\u067e \u06a9\u06cc \u062c\u0627\u0646\u0628 \u0633\u06d2 \u06a9\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0633 \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u0627\u0631 \u06a9\u06d2 \u0628\u063a\u06cc\u0631\u060c \u062f\u0631\u062c \u0630\u06cc\u0644 \u0646\u062a\u0627\u0626\u062c \u0633\u0627\u0645\u0646\u06d2 \u0622\u0626\u06cc\u06ba \u06af\u06d2:<\/p>\n<pre><code class=\"language-python\"># Option A: Global state (untestable, unsafe)\ndb = get_database_connection()\ncurrent_user = None  # Set somewhere else... hopefully before tools run\n\ndef get_spending_history(category: str, days: int) -> dict:\n    # Uses global `db` and `current_user` \u2014 how do you test this?\n    # How do you run two users concurrently?\n    return db.query(\n        \"SELECT sum(amount) FROM transactions WHERE user_id = ? AND category = ? AND date > ?\",\n        current_user.id, category, days_ago(days)\n    )\n\n\n# Option B: Closure-based (awkward, deeply nested)\ndef make_tools(db, user):\n    def get_spending_history(category: str, days: int) -> dict:\n        return db.query(...)  # Captures db and user from enclosing scope\n\n    def lookup_merchant_category(merchant_name: str) -> str:\n        return db.query(...)  # Same closure trick\n\n    return [get_spending_history, lookup_merchant_category]\n\n# Every time you add a dependency, you restructure the closure nesting\n<\/code><\/pre>\n<p>\u062f\u0648\u0646\u0648\u06ba \u0646\u0642\u0637\u06c1 \u0646\u0638\u0631 \u062c\u0627\u0646\u0686 \u06a9\u0648 \u0645\u0634\u06a9\u0644 \u0628\u0646\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0622\u067e \u0627\u067e\u0646\u06d2 \u06a9\u0648\u0688 \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0628\u0646\u0627\u0626\u06d2 \u0628\u063a\u06cc\u0631 \u0641\u0631\u0636\u06cc \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06cc\u0627 \u0679\u06cc\u0633\u0679 \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0622\u0633\u0627\u0646\u06cc \u0633\u06d2 \u062a\u0628\u062f\u06cc\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u06d2\u06d4<\/p>\n<h3 id=\"heading-what-the-solution-should-look-like\">\u062d\u0644 \u06a9\u06cc\u0633\u0627 \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>\u0627\u06cc\u06a9 \u0628\u06c1\u062a\u0631 \u062d\u0644 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0622\u067e \u06a9\u0648 \u06cc\u06c1 \u0628\u062a\u0627\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2 \u06a9\u06c1 \u0622\u067e \u06a9\u0648 \u0627\u0633 \u0679\u0648\u0644 \u0633\u06d2 \u06a9\u06cc\u0627 \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4 LLM \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06c1 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062f\u06c1 \u0679\u0648\u0644 \u0622\u0631\u06af\u06cc\u0648\u0645\u06cc\u0646\u0679\u0633 \u0633\u06d2 \u0627\u0644\u06af \u0627\u0646 \u067e\u0679 \u0636\u0631\u0648\u0631\u06cc\u0627\u062a \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0627\u0646\u062d\u0635\u0627\u0631 (DB\u060c HTTP \u06a9\u0644\u0627\u0626\u0646\u0679\u060c \u0635\u0627\u0631\u0641 \u0633\u06cc\u0634\u0646) \u06a9\u0648 \u0638\u0627\u06c1\u0631 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<p>\u0645\u0632\u06cc\u062f \u0628\u0631\u0622\u06ba\u060c \u0627\u0633\u06d2 \u0688\u06cc\u0641\u06cc\u0646\u06cc\u0634\u0646 \u0679\u0627\u0626\u0645 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0631\u0646 \u0679\u0627\u0626\u0645 \u067e\u0631 \u0627\u0646\u062c\u06cc\u06a9\u0634\u0646 \u0644\u06af\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u0648 \u0686\u0644\u0627\u062a\u06d2 \u0648\u0642\u062a \u0627\u06cc\u06a9 \u0645\u062e\u0635\u0648\u0635 \u0645\u062b\u0627\u0644 \u067e\u0627\u0633 \u06a9\u0631\u06cc\u06ba\u060c \u0646\u06c1 \u06a9\u06c1 \u0679\u0648\u0644 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u062a\u06d2 \u0648\u0642\u062a\u06d4 \u06cc\u06c1 \u0679\u0648\u0644 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641\u0648\u06ba \u06a9\u0648 \u062e\u0627\u0644\u0635 \u0627\u0648\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0642\u0627\u0628\u0644 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0631\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0648\u0631 \u062c\u0627\u0646\u0686 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0646\u062d\u0635\u0627\u0631 \u06a9\u0627 \u062a\u0628\u0627\u062f\u0644\u06c1\u06d4 \u0627\u067e\u0646\u06d2 \u0679\u0648\u0644 \u06a9\u0648\u0688 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u06cc\u06d2 \u0628\u063a\u06cc\u0631 \u0627\u0635\u0644\u06cc \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u06a9\u0648 \u0627\u0646 \u0645\u06cc\u0645\u0648\u0631\u06cc \u0645\u0648\u06a9 \u0688\u06cc\u0679\u0627 \u0628\u06cc\u0633 \u0633\u06d2 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u06cc\u06ba \u06cc\u0627 \u0627\u0635\u0644\u06cc \u0635\u0627\u0631\u0641 \u06a9\u0648 \u0679\u06cc\u0633\u0679 \u0641\u06a9\u0633\u0686\u0631 \u0633\u06d2 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-how-pydantic-ai-solves-this\">Pydantic AI \u0627\u0633 \u0645\u0633\u0626\u0644\u06d2 \u06a9\u0648 \u06a9\u06cc\u0633\u06d2 \u062d\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>Pydantic AI \u0645\u06cc\u06ba \u0627\u0639\u0644\u06cc \u062f\u0631\u062c\u06d2 \u06a9\u0627 \u0627\u0646\u062d\u0635\u0627\u0631 \u0627\u0646\u062c\u06cc\u06a9\u0634\u0646 \u0633\u0633\u0679\u0645 \u06c1\u06d2\u06d4 \u062a\u0645 \u06c1\u0648 <code>deps_type<\/code> \u0627\u06cc\u062c\u0646\u0679 \u0627\u0648\u0631 \u0679\u0648\u0644\u0632 \u06cc\u06c1 \u0627\u0646\u062d\u0635\u0627\u0631 \u0627\u0646 \u067e\u0679 \u0641\u0627\u0631\u0645 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u062d\u0627\u0635\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>RunContext<\/code>\u06a9\u0648\u0626\u06cc \u0639\u0627\u0644\u0645\u06cc \u06cc\u0627 \u0628\u0646\u062f\u0634 \u0646\u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-python\">from dataclasses import dataclass\nfrom pydantic_ai import Agent, RunContext\n\n\n@dataclass\nclass ReceiptDeps:\n    db: DatabaseClient\n    user_id: str\n    http_client: HttpClient\n\n\nreceipt_agent = Agent(\n    \"openai:gpt-4o\",\n    output_type=ReceiptAnalysis,\n    deps_type=ReceiptDeps,\n    system_prompt=\"Analyze the provided receipt and extract structured details.\",\n)\n\n\n@receipt_agent.tool\ndef get_spending_history(ctx: RunContext[ReceiptDeps], category: str, days: int) -> dict:\n    \"\"\"Get spending totals by category for a date range.\"\"\"\n    return ctx.deps.db.query(\n        \"SELECT sum(amount), count(*) FROM transactions WHERE user_id = ? AND category = ? AND date > ?\",\n        ctx.deps.user_id, category, days_ago(days)\n    )\n\n\n@receipt_agent.tool\ndef get_exchange_rate(ctx: RunContext[ReceiptDeps], from_currency: str, to_currency: str) -> float:\n    \"\"\"Get current exchange rate between two currencies.\"\"\"\n    response = ctx.deps.http_client.get(f\"\/rates\/{from_currency}\/{to_currency}\")\n    return response.json()[\"rate\"]\n\n\n# At runtime \u2014 pass real dependencies\nresult = receipt_agent.run_sync(\n    \"CAFE PARIS\\n\u20ac12.50\\nCroissant x2\",\n    deps=ReceiptDeps(\n        db=get_database_connection(),\n        user_id=\"user_123\",\n        http_client=HttpClient(base_url=\"https:\/\/api.exchangerate.host\"),\n    ),\n)\n\n# In tests \u2014 swap with mocks, no code changes to tools\nresult = receipt_agent.run_sync(\n    \"CAFE PARIS\\n\u20ac12.50\\nCroissant x2\",\n    deps=ReceiptDeps(\n        db=InMemoryDb(fake_transactions),\n        user_id=\"test_user\",\n        http_client=MockHttpClient(fixed_rate=1.08),\n    ),\n)\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0622\u067e \u06a9\u0648 \u06a9\u06cc\u0627 \u062f\u06cc\u062a\u0627 \u06c1\u06d2:<\/p>\n<ul>\n<li>\n<p><strong>\u0679\u0648\u0644\u0632 \u0627\u0633 \u0628\u0627\u062a \u06a9\u0627 \u0627\u0639\u0644\u0627\u0646 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u0627\u0646\u06c1\u06cc\u06ba \u06a9\u0633 \u0686\u06cc\u0632 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u060c \u0646\u06c1 \u06a9\u06c1 \u0627\u0633\u06d2 \u06a9\u06cc\u0633\u06d2 \u062d\u0627\u0635\u0644 \u06a9\u0631\u0646\u0627 \u06c1\u06d2\u06d4<\/strong> <code>ctx.deps.db<\/code>    \u06cc\u06c1 \u062f\u0627\u062e\u0644 \u06c1\u06d2\u06d4 IDE \u0627\u0633 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u0627\u0631 \u06a9\u0648 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0645\u06a9\u0645\u0644 \u06a9\u0631\u06d2 \u06af\u0627 \u0627\u0648\u0631 \u0679\u0627\u0626\u067e \u0686\u06cc\u06a9\u0631 \u06a9\u0633\u06cc \u063a\u0644\u0637 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0648 \u067e\u06a9\u0691\u06d2 \u06af\u0627\u06d4 \u0679\u0648\u0644 \u06a9\u0648 \u0645\u0639\u0644\u0648\u0645 \u06cc\u0627 \u067e\u0631\u0648\u0627\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2 \u06a9\u06c1 \u0622\u06cc\u0627 \u06cc\u06c1 \u062d\u0642\u06cc\u0642\u06cc \u067e\u0648\u0633\u0679\u06af\u0631\u06cc\u0633 \u06a9\u0646\u06a9\u0634\u0646 \u06c1\u06d2 \u06cc\u0627 \u0679\u06cc\u0633\u0679 \u0645\u0648\u06a9 \u06a9\u0646\u06a9\u0634\u0646\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>\u06a9\u0648\u0626\u06cc \u0639\u0627\u0644\u0645\u06cc\u060c \u06a9\u0648\u0626\u06cc \u0628\u0646\u062f\u0634 \u0646\u06c1\u06cc\u06ba:<\/strong> \u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u062c\u06af\u06c1\u0648\u06ba \u067e\u0631 \u0627\u0646\u062d\u0635\u0627\u0631 \u06a9\u0648 \u0648\u0627\u0636\u062d \u0637\u0648\u0631 \u067e\u0631 \u0645\u062a\u0639\u0627\u0631\u0641 \u06a9\u0631\u0627\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2: <code>run_sync()<\/code> \u06af\u06be\u0646\u0679\u06c1 \u062f\u0648 \u0633\u0627\u062a\u06be\u06cc \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u0648 \u062f\u0648 \u0627\u0644\u06af \u0627\u0644\u06af \u0627\u062c\u0627\u0632\u062a\u06cc\u06ba \u0645\u0644\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 <code>ReceiptDeps<\/code> \u0627\u06cc\u06a9 \u0627\u06cc\u0633\u06cc \u0645\u062b\u0627\u0644 \u062c\u0633 \u0645\u06cc\u06ba \u06a9\u0648\u0626\u06cc \u0645\u0634\u062a\u0631\u06a9\u06c1 \u062a\u063a\u06cc\u0631 \u067e\u0630\u06cc\u0631 \u062d\u0627\u0644\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>\u0679\u06cc\u0633\u0679 \u0622\u0633\u0627\u0646 \u06c1\u06d2\u06d4<\/strong> \u062a\u0628\u0627\u062f\u0644\u06c1 <code>DatabaseClient<\/code> \u06a9\u06d2 \u0644\u06cc\u06d2 <code>InMemoryDb<\/code>\u0627\u0648\u0631 \u062a\u0628\u0627\u062f\u0644\u06c1 <code>HttpClient<\/code> \u06a9\u06d2 \u0644\u06cc\u06d2 <code>MockHttpClient<\/code>. \u0679\u0648\u0644 \u06a9\u0648\u0688 \u062a\u0628\u062f\u06cc\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u0645\u0627\u0688\u06cc\u0648\u0644 \u0633\u0637\u062d \u06a9\u06cc \u062d\u0627\u0644\u062a \u062a\u06a9 \u067e\u06c1\u0646\u0686\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0648\u0626\u06cc \u0628\u0646\u062f\u0631 \u067e\u06cc\u0686\u060c \u0627\u0646\u062d\u0635\u0627\u0631 \u0627\u0646\u062c\u06cc\u06a9\u0634\u0646 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9\u060c \u06cc\u0627 \u0679\u06cc\u0633\u0679 \u0641\u06a9\u0633\u0686\u0631 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>LLM \u0627\u0646\u062d\u0635\u0627\u0631 \u06a9\u06cc \u062c\u0627\u0646\u0686 \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/strong> <code>RunContext<\/code>    \u06cc\u06c1 \u0679\u0648\u0644 \u067e\u06cc\u0631\u0627\u0645\u06cc\u0679\u0631 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0633\u0627\u0645\u0646\u06d2 \u0646\u06c1\u06cc\u06ba \u0622\u06cc\u0627 \u06c1\u06d2\u06d4 \u0627\u06cc\u0644 \u0627\u06cc\u0644 \u0627\u06cc\u0645 \u0635\u0631\u0641 \u06c1\u06d2\u06d4 <code>category<\/code> \u0627\u0648\u0631 <code>days<\/code>. \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0627\u0633\u06d2 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u0633\u06d2 \u06c1\u0679\u0627 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"heading-problem-4-testing-requires-real-llm-calls\">\u0645\u0633\u0626\u0644\u06c1 4: \u0679\u06cc\u0633\u0679 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u062d\u0642\u06cc\u0642\u06cc LLM \u06a9\u0627\u0644 \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06d2\u06d4<\/h2>\n<p>\u0622\u067e \u0627\u0633 \u0628\u0627\u062a \u06a9\u0648 \u06cc\u0642\u06cc\u0646\u06cc \u0628\u0646\u0627\u0646\u0627 \u0686\u0627\u06c1\u062a\u06d2 \u06c1\u06cc\u06ba \u06a9\u06c1 \u0622\u067e \u06a9\u0627 \u0627\u06cc\u062c\u0646\u0679 \u063a\u06cc\u0631 \u0645\u0644\u06a9\u06cc \u06a9\u0631\u0646\u0633\u06cc \u06a9\u06cc \u0631\u0633\u06cc\u062f\u06cc\u06ba\u060c \u0628\u06cc\u0686\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u06d2 \u0646\u0627\u0645 \u063a\u0627\u0626\u0628\u060c \u0627\u0648\u0631 \u0645\u0628\u06c1\u0645 \u0632\u0645\u0631\u0648\u06ba \u062c\u06cc\u0633\u06d2 \u0627\u06c1\u0645 \u0645\u0639\u0627\u0645\u0644\u0627\u062a \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u062a\u0627\u06c1\u0645\u060c \u062a\u0645\u0627\u0645 \u0679\u06cc\u0633\u0679 \u0627\u0635\u0644 API \u06a9\u0648 \u0645\u0627\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-python\">def test_foreign_currency_receipt():\n    # This test:\n    # - Costs money (API call)\n    # - Takes 2-5 seconds\n    # - Is non-deterministic (might pass today, fail tomorrow)\n    # - Requires network access (breaks in CI without secrets)\n    result = analyze_receipt(\"CAF\u00c9 PARIS\\n\u20ac12.50\\nCroissant x2\")\n    assert result[\"currency\"] == \"EUR\"\n    assert result[\"category\"] == \"food\"  # Might return \"dining\" instead \u2014 flaky!\n<\/code><\/pre>\n<p>\u0622\u067e \u0627\u0633\u06d2 CI \u0645\u06cc\u06ba \u0642\u0627\u0628\u0644 \u0627\u0639\u062a\u0645\u0627\u062f \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u0646\u06c1\u06cc\u06ba \u0686\u0644\u0627 \u0633\u06a9\u062a\u06d2\u06d4 \u0622\u067e \u0627\u067e\u0646\u0627 API \u0628\u062c\u0679 \u062e\u062a\u0645 \u06a9\u06cc\u06d2 \u0628\u063a\u06cc\u0631 50 \u0627\u06cc\u062c \u06a9\u06cc\u0633 \u0679\u06cc\u0633\u0679 \u0646\u06c1\u06cc\u06ba \u0686\u0644\u0627 \u0633\u06a9\u062a\u06d2\u06d4 \u0622\u067e \u06a9\u0627 \u0627\u062e\u062a\u062a\u0627\u0645 \u06a9\u0648\u0626\u06cc \u0679\u06cc\u0633\u0679 \u06cc\u0627 \u0646\u0627\u06a9\u0627\u0645 \u0627\u0646\u0679\u06cc\u06af\u0631\u06cc\u0634\u0646 \u0679\u06cc\u0633\u0679\u0648\u06ba \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-what-the-solution-should-look-like\">\u062d\u0644 \u06a9\u06cc\u0633\u0627 \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>\u0633\u0628 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u060c LLM \u06a9\u0648 \u0627\u06cc\u06a9 \u062a\u0639\u06cc\u06cc\u0646\u0627\u062a\u06cc \u0645\u062a\u0628\u0627\u062f\u0644 \u0641\u0646\u06a9\u0634\u0646 \u0633\u06d2 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u06cc\u06ba\u06d4 \u0645\u0642\u0635\u062f \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u062c\u0627\u0646\u0686 \u06a9\u0648 \u062a\u06cc\u0632\u060c \u0645\u0641\u062a\u060c \u0627\u0648\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0642\u0627\u0628\u0644 \u062f\u06c1\u0631\u0627\u0646\u06d2 \u06a9\u06d2 \u0642\u0627\u0628\u0644 \u067e\u06cc\u0634\u06cc\u0646 \u06af\u0648\u0626\u06cc \u0627\u0648\u0631 \u06a9\u0646\u0679\u0631\u0648\u0644 \u0634\u062f\u06c1 \u062c\u0648\u0627\u0628\u0627\u062a \u0648\u0627\u067e\u0633 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u06af\u0644\u0627\u060c \u0627\u067e\u0646\u06d2 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06cc \u0645\u0646\u0637\u0642 \u06a9\u0648 \u0628\u0631\u0642\u0631\u0627\u0631 \u0631\u06a9\u06be\u06cc\u06ba\u06d4 \u0622\u067e \u06a9\u06d2 \u0679\u06cc\u0633\u0679\u0648\u06ba \u06a9\u0648 \u0627\u0635\u0644 \u0679\u0648\u0644 \u0688\u0633\u067e\u06cc\u0686\u060c \u062a\u0648\u062b\u06cc\u0642\u060c \u0627\u0648\u0631 \u0622\u0624\u0679 \u067e\u0679 \u067e\u0627\u0631\u0633 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u0635\u0631\u0641 \u0645\u0627\u0688\u0644 \u062c\u0639\u0644\u06cc \u06c1\u06d2\u06d4<\/p>\n<p>\u0622\u062e\u0631 \u0645\u06cc\u06ba\u060c \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc\u0648\u06ba \u067e\u0631 \u0627\u0635\u0631\u0627\u0631 \u06a9\u0631\u06cc\u06ba\u060c \u0627\u06cc\u0644 \u0627\u06cc\u0644 \u0627\u06cc\u0645 \u0628\u06cc\u0627\u0646\u0627\u062a \u067e\u0631 \u0646\u06c1\u06cc\u06ba\u06d4 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0635\u062d\u06cc\u062d \u0679\u0648\u0644 \u06a9\u0648 \u0635\u062d\u06cc\u062d \u062f\u0644\u0627\u0626\u0644 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0628\u0644\u0627\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u06cc\u06c1 \u06a9\u06c1 \u0622\u0624\u0679 \u067e\u0679 \u0645\u062a\u0648\u0642\u0639 \u0688\u06be\u0627\u0646\u0686\u06d2 \u0633\u06d2 \u0645\u06cc\u0644 \u06a9\u06be\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-how-pydantic-ai-solves-this\">Pydantic AI \u0627\u0633 \u0645\u0633\u0626\u0644\u06d2 \u06a9\u0648 \u06a9\u06cc\u0633\u06d2 \u062d\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>Pydantic AI \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06c1 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062f\u06c1 <code>TestModel<\/code> \u0627\u0648\u0631 <code>FunctionModel<\/code>. \u06cc\u06c1 \u0627\u06cc\u06a9 \u0688\u0631\u0627\u067e \u0627\u0646 \u0645\u0627\u0688\u0644 \u06a9\u0627 \u0645\u062a\u0628\u0627\u062f\u0644 \u06c1\u06d2 \u062c\u0648 \u0622\u067e \u06a9\u0648 \u0646\u06cc\u0679 \u0648\u0631\u06a9 \u06a9\u0627\u0644 \u06a9\u06cc\u06d2 \u0628\u063a\u06cc\u0631 \u0628\u0627\u0644\u06a9\u0644 &quot;LLM&#8221; \u06a9\u06cc \u0648\u0627\u067e\u0633\u06cc \u06a9\u0648 \u06a9\u0646\u0679\u0631\u0648\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-python\">from pydantic_ai import Agent\nfrom pydantic_ai.models.test import TestModel\nfrom pydantic_ai.models.function import FunctionModel\n\n\n# TestModel \u2014 returns a predictable, schema-valid response automatically\ndef test_receipt_analysis_structure():\n    \"\"\"Test that the agent returns a valid ReceiptAnalysis object.\"\"\"\n    with receipt_agent.override(model=TestModel()):\n        result = receipt_agent.run_sync(\n            \"CAFE PARIS\\n\u20ac12.50\\nCroissant x2\",\n            deps=ReceiptDeps(\n                db=InMemoryDb(fake_transactions),\n                user_id=\"test_user\",\n                http_client=MockHttpClient(fixed_rate=1.08),\n            ),\n        )\n        # TestModel fills fields with valid dummy data matching the schema\n        assert isinstance(result.output, ReceiptAnalysis)\n        assert 0 <= result.output.confidence <= 1\n\n\n# FunctionModel \u2014 you control the exact response for specific scenarios\ndef test_foreign_currency_triggers_exchange_rate_tool():\n    \"\"\"Test that a EUR receipt causes the agent to call get_exchange_rate.\"\"\"\n\n    def mock_model(messages, info):\n        # Simulate the LLM deciding to call the exchange rate tool\n        return ModelResponse(\n            tool_calls=[ToolCall(name=\"get_exchange_rate\", args={\"from_currency\": \"EUR\", \"to_currency\": \"USD\"})]\n        )\n\n    with receipt_agent.override(model=FunctionModel(mock_model)):\n        result = receipt_agent.run_sync(\n            \"CAFE PARIS\\n\u20ac12.50\\nCroissant x2\",\n            deps=ReceiptDeps(\n                db=InMemoryDb(fake_transactions),\n                user_id=\"test_user\",\n                http_client=MockHttpClient(fixed_rate=1.08),\n            ),\n        )\n        # Assert the exchange rate tool was actually invoked\n        tool_calls = [msg for msg in result.all_messages() if hasattr(msg, \"tool_name\")]\n        assert any(tc.tool_name == \"get_exchange_rate\" for tc in tool_calls)\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0645\u0641\u06cc\u062f \u06c1\u06d2 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u06cc\u06c1 \u062a\u06cc\u0632 \u0627\u0648\u0631 \u0645\u0641\u062a \u06c1\u06d2\u06d4 \u06a9\u0648\u0626\u06cc API \u06a9\u0627\u0644\u0632\u060c \u0646\u06cc\u0679 \u0648\u0631\u06a9 \u06cc\u0627 \u0679\u0648\u06a9\u0646 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u06d2 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0679\u06cc\u0633\u0679 \u0645\u0644\u06cc \u0633\u06cc\u06a9\u0646\u0688 \u0645\u06cc\u06ba \u0686\u0644\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u06cc\u06c1 \u062a\u0639\u06cc\u06cc\u0646 \u067e\u0633\u0646\u062f \u0628\u06be\u06cc \u06c1\u06d2\u06d4 \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u0627\u06cc\u06a9 \u06c1\u06cc \u0627\u0646 \u067e\u0679 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c \u0622\u067e \u06a9\u0648 \u06c1\u0631 \u0628\u0627\u0631 \u0627\u06cc\u06a9 \u06c1\u06cc \u0622\u0624\u0679 \u067e\u0679 \u0645\u0644\u062a\u0627 \u06c1\u06d2\u06d4 LLM \u062f\u0631\u062c\u06c1 \u062d\u0631\u0627\u0631\u062a \u06cc\u0627 \u0627\u0644\u0641\u0627\u0638 \u0645\u06cc\u06ba \u062a\u0628\u062f\u06cc\u0644\u06cc \u06a9\u06cc \u0648\u062c\u06c1 \u0633\u06d2 \u06a9\u0648\u0626\u06cc \u063a\u06cc\u0631 \u0645\u0633\u062a\u062d\u06a9\u0645 \u0679\u06cc\u0633\u0679 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u0635\u0644 \u0627\u06cc\u062c\u0646\u0679 \u0645\u0646\u0637\u0642 \u0628\u06be\u06cc \u0686\u0644\u062a\u06cc \u0631\u06c1\u062a\u06cc \u06c1\u06d2\u06d4 \u0679\u0648\u0644 \u0688\u0633\u067e\u06cc\u0686\u060c \u0627\u0646\u062d\u0635\u0627\u0631 \u0627\u0646\u062c\u06cc\u06a9\u0634\u0646\u060c \u0627\u0648\u0631 \u0622\u0624\u0679 \u067e\u0679 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u0633\u0628\u06be\u06cc \u06a9\u0648 \u0627\u0646\u062c\u0627\u0645 \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u0635\u0631\u0641 \u0645\u0627\u0688\u0644 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 CI \u062f\u0648\u0633\u062a\u0627\u0646\u06c1 \u0628\u06be\u06cc \u06c1\u06d2\u06d4 \u0627\u06cc\u06a9 CI \u0645\u0627\u062d\u0648\u0644 \u06a9\u0648 API \u06a9\u06cc\u0632 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u0627\u0646\u062a\u0638\u0627\u0645 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0648\u0626\u06cc \u0631\u0627\u0632 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u06cc\u0627 \u0634\u0631\u062d \u06a9\u06cc \u062d\u062f \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 \u06a9\u0646\u0679\u0631\u0648\u0644 \u06a9\u06cc \u062f\u0648 \u0633\u0637\u062d\u0648\u06ba \u06a9\u06cc \u0628\u06be\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u062a\u0645 \u06c1\u0648 <code>TestModel<\/code> \"\u06a9\u06cc\u0627 \u067e\u0644\u0645\u0628\u0646\u06af \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u061f\" \u0679\u06cc\u0633\u0679 \u0627\u0648\u0631 \u0622\u067e <code>FunctionModel<\/code> \"\u06a9\u06cc\u0627 \u0627\u06cc\u062c\u0646\u0679 \u0635\u062d\u06cc\u062d \u0641\u06cc\u0635\u0644\u06d2 \u06a9\u0631 \u0631\u06c1\u06d2 \u06c1\u06cc\u06ba\u061f\" \u06cc\u06c1 \u0627\u06cc\u06a9 \u0679\u06cc\u0633\u0679 \u06c1\u06d2 \u062c\u0648 \u0645\u062e\u0635\u0648\u0635 LLM \u0631\u0648\u06cc\u06d2 \u06a9\u0648 \u0627\u0633\u06a9\u0631\u067e\u0679 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-problem-5-retry-and-validation-logic-is-hand-rolled\">\u0645\u0633\u0626\u0644\u06c1 5: \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u062f\u0633\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0644\u06a9\u06be\u06cc \u06af\u0626\u06cc \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u0645\u0646\u0637\u0642<\/h2>\n<p>\u0627\u06af\u0631 LLM \u063a\u0644\u0637 \u062c\u0648\u0627\u0628 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u0622\u067e \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06cc \u0686\u0627\u06c1\u06cc\u06d2\u06d4 \u062a\u0627\u06c1\u0645\u060c \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u06cc \u0645\u0646\u0637\u0642 \u062a\u06cc\u0632\u06cc \u0633\u06d2 \u067e\u06cc\u0686\u06cc\u062f\u06c1 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-python\">def analyze_receipt_with_retry(receipt_text: str, max_retries: int = 3) -> dict:\n    for attempt in range(max_retries):\n        try:\n            response = client.chat.completions.create(...)\n            raw = response.choices[0].message.content\n            result = json.loads(strip_markdown(raw))\n\n            # Validate\n            if not isinstance(result.get(\"total\"), (int, float)):\n                raise ValueError(\"total must be numeric\")\n            if result.get(\"confidence\", 0) > 1 or result.get(\"confidence\", 0) < 0:\n                raise ValueError(\"confidence must be 0-1\")\n            if result.get(\"category\") not in ALLOWED_CATEGORIES:\n                raise ValueError(f\"invalid category: {result.get('category')}\")\n\n            return result\n\n        except (json.JSONDecodeError, ValueError, KeyError) as e:\n            if attempt == max_retries - 1:\n                raise\n            # Should we feed the error back to the LLM? Modify the prompt?\n            # How do we track which attempts failed and why?\n            continue\n\n    raise RuntimeError(\"Should not reach here\")\n<\/code><\/pre>\n<p>\u06c1\u0631 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u0648 \u062c\u0648 \u0622\u067e \u062a\u0639\u06cc\u0646\u0627\u062a \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0633\u06cc \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634\/\u062a\u0635\u062f\u06cc\u0642\/\u062f\u0648\u0628\u0627\u0631\u06c1 \u067e\u0631\u0627\u0645\u067e\u0679 \u067e\u06cc\u0679\u0631\u0646 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0622\u067e \u0627\u0633\u06d2 \u06c1\u0631 \u0628\u0627\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u06a9\u06be\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 LLM \u0645\u06cc\u06ba \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u0641\u06cc\u0688 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0645\u0646\u0637\u0642 \u062a\u0627\u06a9\u06c1 \u06cc\u06c1 \u062e\u0648\u062f \u06a9\u0648 \u062f\u0631\u0633\u062a \u06a9\u0631 \u0633\u06a9\u06d2 \u067e\u06cc\u0686\u06cc\u062f\u06af\u06cc \u06a9\u06cc \u0627\u06cc\u06a9 \u0627\u0648\u0631 \u067e\u0631\u062a \u06a9\u0627 \u0627\u0636\u0627\u0641\u06c1 \u06a9\u0631 \u062f\u06cc\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-what-the-solution-should-look-like\">\u062d\u0644 \u06a9\u06cc\u0633\u0627 \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>\u0633\u0628 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u060c \u062a\u0648\u062b\u06cc\u0642 \u0627\u0639\u0644\u0627\u0646\u06cc\u06c1 \u06c1\u0648\u0646\u0627 \u0636\u0631\u0648\u0631\u06cc \u06c1\u06d2. \u06cc\u0639\u0646\u06cc\u060c \u0627\u0633 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u0622\u0624\u0679 \u067e\u0679 \u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u06a9\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06d2\u060c \u0646\u06c1 \u06a9\u06c1 \u06c1\u0627\u062a\u06be \u0633\u06d2 \u0644\u06a9\u06be\u06d2 \u06c1\u0648\u0626\u06d2 \u0627\u06af\u0631 \u0628\u06cc\u0627\u0646\u0627\u062a \u067e\u0648\u0631\u06d2 \u06a9\u0648\u0688 \u0645\u06cc\u06ba \u0628\u06a9\u06be\u0631\u06d2 \u06c1\u0648\u06ba\u06d4<\/p>\n<p>\u062f\u0648\u0633\u0631\u0627\u060c \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634\u06cc\u06ba \u062e\u0648\u062f\u06a9\u0627\u0631 \u06c1\u0648\u0646\u06cc \u0686\u0627\u06c1\u0626\u06cc\u06ba\u06d4 \u0627\u06af\u0631 \u0622\u0624\u0679 \u067e\u0679 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u0645\u06cc\u06ba \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u062a\u0648 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06a9\u0648 \u062e\u0648\u062f \u06a9\u06cc \u0627\u0635\u0644\u0627\u062d \u06a9\u0648 \u0641\u0639\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 LLM \u06a9\u0648 \u0627\u06cc\u06a9 \u063a\u0644\u0637\u06cc \u06a9\u0627 \u067e\u06cc\u063a\u0627\u0645 \u0648\u0627\u067e\u0633 \u062f\u06a9\u06be\u0627\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0627\u0648\u0631 \u0622\u067e \u06a9\u06cc \u0627\u067e\u0646\u06cc \u0645\u0631\u0636\u06cc \u06a9\u06d2 \u0645\u0637\u0627\u0628\u0642 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0648 \u0627\u06cc\u06a9 \u062f\u0648\u0633\u0631\u06d2 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0635\u0627\u0641 \u0637\u0648\u0631 \u067e\u0631 \u0628\u0627\u0646\u062f\u06be\u0646\u0627 \u0686\u0627\u06c1\u0626\u06d2. \u06a9\u0627\u0631\u0648\u0628\u0627\u0631\u06cc \u0642\u0648\u0627\u0639\u062f \u06a9\u06d2 \u0644\u06cc\u06d2 \u062c\u0648 \u0679\u0627\u0626\u067e \u0686\u06cc\u06a9\u0646\u06af \u0633\u06d2 \u0622\u06af\u06d2 \u0628\u0691\u06be\u062a\u06d2 \u06c1\u06cc\u06ba (\u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \"\u0627\u06af\u0631 \u0632\u0645\u0631\u06c1 '\u062f\u06cc\u06af\u0631' \u06c1\u06d2\u060c \u062a\u0648 \u0627\u0639\u062a\u0645\u0627\u062f 0.8\" \u0633\u06d2 \u06a9\u0645 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2)\u060c \u0622\u067e \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0644\u0648\u067e \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u06a9\u06be\u06d2 \u0628\u063a\u06cc\u0631 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u0648\u06ba \u06a9\u0648 \u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0642\u0627\u0628\u0644 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<h3 id=\"heading-how-pydantic-ai-solves-this\">Pydantic AI \u0627\u0633 \u0645\u0633\u0626\u0644\u06d2 \u06a9\u0648 \u06a9\u06cc\u0633\u06d2 \u062d\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>\u0633\u06a9\u06cc\u0645\u0627 \u0644\u06cc\u0648\u0644 \u06a9\u06cc \u062a\u0648\u062b\u06cc\u0642 \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u06c1\u06cc Pydantic \u0645\u0627\u0688\u0644 \u0645\u06cc\u06ba \u0633\u0646\u0628\u06be\u0627\u0644 \u0644\u06cc \u06af\u0626\u06cc \u06c1\u06d2 (\u0645\u0633\u0626\u0644\u06c1 1 \u062f\u06cc\u06a9\u06be\u06cc\u06ba)\u06d4 \u062a\u0627\u06c1\u0645\u060c \u06a9\u0627\u0631\u0648\u0628\u0627\u0631\u06cc \u0645\u0646\u0637\u0642 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642 \u06a9\u06d2 \u0644\u06cc\u06d2\u060c Pydantic AI \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: <code>result_validator<\/code>. \u06cc\u06c1 \u0627\u06cc\u06a9 \u0688\u06cc\u06a9\u0648\u0631\u06cc\u0679\u0631 \u06c1\u06d2 \u062c\u0648 \u062a\u062c\u0632\u06cc\u06c1 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0628\u0639\u062f \u0686\u0644\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u062e\u0648\u062f\u06a9\u0627\u0631 \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634\u0648\u06ba \u06a9\u0648 \u0645\u062a\u062d\u0631\u06a9 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-python\">from pydantic_ai import Agent, RunContext, ModelRetry\n\n\nreceipt_agent = Agent(\n    \"openai:gpt-4o\",\n    output_type=ReceiptAnalysis,\n    deps_type=ReceiptDeps,\n    system_prompt=\"Analyze the provided receipt and extract structured details.\",\n    retries=3,  # Max retry attempts on validation failure\n)\n\n\n@receipt_agent.result_validator\ndef validate_receipt_analysis(ctx: RunContext[ReceiptDeps], result: ReceiptAnalysis) -> ReceiptAnalysis:\n    \"\"\"Business logic validation \u2014 runs after schema validation passes.\"\"\"\n\n    # Rule: if total doesn't match sum of items, ask LLM to fix it\n    items_sum = sum(item.amount for item in result.items)\n    if abs(result.total - items_sum) > 0.01:\n        raise ModelRetry(\n            f\"Total ({result.total}) doesn't match sum of items ({items_sum}). \"\n            f\"Please recheck the receipt and correct either the total or the item amounts.\"\n        )\n\n    # Rule: low confidence + \"other\" category likely means the LLM gave up \u2014 retry\n    if result.category == SpendingCategory.OTHER and result.confidence < 0.5:\n        raise ModelRetry(\n            \"Category is 'other' with low confidence. Look more carefully at the \"\n            \"merchant name and items to determine a more specific category.\"\n        )\n\n    return result\n<\/code><\/pre>\n<p>\u0627\u06af\u0631 \u062a\u0648\u062b\u06cc\u0642 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u062c\u0627\u062a\u06cc \u06c1\u06d2\u060c \u062a\u0648 \u062f\u0631\u062c \u0630\u06cc\u0644 \u06c1\u0648\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-plaintext\">\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502  Automatic Retry Flow                                       \u2502\n\u2502                                                             \u2502\n\u2502  LLM response                                               \u2502\n\u2502       \u2502                                                     \u2502\n\u2502       \u25bc                                                     \u2502\n\u2502  Schema validation (Pydantic model)                         \u2502\n\u2502       \u2502                                                     \u2502\n\u2502       \u251c\u2500\u2500 FAIL \u2192 error message sent back to LLM \u2192 retry     \u2502\n\u2502       \u2502                                                     \u2502\n\u2502       \u25bc                                                     \u2502\n\u2502  result_validator (your business rules)                     \u2502\n\u2502       \u2502                                                     \u2502\n\u2502       \u251c\u2500\u2500 ModelRetry raised \u2192 message sent to LLM \u2192 retry   \u2502\n\u2502       \u2502                                                     \u2502\n\u2502       \u25bc                                                     \u2502\n\u2502  PASS \u2192 return typed result                                 \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n<\/code><\/pre>\n<ul>\n<li>\n<p>\u0627\u0633\u06a9\u06cc\u0645\u0627 \u06a9\u06cc \u062e\u0644\u0627\u0641 \u0648\u0631\u0632\u06cc\u0627\u06ba (\u063a\u0644\u0637 \u0642\u0633\u0645\u06cc\u06ba\u060c \u06af\u0645\u0634\u062f\u06c1 \u0641\u06cc\u0644\u0688\u0632\u060c \u06af\u0646\u062a\u06cc \u06a9\u06cc \u0645\u0645\u0627\u062b\u0644\u062a\u06cc\u06ba) \u062e\u0648\u062f \u0628\u062e\u0648\u062f Pydantic \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u067e\u06a9\u0691\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u0633\u06cc\u0627\u0642 \u0648 \u0633\u0628\u0627\u0642 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 LLM \u06a9\u0648 \u0648\u0627\u067e\u0633 \u0628\u06be\u06cc\u062c\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u062a\u0627\u06a9\u06c1 \u0627\u0633\u06d2 \u0645\u0637\u0644\u0639 \u06a9\u06cc\u0627 \u062c\u0627\u0633\u06a9\u06d2\u06d4 <em>\u06a9\u06cc\u0627<\/em> \u0679\u06be\u06cc\u06a9 \u06a9\u0631\u06cc\u06ba<\/p>\n<\/li>\n<li>\n<p>\u06a9\u0627\u0631\u0648\u0628\u0627\u0631\u06cc \u0642\u0648\u0627\u0646\u06cc\u0646 \u06a9\u06cc \u06a9\u0633\u06cc \u0628\u06be\u06cc \u062e\u0644\u0627\u0641 \u0648\u0631\u0632\u06cc \u067e\u0631 \u0622\u067e \u06a9\u0648 \u067e\u06a9\u0691 \u0644\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4 <code>result_validator<\/code>. <code>ModelRetry<\/code> \u0635\u062d\u06cc\u062d \u062c\u0648\u0627\u0628 \u06a9\u06cc \u062d\u0648\u0635\u0644\u06c1 \u0627\u0641\u0632\u0627\u0626\u06cc \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u067e\u0646\u06d2 LLM \u06a9\u0648 \u062d\u0633\u0628 \u0636\u0631\u0648\u0631\u062a \u067e\u06cc\u063a\u0627\u0645\u0627\u062a \u0628\u06be\u06cc\u062c\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<li>\n<p>\u0622\u067e \u06a9\u06d2 \u06a9\u0648\u0688 \u0645\u06cc\u06ba \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u0644\u0648\u067e \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u06a9\u06c1 <code>retries=3<\/code> \u067e\u06cc\u0631\u0627\u0645\u06cc\u0679\u0631 \u06a9\u0648\u0634\u0634\u0648\u06ba \u06a9\u06cc \u0632\u06cc\u0627\u062f\u06c1 \u0633\u06d2 \u0632\u06cc\u0627\u062f\u06c1 \u062a\u0639\u062f\u0627\u062f \u06a9\u0648 \u06a9\u0646\u0679\u0631\u0648\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u0644\u0648\u067e\u0633\u060c \u062f\u0648\u0628\u0627\u0631\u06c1 \u0627\u0634\u0627\u0631\u06c1\u060c \u0627\u0648\u0631 \u0627\u06cc\u0631\u0631 \u0645\u06cc\u0633\u062c \u0641\u0627\u0631\u0645\u06cc\u0679\u0633 \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"heading-problem-6-switching-models-means-rewriting-integration-code\">\u0645\u0633\u0626\u0644\u06c1 6: \u0645\u0627\u0688\u0644\u0632 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u0627\u0646\u0679\u06cc\u06af\u0631\u06cc\u0634\u0646 \u06a9\u0648\u0688 \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u06a9\u06be\u0646\u0627<\/h2>\n<p>\u0627\u06cc\u062c\u0646\u0679 OpenAI \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06a9\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0628 \u0645\u06cc\u06ba \u0627\u0633\u06d2 \u0645\u0642\u0627\u0645\u06cc \u0637\u0648\u0631 \u067e\u0631 Anthropic (\u0645\u06cc\u0631\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06d2 \u0645\u0639\u0627\u0645\u0644\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0633\u0633\u062a\u0627) \u06cc\u0627 \u0627\u0648\u0644\u0627\u0645\u0627 (\u0688\u06cc\u0679\u0627 \u06a9\u06cc \u0631\u0627\u0632\u062f\u0627\u0631\u06cc \u06a9\u06d2 \u0644\u06cc\u06d2) \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0686\u0644\u0627\u0646\u0627 \u0686\u0627\u06c1\u062a\u0627 \u06c1\u0648\u06ba\u06d4 \u06c1\u0631 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0646\u0646\u062f\u06c1 \u06a9\u06d2 \u067e\u0627\u0633 \u0645\u062e\u062a\u0644\u0641 SDKs\u060c \u0679\u0648\u0644 \u06a9\u0627\u0644 \u0641\u0627\u0631\u0645\u06cc\u0679\u0633\u060c \u0627\u0648\u0631 \u0631\u0633\u067e\u0627\u0646\u0633 \u0627\u0633\u0679\u0631\u06a9\u0686\u0631 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-python\"># OpenAI\nresponse = openai_client.chat.completions.create(\n    model=\"gpt-4o\",\n    messages=messages,\n    tools=tools  # OpenAI tool format\n)\ntool_calls = response.choices[0].message.tool_calls\n\n# Anthropic \u2014 completely different API shape\nresponse = anthropic_client.messages.create(\n    model=\"claude-sonnet-4-20250514\",\n    messages=messages,\n    tools=anthropic_tools  # Different format than OpenAI!\n)\ntool_use_blocks = [b for b in response.content if b.type == \"tool_use\"]\n\n# Google \u2014 yet another shape\nresponse = genai_client.generate_content(\n    contents=messages,\n    tools=google_tools  # Yet another format!\n)\nfunction_calls = response.candidates[0].content.parts\n<\/code><\/pre>\n<p>\u0628\u0627\u0644\u0622\u062e\u0631\u060c \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0646\u0646\u062f\u06c1 \u06a9\u06d2 \u0645\u062e\u0635\u0648\u0635 \u06a9\u0648\u0688 \u06a9\u06d2 \u0631\u0627\u0633\u062a\u06d2\u060c \u0627\u0688\u0627\u067e\u0679\u0631 \u067e\u0631\u062a\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0627\u06cc\u062c\u0646\u0679 \u0645\u0646\u0637\u0642 \u0627\u0646\u0636\u0645\u0627\u0645 \u06af\u0644\u0648 \u06a9\u06d2 \u0646\u06cc\u0686\u06d2 \u062f\u0628 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-what-the-solution-should-look-like\">\u062d\u0644 \u06a9\u06cc\u0633\u0627 \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>\u0627\u06cc\u06a9 \u0628\u0627\u0631 \u0627\u067e\u0646\u06d2 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06cc \u0645\u0646\u0637\u0642 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u06a9\u06d2 \u0634\u0631\u0648\u0639 \u06a9\u0631\u06cc\u06ba\u06d4 \u0679\u0648\u0644\u0632\u060c \u0622\u0624\u0679 \u067e\u0679 \u06a9\u06cc \u0642\u0633\u0645\u06cc\u06ba\u060c \u0633\u0633\u0679\u0645 \u067e\u0631\u0627\u0645\u067e\u0679\u0633\u060c \u0627\u0648\u0631 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0627 \u0645\u0627\u0688\u0644 \u0622\u0632\u0627\u062f \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0645\u0632\u06cc\u062f \u0628\u0631\u0622\u06ba\u060c \u0622\u067e \u06a9\u0648 SDK \u06a9\u0627\u0644\u0632\u060c \u0679\u0648\u0644 \u0633\u06a9\u06cc\u0645\u0627\u060c \u06cc\u0627 \u0631\u0633\u067e\u0627\u0646\u0633 \u067e\u0627\u0631\u0633\u0646\u06af \u06a9\u0648 \u062f\u0648\u0628\u0627\u0631\u06c1 \u0644\u06a9\u06be\u0646\u06d2 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0633\u0679\u0631\u0646\u06af\u0632 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631 \u06a9\u06d2 \u0645\u0627\u0688\u0644\u0632 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0642\u0627\u0628\u0644 \u06c1\u0648\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<p>\u0627\u0648\u0631 \u0622\u067e \u06a9\u0648 \u0633\u067e\u0644\u0627\u0626\u0631 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u062e\u0635\u0648\u0635 \u062a\u0641\u0635\u06cc\u0644\u0627\u062a \u0686\u06be\u067e\u0627\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u06a9\u0648 \u06c1\u0631 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0646\u0646\u062f\u06c1 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06c1 \u0645\u062a\u0648\u0642\u0639 \u0641\u0627\u0631\u0645\u06cc\u0679 \u0645\u06cc\u06ba \u06cc\u0648\u0646\u06cc\u0648\u0631\u0633\u0644 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641 \u06a9\u0627 \u062a\u0631\u062c\u0645\u06c1 \u06a9\u0631\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2\u06d4<\/p>\n<h3 id=\"heading-how-pydantic-ai-solves-this\">Pydantic AI \u0627\u0633 \u0645\u0633\u0626\u0644\u06d2 \u06a9\u0648 \u06a9\u06cc\u0633\u06d2 \u062d\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/h3>\n<p>\u0627\u06cc\u062c\u0646\u0679 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641\u06cc\u06ba \u0645\u06a9\u0645\u0644 \u0637\u0648\u0631 \u067e\u0631 \u0645\u0627\u0688\u0644 \u0627\u06cc\u06af\u0646\u0648\u0633\u0679\u06a9 \u06c1\u06cc\u06ba\u06d4 \u0627\u06cc\u06a9 \u0645\u0627\u0688\u0644 \u0635\u0631\u0641 \u0627\u06cc\u06a9 \u062a\u0627\u0631 \u06a9\u0627 \u0634\u0646\u0627\u062e\u062a \u06a9\u0646\u0646\u062f\u06c1 \u06c1\u06d2\u06d4 \u0627\u06af\u0631 \u0622\u067e \u0645\u0627\u0688\u0644 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u062a\u0648 \u0628\u0627\u0642\u06cc \u0633\u0628 \u06a9\u0686\u06be \u0648\u06c1\u06cc \u0631\u06c1\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-python\"># Your agent definition \u2014 tools, output type, deps, validators \u2014 all unchanged\nreceipt_agent = Agent(\n    \"openai:gpt-4o\",  # \u2190 this is the only line that changes\n    output_type=ReceiptAnalysis,\n    deps_type=ReceiptDeps,\n    system_prompt=\"Analyze the provided receipt and extract structured details.\",\n)\n\n# Switch to Anthropic \u2014 same agent, same tools, same output type\nreceipt_agent = Agent(\n    \"anthropic:claude-sonnet-4-20250514\",\n    output_type=ReceiptAnalysis,\n    deps_type=ReceiptDeps,\n    system_prompt=\"Analyze the provided receipt and extract structured details.\",\n)\n\n# Switch to a local model via Ollama\nreceipt_agent = Agent(\n    \"ollama:llama3.1\",\n    output_type=ReceiptAnalysis,\n    deps_type=ReceiptDeps,\n    system_prompt=\"Analyze the provided receipt and extract structured details.\",\n)\n\n# Or make it configurable at runtime\nimport os\n\nreceipt_agent = Agent(\n    os.getenv(\"RECEIPT_AGENT_MODEL\", \"openai:gpt-4o\"),\n    output_type=ReceiptAnalysis,\n    deps_type=ReceiptDeps,\n    system_prompt=\"Analyze the provided receipt and extract structured details.\",\n)\n<\/code><\/pre>\n<p>\u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u067e\u0631\u062f\u06d2 \u06a9\u06d2 \u067e\u06cc\u0686\u06be\u06d2 \u06a9\u06cc\u0627 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2:<\/p>\n<ul>\n<li>\n<p><strong>\u0679\u0648\u0644 \u0633\u06a9\u06cc\u0645\u0627 \u062a\u0631\u062c\u0645\u06c1:<\/strong> \u0622\u067e \u06a9\u0627 <code>@receipt_agent.tool<\/code> \u0627\u0641\u0639\u0627\u0644 \u06a9\u0648 OpenAI \u0645\u06cc\u06ba \u062a\u0628\u062f\u06cc\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 <code>tools<\/code> \u0631\u0633\u0645\u06cc\u060c \u0628\u0634\u0631\u06cc\u0627\u062a <code>tools<\/code> \u0641\u0627\u0631\u0645\u06cc\u0679 \u06cc\u0627 \u06af\u0648\u06af\u0644 <code>function_declarations<\/code> - \u0622\u067e \u0627\u067e\u0646\u06d2 \u0645\u0646\u062a\u062e\u0628 \u0633\u067e\u0644\u0627\u0626\u0631 \u0633\u06d2 \u06a9\u06cc\u0627 \u062a\u0648\u0642\u0639 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0622\u067e \u06a9\u0648 \u06a9\u0628\u06be\u06cc \u0641\u0631\u0642 \u0646\u0638\u0631 \u0646\u06c1\u06cc\u06ba \u0622\u0626\u06d2 \u06af\u0627\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>\u0631\u062f\u0639\u0645\u0644 \u06a9\u0648 \u0645\u0639\u0645\u0648\u0644 \u067e\u0631 \u0644\u0627\u0646\u0627:<\/strong> \u06a9\u06cc\u0627 \u0645\u0627\u0688\u0644 \u0648\u0627\u067e\u0633 \u0622\u0626\u06d2 \u06af\u0627\u061f <code>choices[0].message.tool_calls<\/code> (\u0627\u0648\u067e\u0646 \u0627\u06d2 \u0622\u0626\u06cc)\u060c <code>content[].type == \"tool_use\"<\/code> (\u0627\u0646\u0633\u0627\u0646\u06cc\u062a) \u06cc\u0627 <code>candidates[0].content.parts<\/code> (\u06af\u0648\u06af\u0644)\u060c \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u0627\u0633\u06d2 \u0627\u06cc\u06a9 \u0645\u0633\u062a\u0642\u0644 \u0627\u0646\u062f\u0631\u0648\u0646\u06cc \u0646\u0645\u0627\u0626\u0646\u062f\u06af\u06cc \u0645\u06cc\u06ba \u0645\u0639\u0645\u0648\u0644 \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<li>\n<p><strong>\u0641\u0631\u0627\u06c1\u0645 \u06a9\u0646\u0646\u062f\u06c1 \u06a9\u06cc \u0645\u062e\u0635\u0648\u0635 \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u06a9\u0648 \u0634\u0641\u0627\u0641 \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u0633\u0646\u0628\u06be\u0627\u0644\u0627 \u06af\u06cc\u0627:<\/strong> \u06c1\u0631 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0646\u0646\u062f\u06c1 \u0633\u0627\u062e\u062a\u06cc \u0622\u0624\u0679 \u067e\u0679 \u0645\u0648\u0688\u060c \u0627\u0633\u0679\u0631\u06cc\u0645\u0646\u06af\u060c \u0627\u0648\u0631 \u0679\u0648\u06a9\u0646 \u06a9\u06cc\u0644\u06a9\u0648\u0644\u06cc\u0634\u0646 \u06a9\u0648 \u0645\u062e\u062a\u0644\u0641 \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u0644\u0627\u06af\u0648 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0641\u0631\u06cc\u0645 \u0648\u0631\u06a9 \u0622\u067e \u06a9\u06d2 \u06a9\u0648\u0688 \u0645\u06cc\u06ba \u0641\u0631\u0642 \u06a9\u0648 \u0638\u0627\u06c1\u0631 \u06a9\u06cc\u06d2 \u0628\u063a\u06cc\u0631 \u0627\u067e\u0646\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<\/ul>\n<p>\u0627\u06cc\u06a9 \u0627\u06cc\u062c\u0646\u0679 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641\u060c \u062a\u0645\u0627\u0645 \u0645\u0627\u0688\u0644\u0632\u06d4 \u06a9\u0646\u0641\u06cc\u06af\u0631\u06cc\u0634\u0646 \u06cc\u0627 \u0645\u0627\u062d\u0648\u0644\u06cc\u0627\u062a\u06cc \u0645\u062a\u063a\u06cc\u0631 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-wrapping-up\">\u062e\u062a\u0645<\/h2>\n<p>\u0627\u0633 \u0645\u0636\u0645\u0648\u0646 \u06a9\u06d2 \u062a\u0645\u0627\u0645 \u0645\u0633\u0627\u0626\u0644 \u0627\u06cc\u06a9 \u06c1\u06cc \u062c\u06af\u06c1 \u0633\u06d2 \u067e\u06cc\u062f\u0627 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 LLM \u06a9\u0627\u0644 \u0679\u06cc\u06a9\u0633\u0679 \u0627\u0646 \u067e\u0679\u060c \u0679\u06cc\u06a9\u0633\u0679 \u0622\u0624\u0679 \u067e\u0679\u060c \u0627\u0648\u0631 \u062f\u0648\u0646\u0648\u06ba \u0637\u0631\u0641 \u06a9\u0627 \u06a9\u0648\u0688 \u0627\u0646 \u067e\u0679 \u06c1\u06d2\u06d4 \u0645\u0642\u0627\u0645\u06cc SDK \u0646\u0642\u0637\u06c1 \u0646\u0638\u0631 \u06c1\u0627\u062a\u06be \u0633\u06d2 \u0644\u06a9\u06be\u06d2 \u06c1\u0648\u0626\u06d2 \u06af\u0644\u0648 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u0633 \u062e\u0644\u0627 \u06a9\u0648 \u067e\u064f\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: \u0628\u0627\u0691 \u06a9\u06d2 \u0627\u0633\u0679\u0631\u0627\u0626\u067e\u0631\u0632\u060c \u0627\u06af\u0631 \u0686\u06cc\u06a9 \u0686\u06cc\u0646\u0632\u060c \u0688\u0633\u067e\u06cc\u0686 \u0679\u06cc\u0628\u0644\u0632\u060c \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0644\u0648\u067e\u0633 \u0648\u063a\u06cc\u0631\u06c1\u06d4 \u06c1\u0631 \u0679\u06a9\u0691\u0627 \u0622\u0633\u0627\u0646 \u06c1\u06d2\u06d4 \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0648\u06c1 \u0627\u067e\u0646\u06d2 \u0627\u0631\u062f \u06af\u0631\u062f \u0627\u06cc\u062c\u0646\u0679 \u0644\u0627\u062c\u06a9\u0633 \u06a9\u0648 \u0622\u06af\u06d2 \u0628\u0691\u06be\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0622\u067e \u0627\u0646 \u0633\u0628 \u06a9\u06d2 \u0645\u0627\u0644\u06a9 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>Pydantic AI \u062d\u062f\u0648\u062f \u06a9\u0648 \u0627\u06cc\u06a9 \u0627\u0639\u0644\u0627\u0646 \u06a9\u0631\u062f\u06c1 \u0645\u0639\u0627\u06c1\u062f\u06c1 \u0628\u0646\u0627 \u06a9\u0631 \u062e\u0644\u0627 \u06a9\u0648 \u067e\u0648\u0631\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06c1\u0631 \u0633\u06cc\u06a9\u0634\u0646 \u06a9\u06d2 \u0645\u0646\u062f\u0631\u062c\u0627\u062a \u062f\u0631\u062c \u0630\u06cc\u0644 \u06c1\u06cc\u06ba:<\/p>\n<table>\n<thead>\n<tr>\n<th>\u0645\u0633\u0626\u0644\u06c1<\/th>\n<th>\u062e\u0627\u0645 SDK<\/th>\n<th>\u0641\u06cc\u0688\u0627\u0646\u0679\u06a9 AI<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u0633\u0627\u062e\u062a\u06cc \u067e\u06cc\u062f\u0627\u0648\u0627\u0631<\/td>\n<td>\u0627\u0633\u06a9\u06cc\u0645\u0627 \u0627\u0646\u06af\u0631\u06cc\u0632\u06cc \u0645\u06cc\u06ba \u0628\u06cc\u0627\u0646 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u0627\u0648\u0631 \u0628\u0631\u0627\u06c1 \u0631\u0627\u0633\u062a \u062a\u062c\u0632\u06cc\u06c1 \u06a9\u06cc\u0627 \u06af\u06cc\u0627\u06d4<\/td>\n<td><code>output_type=ReceiptAnalysis<\/code>    - \u0627\u0633\u06a9\u06cc\u0645\u0627 \u062c\u0646\u0631\u06cc\u0634\u0646\u060c \u0631\u062f\u0639\u0645\u0644 \u06a9\u06cc \u062a\u0635\u062f\u06cc\u0642<\/td>\n<\/tr>\n<tr>\n<td>\u0622\u0644\u06d2 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641<\/td>\n<td>JSON \u0627\u0633\u06a9\u06cc\u0645\u0627 + \u0688\u0633\u067e\u06cc\u0686 \u06a9\u06cc ~70 \u0644\u0627\u0626\u0646\u06cc\u06ba\u06d4<\/td>\n<td><code>@agent.tool_plain<\/code>    \u062f\u0627\u062e\u0644 \u06a9\u0631\u062f\u06c1 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u06d2 \u0628\u0627\u0631\u06d2 \u0645\u06cc\u06ba<\/td>\n<\/tr>\n<tr>\n<td>\u0631\u0646 \u0679\u0627\u0626\u0645 \u0633\u06cc\u0627\u0642 \u0648 \u0633\u0628\u0627\u0642<\/td>\n<td>\u0639\u0627\u0644\u0645\u06cc \u06cc\u0627 \u0646\u06cc\u0633\u0679\u0688 \u0628\u0646\u062f\u0634<\/td>\n<td><code>deps_type<\/code>    + <code>RunContext<\/code>\u0627\u0646\u062c\u06a9\u0634\u0646 \u0641\u06cc \u0631\u0646<\/td>\n<\/tr>\n<tr>\n<td>\u0679\u06cc\u0633\u0679<\/td>\n<td>\u0627\u0635\u0644 API \u06a9\u0627\u0644\u0632: \u0633\u0633\u062a\u060c \u0645\u06c1\u0646\u06af\u06cc\u060c \u0627\u0648\u0631 \u063a\u06cc\u0631 \u0645\u0633\u062a\u062d\u06a9\u0645<\/td>\n<td><code>TestModel<\/code>    \/ <code>FunctionModel<\/code>\u06a9\u0648\u0626\u06cc \u0646\u06cc\u0679 \u0648\u0631\u06a9 \u0646\u06c1\u06cc\u06ba<\/td>\n<\/tr>\n<tr>\n<td>\u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u062a\u0648\u062b\u06cc\u0642 \u06a9\u0631\u06cc\u06ba\u06d4<\/td>\n<td>\u06c1\u06cc\u0646\u0688 \u0631\u0648\u0644\u0688 \u0644\u0648\u067e\u0633\u060c \u063a\u0644\u0637\u06cc\u0627\u06ba \u062e\u062a\u0645 \u06a9\u0631 \u062f\u06cc \u06af\u0626\u06cc\u06ba\u06d4<\/td>\n<td>\u0641\u06cc\u0644\u0688 \u06a9\u06cc \u0631\u06a9\u0627\u0648\u0679\u06cc\u06ba + <code>ModelRetry<\/code>\u062e\u0631\u0627\u0628\u06cc \u06a9\u0648 \u0645\u0627\u0688\u0644 \u0645\u06cc\u06ba \u0641\u06cc\u0688 \u06a9\u0631 \u062f\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u06d4<\/td>\n<\/tr>\n<tr>\n<td>\u0645\u0627\u0688\u0644 \u06a9\u06cc \u062a\u0628\u062f\u06cc\u0644\u06cc<\/td>\n<td>\u0641\u0631\u0627\u06c1\u0645 \u06a9\u0646\u0646\u062f\u06c1 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u062e\u0635\u0648\u0635 SDKs \u0627\u0648\u0631 \u067e\u0627\u0631\u0633\u0646\u06af \u06a9\u0648\u0688<\/td>\n<td>1 \u062a\u0627\u0631: <code>\"openai:gpt-4o\"<\/code> \u2192 <code>\"anthropic:claude-sonnet-4-20250514\"<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u06c1\u0645\u0627\u0631\u0627 \u0645\u06a9\u0645\u0644 \u0634\u062f\u06c1 \u0631\u0633\u06cc\u062f \u0627\u06cc\u062c\u0646\u0679 \u0627\u06cc\u06a9 Pydantic \u0645\u0627\u0688\u0644\u060c \u0686\u0646\u062f \u0627\u0646 \u067e\u0679 \u0641\u0646\u06a9\u0634\u0646\u0632\u060c \u0627\u06cc\u06a9 \u0688\u06cc\u067e\u0633 \u0688\u06cc\u0679\u0627 \u06a9\u0644\u0627\u0633\u060c \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u062a\u0635\u062f\u06cc\u0642 \u06a9\u0646\u0646\u062f\u06c1 \u06c1\u06d2\u06d4 \u06a9\u0648\u0626\u06cc \u062a\u0635\u0631\u06cc\u0641 \u0646\u06c1\u06cc\u06ba\u060c \u06a9\u0648\u0626\u06cc \u0688\u0633\u067e\u06cc\u0686\u0646\u06af \u0646\u06c1\u06cc\u06ba\u060c \u06a9\u0648\u0626\u06cc \u062f\u0648\u0628\u0627\u0631\u06c1 \u06a9\u0648\u0634\u0634 \u0646\u06c1\u06cc\u06ba \u06a9\u06cc \u06af\u0626\u06cc\u06d4<\/p>\n<p>Pydantic AI \u062f\u0633\u062a\u0627\u0648\u06cc\u0632\u0627\u062a \u0645\u062e\u062a\u0635\u0631 \u0627\u0648\u0631 \u067e\u0691\u06be\u0646\u06d2 \u06a9\u06d2 \u0642\u0627\u0628\u0644 \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1\u0627\u06ba \u06c1\u0631 \u0686\u06cc\u0632 API \u06a9\u06d2 \u062d\u0648\u0627\u0644\u06c1 \u0633\u06d2 \u0646\u0642\u0634\u06c1 \u0628\u0646\u0627\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u0645\u0642\u0627\u0645\u06cc LLM SDK \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 AI \u0627\u06cc\u062c\u0646\u0679\u0648\u06ba \u06a9\u06cc \u062a\u0639\u0645\u06cc\u0631 \u0627\u0633 \u0648\u0642\u062a \u062a\u06a9 \u067e\u0631\u0648\u0679\u0648 \u0679\u0627\u0626\u067e\u0646\u06af \u06a9\u06d2 \u0644\u06cc\u06d2 \u0628\u06c1\u062a\u0631\u06cc\u0646 \u06c1\u06d2 \u062c\u0628 \u062a\u06a9 \u06a9\u06c1 \u0622\u067e \u06a9\u0648 \u0633\u0627\u062e\u062a\u06cc \u0622\u0624\u0679 \u067e\u0679\u060c \u0642\u0627\u0628\u0644 \u062c\u0627\u0646\u0686 \u06a9\u0648\u0688\u060c \u0627\u0648\u0631 \u067e\u06cc\u062f\u0627\u0648\u0627\u0631\u06cc \u0627\u0633\u062a\u062d\u06a9\u0627\u0645 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u0646\u06c1 \u06c1\u0648\u06d4 \u062e\u0644\u0627 \u062e\u0648\u062f \u06a9\u0648 \u067e\u06cc\u0634\u06cc\u0646 \u06af\u0648\u0626\u06cc \u06a9\u06d2 \u0637\u0631\u06cc\u0642\u0648\u06ba \u0633\u06d2 \u0638\u0627\u06c1\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0628 \u062c\u0628 \u06a9\u06c1 \u0622\u067e \u06a9\u0627 \u0646\u0648\u0679 [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-27685","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/posts\/27685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/comments?post=27685"}],"version-history":[{"count":0,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/posts\/27685\/revisions"}],"wp:attachment":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/media?parent=27685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/categories?post=27685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/tags?post=27685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}