{"id":97466,"date":"2026-08-29T15:25:06","date_gmt":"2026-08-29T07:25:06","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/97466.html"},"modified":"2026-08-29T15:25:06","modified_gmt":"2026-08-29T07:25:06","slug":"llm-%e8%b0%83%e7%94%a8%e7%9a%84%e5%9b%9b%e5%b1%82%e9%94%99%e8%af%af%e5%88%86%e7%b1%bb%e4%b8%8e%e6%b5%81%e5%bc%8f%e8%b6%85%e6%97%b6%e6%a3%80%e6%b5%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/97466.html","title":{"rendered":"LLM \u8c03\u7528\u7684\u56db\u5c42\u9519\u8bef\u5206\u7c7b\u4e0e\u6d41\u5f0f\u8d85\u65f6\u68c0\u6d4b"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829072502-6a92894eb83d1.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>TL;DR&#xff08;30 \u79d2\u901f\u89c8&#xff09;<\/h3>\n<ul>\n<li>Agent \u8c03\u7528 LLM API \u62a5\u9519\u4e86\u2014\u2014API Key \u8fc7\u671f&#xff1f;\u4e0a\u4e0b\u6587\u8d85\u957f&#xff1f;\u7f51\u7edc\u8d85\u65f6&#xff1f;\u9650\u6d41&#xff1f;\u4e0d\u540c Provider \u7684\u9519\u8bef\u683c\u5f0f\u5b8c\u5168\u4e0d\u540c<\/li>\n<li>\u56db\u5c42\u9519\u8bef\u5206\u7c7b&#xff1a;\u7ed3\u6784\u5316\u5f02\u5e38 \u2192 HTTP \u72b6\u6001\u7801 \u2192 Provider \u7279\u5b9a\u5f02\u5e38 \u2192 \u5173\u952e\u8bcd\u515c\u5e95<\/li>\n<li>\u4e09\u79cd\u9519\u8bef\u7c7b\u578b&#xff1a;Context Overflow&#xff08;\u538b\u7f29\u540e\u91cd\u8bd5&#xff09;\u3001Transient&#xff08;\u6307\u6570\u9000\u907f\u91cd\u8bd5&#xff09;\u3001Non-Transient&#xff08;\u7acb\u5373\u5931\u8d25&#xff09;<\/li>\n<li>\u53cc\u6d41\u505c\u6ede\u68c0\u6d4b&#xff1a;TTFT 240s&#xff08;\u9996 token \u8d85\u65f6&#xff09;&#043; Inter-chunk 120s&#xff08;chunk \u95f4\u9694\u8d85\u65f6&#xff09;<\/li>\n<li>\u5f02\u5e38\u94fe\u904d\u5386&#xff1a;MAX_CAUSE_DEPTH &#061; 16 \u9632\u6b62\u5faa\u73af\u5f15\u7528&#xff0c;\u6bcf\u5c42\u68c0\u67e5\u6240\u6709\u56db\u79cd\u7b56\u7565<\/li>\n<li>\u6838\u5fc3\u4ee3\u7801&#xff1a;LlmErrorClassifier&#xff08;237 \u884c&#xff09;&#043; AgentLoopRunner \u6d41\u5f0f\u8d85\u65f6&#xff08;335 \u884c&#xff09;<\/li>\n<\/ul>\n<hr \/>\n<p>\u524d\u60c5\u63d0\u8981&#xff1a;\u4e0a\u4e00\u7bc7\u6211\u4eec\u8bb2\u4e86 \u5168\u5f02\u6b65 MCP \u96c6\u6210\u2014\u2014\u53cc\u4f20\u8f93\u534f\u8bae\u3001Reactor \u2192 Coroutine \u6865\u63a5\u3001\u6309\u7528\u6237\u61d2\u52a0\u8f7d\u3002\u4eca\u5929\u8bb2 LLM \u8c03\u7528\u51fa\u9519\u65f6\u600e\u4e48\u529e\u3002<\/p>\n<hr \/>\n<h3>\u6838\u5fc3\u77db\u76fe<\/h3>\n<p>Agent \u8c03\u7528 LLM API \u62a5\u9519\u4e86\u3002<\/p>\n<p>OpenAI \u8bf4 &#034;context_length_exceeded&#034;&#xff0c;Anthropic \u8bf4 &#034;prompt is too long&#034;&#xff0c;DashScope \u8bf4 &#034;maximum context length is&#034;\u2014\u2014\u610f\u601d\u4e00\u6837&#xff0c;\u683c\u5f0f\u5b8c\u5168\u4e0d\u540c\u3002\u600e\u4e48\u5904\u7406&#xff1f;<\/p>\n<table>\n<tr>Provider\u9519\u8bef\u683c\u5f0f<\/tr>\n<tbody>\n<tr>\n<td>OpenAI<\/td>\n<td>400 &#8211; {&#034;error&#034;:{&#034;code&#034;:&#034;context_length_exceeded&#034;}}<\/td>\n<\/tr>\n<tr>\n<td>Anthropic<\/td>\n<td>400 &#8211; {&#034;type&#034;:&#034;error&#034;,&#034;error&#034;:{&#034;type&#034;:&#034;invalid_request_error&#034;,&#034;message&#034;:&#034;prompt is too long&#034;}}<\/td>\n<\/tr>\n<tr>\n<td>DashScope<\/td>\n<td>400 &#8211; {&#034;code&#034;:&#034;InvalidParameter&#034;,&#034;message&#034;:&#034;maximum context length is 128000&#034;}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>EasyAI \u7684\u65b9\u6848&#xff1a;\u56db\u5c42\u68c0\u6d4b\u7b56\u7565 &#043; \u7edf\u4e00\u5206\u7c7b\u3002<\/p>\n<hr \/>\n<h3>\u56db\u5c42\u9519\u8bef\u5206\u7c7b<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829072504-6a9289500244f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>Layer 1: \u7ed3\u6784\u5316\u5f02\u5e38&#xff08;NonTransientAiException \/ TransientAiException&#xff09;<br \/>\n  \u2193 \u672a\u547d\u4e2d<br \/>\nLayer 2: HTTP \u72b6\u6001\u7801&#xff08;400 &#061; \u4e0a\u4e0b\u6587\u6ea2\u51fa, 429 &#061; \u9650\u6d41, 5xx &#061; \u670d\u52a1\u4e0d\u53ef\u7528&#xff09;<br \/>\n  \u2193 \u672a\u547d\u4e2d<br \/>\nLayer 3: Provider \u7279\u5b9a\u5f02\u5e38&#xff08;OpenAI ApiError, Anthropic ApiException&#xff09;<br \/>\n  \u2193 \u672a\u547d\u4e2d<br \/>\nLayer 4: \u5173\u952e\u8bcd\u515c\u5e95&#xff08;&#034;context_length&#034;, &#034;rate_limit&#034;, &#034;timeout&#034; \u7b49&#xff09;<\/p>\n<h4>\u4e0a\u4e0b\u6587\u6ea2\u51fa\u68c0\u6d4b<\/h4>\n<p><span class=\"token comment\">\/\/ LlmErrorClassifier.isContextOverflow()<\/span><br \/>\n<span class=\"token keyword\">fun<\/span> <span class=\"token function\">isContextOverflow<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token operator\">:<\/span> Throwable<span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span> Boolean <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">var<\/span> current<span class=\"token operator\">:<\/span> Throwable<span class=\"token operator\">?<\/span> <span class=\"token operator\">&#061;<\/span> e<br \/>\n    <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span>current <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ Layer 1: Spring AI \u7ed3\u6784\u5316\u5f02\u5e38<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>current <span class=\"token keyword\">is<\/span> NonTransientAiException<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">isContextOverflowMessage<\/span><span class=\"token punctuation\">(<\/span>current<span class=\"token punctuation\">.<\/span>message<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">true<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token comment\">\/\/ Layer 2: HTTP 400 \u72b6\u6001\u7801<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> message <span class=\"token operator\">&#061;<\/span> current<span class=\"token punctuation\">.<\/span>message<span class=\"token operator\">?<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">lowercase<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">?:<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;&#034;<\/span><\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>message<span class=\"token punctuation\">.<\/span><span class=\"token function\">startsWith<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;400&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">||<\/span> message<span class=\"token punctuation\">.<\/span><span class=\"token function\">contains<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;400 -&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&amp;&amp;<\/span><br \/>\n            <span class=\"token function\">isContextOverflowMessage<\/span><span class=\"token punctuation\">(<\/span>message<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">true<\/span><br \/>\n        <span class=\"token comment\">\/\/ Layer 3: Provider \u7279\u5b9a\u5f02\u5e38<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">isProviderContextOverflowException<\/span><span class=\"token punctuation\">(<\/span>current<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">true<\/span><br \/>\n        current <span class=\"token operator\">&#061;<\/span> current<span class=\"token punctuation\">.<\/span>cause<br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ Layer 4: \u5173\u952e\u8bcd\u515c\u5e95&#xff08;\u53ea\u68c0\u67e5\u6700\u5916\u5c42\u5f02\u5e38&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token function\">isContextOverflowMessage<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">.<\/span>message<span class=\"token operator\">?<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">lowercase<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">?:<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u5173\u952e\u8bcd\u5339\u914d<\/h4>\n<p><span class=\"token keyword\">private<\/span> <span class=\"token keyword\">fun<\/span> <span class=\"token function\">isContextOverflowMessage<\/span><span class=\"token punctuation\">(<\/span>message<span class=\"token operator\">:<\/span> String<span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span> Boolean <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> message<span class=\"token punctuation\">.<\/span><span class=\"token function\">contains<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;context_length&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">||<\/span>      <span class=\"token comment\">\/\/ OpenAI<\/span><br \/>\n           message<span class=\"token punctuation\">.<\/span><span class=\"token function\">contains<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;prompt is too long&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">||<\/span>  <span class=\"token comment\">\/\/ Anthropic<\/span><br \/>\n           message<span class=\"token punctuation\">.<\/span><span class=\"token function\">contains<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;maximum context length&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">||<\/span> <span class=\"token comment\">\/\/ DashScope<\/span><br \/>\n           message<span class=\"token punctuation\">.<\/span><span class=\"token function\">contains<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;context length exceeded&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">||<\/span><br \/>\n           message<span class=\"token punctuation\">.<\/span><span class=\"token function\">contains<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;too many tokens&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5173\u952e&#xff1a;\u4e0d\u80fd\u628a API Key \u9519\u8bef\u8bef\u5224\u4e3a\u4e0a\u4e0b\u6587\u6ea2\u51fa\u2014\u2014\u5426\u5219\u65e0\u9650\u91cd\u8bd5\u3002<\/p>\n<h4>\u8d85\u65f6\u68c0\u6d4b<\/h4>\n<p><span class=\"token keyword\">fun<\/span> <span class=\"token function\">isTimeout<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token operator\">:<\/span> Throwable<span class=\"token punctuation\">)<\/span><span class=\"token operator\">:<\/span> Boolean <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">var<\/span> current<span class=\"token operator\">:<\/span> Throwable<span class=\"token operator\">?<\/span> <span class=\"token operator\">&#061;<\/span> e<br \/>\n    <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span>current <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>current <span class=\"token keyword\">is<\/span> TransientAiException<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">true<\/span>       <span class=\"token comment\">\/\/ Layer 1<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>current <span class=\"token keyword\">is<\/span> SocketTimeoutException <span class=\"token operator\">||<\/span>                <span class=\"token comment\">\/\/ Layer 2<\/span><br \/>\n            current <span class=\"token keyword\">is<\/span> TimeoutException <span class=\"token operator\">||<\/span><br \/>\n            current <span class=\"token keyword\">is<\/span> ResourceAccessException<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">true<\/span><br \/>\n        <span class=\"token comment\">\/\/ Layer 3-4: \u6d88\u606f\u5173\u952e\u8bcd<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> message <span class=\"token operator\">&#061;<\/span> current<span class=\"token punctuation\">.<\/span>message<span class=\"token operator\">?<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">lowercase<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">?:<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;&#034;<\/span><\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>message<span class=\"token punctuation\">.<\/span><span class=\"token function\">contains<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;timeout&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">||<\/span> message<span class=\"token punctuation\">.<\/span><span class=\"token function\">contains<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;timed out&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">true<\/span><br \/>\n        current <span class=\"token operator\">&#061;<\/span> current<span class=\"token punctuation\">.<\/span>cause<br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">false<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u5f02\u5e38\u94fe\u904d\u5386<\/h4>\n<p><span class=\"token comment\">\/\/ \u5f02\u5e38\u53ef\u80fd\u5d4c\u5957\u591a\u5c42&#xff1a;RuntimeException \u2192 IOException \u2192 SocketTimeoutException<\/span><br \/>\n<span class=\"token comment\">\/\/ MAX_CAUSE_DEPTH &#061; 16 \u9632\u6b62\u5faa\u73af\u5f15\u7528<\/span><br \/>\n<span class=\"token keyword\">private<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">val<\/span> MAX_CAUSE_DEPTH <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">16<\/span><\/p>\n<p>\u6bcf\u5c42\u90fd\u68c0\u67e5\u6240\u6709\u56db\u79cd\u7b56\u7565&#xff0c;\u786e\u4fdd\u6df1\u5c42\u5d4c\u5957\u7684\u5f02\u5e38\u4e5f\u80fd\u88ab\u6b63\u786e\u5206\u7c7b\u3002<\/p>\n<hr \/>\n<h3>\u53cc\u6d41\u505c\u6ede\u68c0\u6d4b<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829072504-6a928950d1ba6.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>\u95ee\u9898<\/h4>\n<p>LLM \u6d41\u5f0f\u54cd\u5e94\u53ef\u80fd&#034;\u5361\u4f4f&#034;&#xff1a;HTTP \u8fde\u63a5\u8fd8\u6d3b\u7740&#xff0c;\u4f46\u4e0d\u518d\u53d1\u9001\u65b0 chunk\u3002\u4f20\u7edf\u7684 HTTP \u8d85\u65f6\u4e0d\u68c0\u6d4b\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n<h4>\u53cc\u8d85\u65f6\u673a\u5236<\/h4>\n<p><span class=\"token comment\">\/\/ AgentLoopRunner<\/span><br \/>\n<span class=\"token keyword\">companion<\/span> <span class=\"token keyword\">object<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/** TTFT: \u4ece\u53d1\u9001\u8bf7\u6c42\u5230\u6536\u5230\u7b2c\u4e00\u4e2a chunk *\/<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">val<\/span> FIRST_CHUNK_TIMEOUT_SECONDS <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">240L<\/span><br \/>\n    <span class=\"token comment\">\/** Inter-chunk: \u4e24\u4e2a chunk \u4e4b\u95f4\u7684\u6700\u5927\u95f4\u9694 *\/<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token keyword\">val<\/span> STREAM_STALL_TIMEOUT_SECONDS <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">120L<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<table>\n<tr>\u8d85\u65f6\u503c\u542b\u4e49<\/tr>\n<tbody>\n<tr>\n<td>TTFT<\/td>\n<td>240s<\/td>\n<td>\u4ece\u53d1\u9001\u8bf7\u6c42\u5230\u6536\u5230\u7b2c\u4e00\u4e2a chunk&#xff08;LLM \u9700\u8981\u65f6\u95f4\u601d\u8003&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>Inter-chunk<\/td>\n<td>120s<\/td>\n<td>\u4e24\u4e2a chunk \u4e4b\u95f4\u7684\u6700\u5927\u95f4\u9694&#xff08;\u6d41\u5f0f\u54cd\u5e94\u4e2d\u9014\u505c\u6ede&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u5b9e\u73b0<\/h4>\n<p><span class=\"token comment\">\/\/ AgentLoopRunner \u4e2d\u7684\u6d41\u5f0f\u6d88\u8d39\u5faa\u73af<\/span><br \/>\n<span class=\"token keyword\">var<\/span> receivedContentChunk <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">false<\/span><br \/>\n<span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token boolean\">true<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ TTFT \u7528\u66f4\u957f\u7684\u8d85\u65f6&#xff08;LLM \u9700\u8981\u5904\u7406 Prompt&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> baseTimeout <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token operator\">!<\/span>receivedContentChunk <span class=\"token operator\">&amp;&amp;<\/span> chunkCount <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        FIRST_CHUNK_TIMEOUT_SECONDS<span class=\"token punctuation\">.<\/span>seconds  <span class=\"token comment\">\/\/ 240s<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        STREAM_STALL_TIMEOUT_SECONDS<span class=\"token punctuation\">.<\/span>seconds  <span class=\"token comment\">\/\/ 120s<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> result <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">withTimeoutOrNull<\/span><span class=\"token punctuation\">(<\/span>baseTimeout<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        channel<span class=\"token punctuation\">.<\/span><span class=\"token function\">receiveCatching<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>result <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u8d85\u65f6&#xff01;<\/span><br \/>\n        <span class=\"token keyword\">val<\/span> phase <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>chunkCount <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;first token (TTFT)&#034;<\/span><\/span> <span class=\"token keyword\">else<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;subsequent chunk&#034;<\/span><\/span><br \/>\n        <span class=\"token keyword\">throw<\/span> <span class=\"token function\">TimeoutException<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;LLM stream stalled: no <\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">$<\/span><span class=\"token expression\">phase<\/span><\/span><span class=\"token string\"> received within <\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span><span class=\"token expression\">timeoutSec<\/span><span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token string\">s&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> chunk <span class=\"token operator\">&#061;<\/span> result<span class=\"token punctuation\">.<\/span><span class=\"token function\">getOrNull<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">?:<\/span> <span class=\"token keyword\">break<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u8df3\u8fc7\u7a7a chunk&#xff08;SSE keepalive&#xff09;&#xff0c;\u4e0d\u91cd\u7f6e\u8ba1\u65f6\u5668<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>chunk<span class=\"token punctuation\">.<\/span>results<span class=\"token punctuation\">.<\/span><span class=\"token function\">isEmpty<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">||<\/span> chunk<span class=\"token punctuation\">.<\/span>results<span class=\"token punctuation\">.<\/span><span class=\"token function\">all<\/span> <span class=\"token punctuation\">{<\/span> it<span class=\"token punctuation\">.<\/span>output<span class=\"token punctuation\">.<\/span>text<span class=\"token punctuation\">.<\/span><span class=\"token function\">isNullOrEmpty<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">continue<\/span>  <span class=\"token comment\">\/\/ \u7a7a chunk \u4e0d\u8868\u793a LLM \u5728\u5de5\u4f5c<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    receivedContentChunk <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5904\u7406 chunk&#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u72ec\u7acb\u4e8e HTTP \u5c42<\/h4>\n<p>\u4e0d\u5728 Netty\/OkHttp \u5c42\u8bbe\u7f6e\u8d85\u65f6&#xff08;\u90a3\u662f\u8fde\u63a5\u7ea7\u8d85\u65f6&#xff09;&#xff0c;\u800c\u662f\u5728\u5e94\u7528\u5c42\u68c0\u6d4b&#xff1a;\u6bcf\u4e2a chunk \u5230\u8fbe\u65f6\u91cd\u7f6e\u8ba1\u65f6\u5668\u3002<\/p>\n<hr \/>\n<h3>Agent \u5faa\u73af\u4e2d\u7684\u9519\u8bef\u5904\u7406<\/h3>\n<h4>\u4e0a\u4e0b\u6587\u6ea2\u51fa\u81ea\u6108<\/h4>\n<p>AgentLoop.runInnerLoop()<br \/>\n  \u2192 callLLMWithOverflowHandling()<br \/>\n    \u2192 \u8c03\u7528 LLM<br \/>\n    \u2192 \u6355\u83b7\u5f02\u5e38<br \/>\n    \u2192 LlmErrorClassifier.isContextOverflow(e)?<br \/>\n      \u2192 true: \u89e6\u53d1 ContextCompactionOrchestrator \u538b\u7f29<br \/>\n             \u2192 \u538b\u7f29\u5b8c\u6210\u540e\u900f\u660e\u91cd\u8bd5&#xff08;\u540c\u4e00\u8f6e&#xff09;<br \/>\n      \u2192 false: \u6b63\u5e38\u5f02\u5e38\u5904\u7406<\/p>\n<h4>\u91cd\u8bd5\u7b56\u7565<\/h4>\n<p><span class=\"token comment\">\/\/ AgentLoopRunner \u4e2d\u7684\u91cd\u8bd5\u903b\u8f91<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>retryCount <span class=\"token operator\">&lt;<\/span> context<span class=\"token punctuation\">.<\/span>maxRetries <span class=\"token operator\">&amp;&amp;<\/span> <span class=\"token function\">isTimeoutException<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    retryCount<span class=\"token operator\">&#043;&#043;<\/span><br \/>\n    <span class=\"token keyword\">val<\/span> backoffMs <span class=\"token operator\">&#061;<\/span> retryCount <span class=\"token operator\">*<\/span> <span class=\"token number\">1000L<\/span>  <span class=\"token comment\">\/\/ \u7ebf\u6027\u9000\u907f<\/span><br \/>\n    logger<span class=\"token punctuation\">.<\/span><span class=\"token function\">warn<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;LLM call timed out, retrying ({}\/{}) after {}ms&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span> retryCount<span class=\"token punctuation\">,<\/span> context<span class=\"token punctuation\">.<\/span>maxRetries<span class=\"token punctuation\">,<\/span> backoffMs<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">RetryEvent<\/span><span class=\"token punctuation\">(<\/span>messageId<span class=\"token punctuation\">,<\/span> retryCount<span class=\"token punctuation\">,<\/span> context<span class=\"token punctuation\">.<\/span>maxRetries<span class=\"token punctuation\">,<\/span> backoffMs<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">..<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token function\">delay<\/span><span class=\"token punctuation\">(<\/span>backoffMs<span class=\"token punctuation\">.<\/span>milliseconds<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u91cd\u7f6e\u7d2f\u52a0\u5668<\/span><br \/>\n    fullText<span class=\"token punctuation\">.<\/span><span class=\"token function\">clear<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    fullThinking<span class=\"token punctuation\">.<\/span><span class=\"token function\">clear<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">throw<\/span> e  <span class=\"token comment\">\/\/ Non-Transient \u6216\u91cd\u8bd5\u6b21\u6570\u7528\u5c3d<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<table>\n<tr>\u9519\u8bef\u7c7b\u578b\u5904\u7406\u7b56\u7565\u91cd\u8bd5<\/tr>\n<tbody>\n<tr>\n<td>Context Overflow<\/td>\n<td>\u538b\u7f29\u4e0a\u4e0b\u6587 \u2192 \u91cd\u8bd5<\/td>\n<td>\u6700\u591a 1 \u6b21<\/td>\n<\/tr>\n<tr>\n<td>Transient&#xff08;\u8d85\u65f6\/5xx\/\u9650\u6d41&#xff09;<\/td>\n<td>\u6307\u6570\u9000\u907f\u91cd\u8bd5<\/td>\n<td>\u6700\u591a N \u6b21<\/td>\n<\/tr>\n<tr>\n<td>Non-Transient&#xff08;API Key \u65e0\u6548&#xff09;<\/td>\n<td>\u7acb\u5373\u5931\u8d25<\/td>\n<td>\u4e0d\u91cd\u8bd5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u7194\u65ad\u5668\u96c6\u6210<\/h4>\n<p><span class=\"token comment\">\/\/ \u8fde\u63a5\u9519\u8bef\u3001\u6d41\u505c\u6ede\u30015xx \u2192 \u62a5\u544a\u7ed9\u7aef\u70b9\u7194\u65ad\u5668<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>LlmErrorClassifier<span class=\"token punctuation\">.<\/span><span class=\"token function\">isEndpointOutage<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    breaker<span class=\"token operator\">?<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">recordFailure<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\">\/\/ \u9650\u6d41\u548c\u5ba2\u6237\u7aef\u9519\u8bef\u4e0d\u8ba1\u5165\u7194\u65ad<\/span><\/p>\n<hr \/>\n<h3>\u8de8 Provider \u517c\u5bb9\u6027<\/h3>\n<table>\n<tr>Provider\u5df2\u9a8c\u8bc1\u7684\u9519\u8bef\u683c\u5f0f<\/tr>\n<tbody>\n<tr>\n<td>OpenAI<\/td>\n<td>400 &#8211; {&#034;error&#034;:{&#034;code&#034;:&#034;context_length_exceeded&#034;}}<\/td>\n<\/tr>\n<tr>\n<td>Anthropic<\/td>\n<td>400 &#8211; {&#034;type&#034;:&#034;error&#034;,&#034;error&#034;:{&#034;type&#034;:&#034;invalid_request_error&#034;,&#034;message&#034;:&#034;prompt is too long&#034;}}<\/td>\n<\/tr>\n<tr>\n<td>DashScope<\/td>\n<td>400 &#8211; {&#034;code&#034;:&#034;InvalidParameter&#034;,&#034;message&#034;:&#034;maximum context length is 128000&#034;}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u56db\u5c42\u68c0\u6d4b\u786e\u4fdd\u5373\u4f7f Provider \u6539\u53d8\u4e86\u9519\u8bef\u683c\u5f0f&#xff0c;\u5173\u952e\u8bcd\u515c\u5e95\u4e5f\u80fd\u8986\u76d6\u3002\u65b0\u589e Provider \u65f6\u53ea\u9700\u5728 Layer 3 \u6dfb\u52a0 Provider \u7279\u5b9a\u68c0\u6d4b\u3002<\/p>\n<hr \/>\n<h3>\u76d1\u63a7\u4e0e\u65e5\u5fd7<\/h3>\n<p><span class=\"token comment\">\/\/ \u6bcf\u6b21\u9519\u8bef\u5206\u7c7b\u90fd\u8bb0\u5f55\u65e5\u5fd7<\/span><br \/>\nlogger<span class=\"token punctuation\">.<\/span><span class=\"token function\">warn<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;LLM error classified as {}: {}&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span> type<span class=\"token punctuation\">,<\/span> message<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u4e0a\u4e0b\u6587\u6ea2\u51fa\u81ea\u6108\u65f6\u63a8\u9001 SSE \u4e8b\u4ef6<\/span><br \/>\n<span class=\"token comment\">\/\/ \u524d\u7aef\u53ef\u4ee5\u770b\u5230&#034;\u4e0a\u4e0b\u6587\u8d85\u957f&#xff0c;\u6b63\u5728\u81ea\u52a8\u538b\u7f29&#034;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u6d41\u505c\u6ede\u8d85\u65f6\u65f6\u8bb0\u5f55<\/span><br \/>\nlogger<span class=\"token punctuation\">.<\/span><span class=\"token function\">error<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;LLM stream stalled: no {} received within {}s (provider&#061;{}, lastChunk&#061;{})&#034;<\/span><\/span><span class=\"token punctuation\">,<\/span><br \/>\n    phase<span class=\"token punctuation\">,<\/span> timeoutSec<span class=\"token punctuation\">,<\/span> providerName<span class=\"token punctuation\">,<\/span> lastChunkSummary<span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h3>\u8e29\u5751\u8bb0\u5f55<\/h3>\n<table>\n<tr>\u5751\u539f\u56e0\u89e3\u6cd5<\/tr>\n<tbody>\n<tr>\n<td>Anthropic message_delta \u4e0d\u542b input_tokens<\/td>\n<td>usage \u62a5\u544a\u4e0d\u5b8c\u6574<\/td>\n<td>UsageAwareTokenEstimator \u5408\u7406\u6027\u7a97\u53e3\u68c0\u6d4b<\/td>\n<\/tr>\n<tr>\n<td>429 \u8bef\u5224<\/td>\n<td>\u201cprocessed 429 items\u201d \u4e2d\u7684\u6570\u5b57<\/td>\n<td>\\\\b429\\\\b \u5168\u8bcd\u5339\u914d<\/td>\n<\/tr>\n<tr>\n<td>Spring AI TransientAiException \u4e0d\u542b 5xx<\/td>\n<td>\u67d0\u4e9b\u7248\u672c\u9057\u6f0f<\/td>\n<td>Layer 2 HTTP \u72b6\u6001\u7801\u68c0\u6d4b\u4f5c\u4e3a\u8865\u5145<\/td>\n<\/tr>\n<tr>\n<td>\u5f02\u5e38\u94fe\u5faa\u73af\u5f15\u7528<\/td>\n<td>e.cause \u5f62\u6210\u73af<\/td>\n<td>MAX_CAUSE_DEPTH &#061; 16<\/td>\n<\/tr>\n<tr>\n<td>\u7a7a chunk \u91cd\u7f6e\u8ba1\u65f6\u5668<\/td>\n<td>SSE keepalive \u88ab\u8bef\u8ba4\u4e3a LLM \u5728\u5de5\u4f5c<\/td>\n<td>\u53ea\u5728\u5b9e\u9645\u5185\u5bb9 chunk \u65f6\u91cd\u7f6e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u603b\u7ed3<\/h3>\n<table>\n<tr>\u7ef4\u5ea6\u7b80\u5355 try-catchEasyAI \u56db\u5c42\u5206\u7c7b<\/tr>\n<tbody>\n<tr>\n<td>\u9519\u8bef\u8bc6\u522b<\/td>\n<td>\u53ea\u770b message<\/td>\n<td>\u56db\u5c42\u7b56\u7565\u9010\u5c42\u68c0\u6d4b<\/td>\n<\/tr>\n<tr>\n<td>\u8de8 Provider<\/td>\n<td>\u6bcf\u4e2a Provider \u5355\u72ec\u5904\u7406<\/td>\n<td>\u7edf\u4e00\u5206\u7c7b\u63a5\u53e3<\/td>\n<\/tr>\n<tr>\n<td>\u4e0a\u4e0b\u6587\u6ea2\u51fa<\/td>\n<td>\u62a5\u9519\u7ec8\u6b62<\/td>\n<td>\u81ea\u52a8\u538b\u7f29 \u2192 \u91cd\u8bd5<\/td>\n<\/tr>\n<tr>\n<td>\u6d41\u505c\u6ede<\/td>\n<td>HTTP \u8d85\u65f6&#xff08;\u8fde\u63a5\u7ea7&#xff09;<\/td>\n<td>\u5e94\u7528\u5c42\u53cc\u8d85\u65f6\u68c0\u6d4b<\/td>\n<\/tr>\n<tr>\n<td>\u91cd\u8bd5\u7b56\u7565<\/td>\n<td>\u56fa\u5b9a\u95f4\u9694<\/td>\n<td>\u5206\u7c7b\u9a71\u52a8&#xff08;\u538b\u7f29\/\u9000\u907f\/\u7ec8\u6b62&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>EasyAI \u7684 LlmErrorClassifier \u7528 237 \u884c Kotlin \u4ee3\u7801\u5b9e\u73b0\u4e86\u5b8c\u6574\u7684\u9519\u8bef\u5206\u7c7b\u2014\u2014\u56db\u5c42\u68c0\u6d4b\u3001\u4e09\u79cd\u7c7b\u578b\u3001\u53cc\u6d41\u505c\u6ede\u68c0\u6d4b\u3001\u8de8 Provider \u517c\u5bb9\u3002<\/p>\n<p>\u6838\u5fc3\u601d\u60f3&#xff1a;\u597d\u7684\u9519\u8bef\u5904\u7406\u4e0d\u662f try-catch \u6253\u5370\u65e5\u5fd7&#xff0c;\u800c\u662f\u5206\u7c7b\u9a71\u52a8\u2014\u2014\u4e0d\u540c\u7c7b\u578b\u7684\u9519\u8bef\u6709\u4e0d\u540c\u7684\u81ea\u6108\u7b56\u7565\u3002<\/p>\n<hr \/>\n<p>\u4e0b\u4e00\u7bc7&#xff1a;\u8ba9 LLM \u7a33\u5b9a\u8f93\u51fa JSON&#xff0c;\u6211\u4eec\u8e29\u4e86\u56db\u9053\u574e<\/p>\n<p>Agent \u7684\u6700\u7ec8\u8f93\u51fa\u8981\u4ee5 JSON \u4ea4\u7ed9\u4e0b\u6e38\u7cfb\u7edf\u2014\u2014\u683c\u5f0f\u9519\u4e00\u4e2a\u5b57\u7b26\u5168\u94fe\u8def\u5c31\u65ad\u3002EasyAI \u7684\u65b9\u6848&#xff1a;\u5bbd\u5bb9\u63d0\u53d6 \u2192 Schema \u6821\u9a8c\u91cd\u8bd5 \u2192 \u539f\u751f\u7ed3\u6784\u5316\u8f93\u51fa \u2192 \u5927 JSON \u5206\u5757\u63d0\u4ea4&#xff0c;\u56db\u7ea7\u7eb5\u6df1\u9632\u5fa1\u3002<\/p>\n<hr \/>\n<p>\u5f00\u6e90\u5730\u5740&#xff1a;https:\/\/github.com\/haibingzhao\/easyai<\/p>\n<p>\u6b22\u8fce Star\u3001Issue \u548c PR\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR&#xff08;30 \u79d2\u901f\u89c8&#xff09;<br \/>\nAgent \u8c03\u7528 LLM API \u62a5\u9519\u4e86\u2014\u2014API Key \u8fc7\u671f&#xff1f;\u4e0a\u4e0b\u6587\u8d85\u957f&#xff1f;\u7f51\u7edc\u8d85\u65f6&#xff1f;\u9650\u6d41&#xff1f;\u4e0d\u540c Provider \u7684\u9519\u8bef\u683c\u5f0f\u5b8c\u5168\u4e0d\u540c\u56db\u5c42\u9519\u8bef\u5206\u7c7b&#xff1a;\u7ed3\u6784\u5316\u5f02\u5e38 \u2192 HTTP \u72b6\u6001\u7801 \u2192 Provider \u7279\u5b9a\u5f02\u5e38 \u2192 \u5173\u952e\u8bcd\u515c\u5e95\u4e09\u79cd\u9519\u8bef\u7c7b\u578b&#xff1a;Context Overflow&#xff08;\u538b\u7f29\u540e\u91cd\u8bd5&#xff09;\u3001Transient<\/p>\n","protected":false},"author":2,"featured_media":97463,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1693,50],"topic":[],"class_list":["post-97466","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-kotlin","tag-50"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LLM \u8c03\u7528\u7684\u56db\u5c42\u9519\u8bef\u5206\u7c7b\u4e0e\u6d41\u5f0f\u8d85\u65f6\u68c0\u6d4b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/97466.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LLM \u8c03\u7528\u7684\u56db\u5c42\u9519\u8bef\u5206\u7c7b\u4e0e\u6d41\u5f0f\u8d85\u65f6\u68c0\u6d4b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"TL;DR&#xff08;30 \u79d2\u901f\u89c8&#xff09; Agent \u8c03\u7528 LLM API \u62a5\u9519\u4e86\u2014\u2014API Key \u8fc7\u671f&#xff1f;\u4e0a\u4e0b\u6587\u8d85\u957f&#xff1f;\u7f51\u7edc\u8d85\u65f6&#xff1f;\u9650\u6d41&#xff1f;\u4e0d\u540c Provider \u7684\u9519\u8bef\u683c\u5f0f\u5b8c\u5168\u4e0d\u540c\u56db\u5c42\u9519\u8bef\u5206\u7c7b&#xff1a;\u7ed3\u6784\u5316\u5f02\u5e38 \u2192 HTTP \u72b6\u6001\u7801 \u2192 Provider \u7279\u5b9a\u5f02\u5e38 \u2192 \u5173\u952e\u8bcd\u515c\u5e95\u4e09\u79cd\u9519\u8bef\u7c7b\u578b&#xff1a;Context Overflow&#xff08;\u538b\u7f29\u540e\u91cd\u8bd5&#xff09;\u3001Transient\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/97466.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-29T07:25:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829072502-6a92894eb83d1.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97466.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/97466.html\",\"name\":\"LLM \u8c03\u7528\u7684\u56db\u5c42\u9519\u8bef\u5206\u7c7b\u4e0e\u6d41\u5f0f\u8d85\u65f6\u68c0\u6d4b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-29T07:25:06+00:00\",\"dateModified\":\"2026-08-29T07:25:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/97466.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/97466.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97466.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LLM \u8c03\u7528\u7684\u56db\u5c42\u9519\u8bef\u5206\u7c7b\u4e0e\u6d41\u5f0f\u8d85\u65f6\u68c0\u6d4b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LLM \u8c03\u7528\u7684\u56db\u5c42\u9519\u8bef\u5206\u7c7b\u4e0e\u6d41\u5f0f\u8d85\u65f6\u68c0\u6d4b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/97466.html","og_locale":"zh_CN","og_type":"article","og_title":"LLM \u8c03\u7528\u7684\u56db\u5c42\u9519\u8bef\u5206\u7c7b\u4e0e\u6d41\u5f0f\u8d85\u65f6\u68c0\u6d4b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"TL;DR&#xff08;30 \u79d2\u901f\u89c8&#xff09; Agent \u8c03\u7528 LLM API \u62a5\u9519\u4e86\u2014\u2014API Key \u8fc7\u671f&#xff1f;\u4e0a\u4e0b\u6587\u8d85\u957f&#xff1f;\u7f51\u7edc\u8d85\u65f6&#xff1f;\u9650\u6d41&#xff1f;\u4e0d\u540c Provider \u7684\u9519\u8bef\u683c\u5f0f\u5b8c\u5168\u4e0d\u540c\u56db\u5c42\u9519\u8bef\u5206\u7c7b&#xff1a;\u7ed3\u6784\u5316\u5f02\u5e38 \u2192 HTTP \u72b6\u6001\u7801 \u2192 Provider \u7279\u5b9a\u5f02\u5e38 \u2192 \u5173\u952e\u8bcd\u515c\u5e95\u4e09\u79cd\u9519\u8bef\u7c7b\u578b&#xff1a;Context Overflow&#xff08;\u538b\u7f29\u540e\u91cd\u8bd5&#xff09;\u3001Transient","og_url":"https:\/\/www.wsisp.com\/helps\/97466.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-29T07:25:06+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260829072502-6a92894eb83d1.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/97466.html","url":"https:\/\/www.wsisp.com\/helps\/97466.html","name":"LLM \u8c03\u7528\u7684\u56db\u5c42\u9519\u8bef\u5206\u7c7b\u4e0e\u6d41\u5f0f\u8d85\u65f6\u68c0\u6d4b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-29T07:25:06+00:00","dateModified":"2026-08-29T07:25:06+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/97466.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/97466.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/97466.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"LLM \u8c03\u7528\u7684\u56db\u5c42\u9519\u8bef\u5206\u7c7b\u4e0e\u6d41\u5f0f\u8d85\u65f6\u68c0\u6d4b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=97466"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97466\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/97463"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=97466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=97466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=97466"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=97466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}