PageSourceSearch

https://java2ai.com/assets/js/aeea83ee.2202c03c.js

js java2ai.com collected 2026-10-03 21:35:36 UTC 15,144 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkspring_ai_alibaba_website=self.webpackChunkspring_ai_alibaba_website||[]).push([[4914],{28453:(e,n,t)=>{t.d(n,{R:()=>s,x:()=>c});var r=t(96540);const i={},a=r.createContext(i);function s(e){const n=r.useContext(a);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function c(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:s(e.components),r.createElement(a.Provider,{value:n},e.children)}},67208:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>c,default:()=>x,frontMatter:()=>s,metadata:()=>r,toc:()=>o});const r=JSON.parse('{"id":"assistantagent/features/learning/quickstart","title":"\u5b66\u4e60\u6a21\u5757\uff08Learning\uff09","description":"1. \u6a21\u5757\u4ecb\u7ecd","source":"@site/agents-docs/assistantagent/features/learning/quickstart.md","sourceDirName":"assistantagent/features/learning","slug":"/assistantagent/features/learning/quickstart","permalink":"/agents/assistantagent/features/learning/quickstart","draft":false,"unlisted":false,"editUrl":"https://github.com/spring-ai-alibaba/website/tree/main/agents-docs/assistantagent/features/learning/quickstart.md","tags":[],"version":"current","lastUpdatedBy":"canfuu","lastUpdatedAt":1767918666000,"frontMatter":{},"sidebar":"agentsSidebar","previous":{"title":"\u9ad8\u7ea7\u7279\u6027","permalink":"/agents/assistantagent/features/experience/advanced"},"next":{"title":"\u9ad8\u7ea7\u7279\u6027","permalink":"/agents/assistantagent/features/learning/advanced"}}');var i=t(74848),a=t(28453);const s={},c="\u5b66\u4e60\u6a21\u5757\uff08Learning\uff09",l={},o=[{value:"1. \u6a21\u5757\u4ecb\u7ecd",id:"1-\u6a21\u5757\u4ecb\u7ecd",level:2},{value:"\u6838\u5fc3\u6982\u5ff5",id:"\u6838\u5fc3\u6982\u5ff5",level:3},{value:"\u5b66\u4e60\u89e6\u53d1\u65f6\u673a",id:"\u5b66\u4e60\u89e6\u53d1\u65f6\u673a",level:3},{value:"\u5de5\u4f5c\u6d41\u7a0b",id:"\u5de5\u4f5c\u6d41\u7a0b",level:3},{value:"2. \u5feb\u901f\u63a5\u5165\u65b9\u5f0f",id:"2-\u5feb\u901f\u63a5\u5165\u65b9\u5f0f",level:2},{value:"\u6b65\u9aa4 1\uff1a\u914d\u7f6e\u5b66\u4e60\u6a21\u5757",id:"\u6b65\u9aa4-1\u914d\u7f6e\u5b66\u4e60\u6a21\u5757",level:3},{value:"\u6b65\u9aa4 2\uff1a\u5b9e\u73b0\u81ea\u5b9a\u4e49 LearningExtractor",id:"\u6b65\u9aa4-2\u5b9e\u73b0\u81ea\u5b9a\u4e49-learningextractor",level:3},{value:"\u6b65\u9aa4 3\uff1a\u5b9e\u73b0 LearningRepository\uff08\u53ef\u9009\uff09",id:"\u6b65\u9aa4-3\u5b9e\u73b0-learningrepository\u53ef\u9009",level:3},{value:"3. \u5b66\u4e60\u4e0a\u4e0b\u6587",id:"3-\u5b66\u4e60\u4e0a\u4e0b\u6587",level:2}];function d(e){const n={code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",hr:"hr",p:"p",pre:"pre",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,a.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.header,{children:(0,i.jsx)(n.h1,{id:"\u5b66\u4e60\u6a21\u5757learning",children:"\u5b66\u4e60\u6a21\u5757\uff08Learning\uff09"})}),"\n",(0,i.jsx)(n.h2,{id:"1-\u6a21\u5757\u4ecb\u7ecd",children:"1. \u6a21\u5757\u4ecb\u7ecd"}),"\n",(0,i.jsx)(n.p,{children:"\u5b66\u4e60\u6a21\u5757\u662f Assistant Agent \u7684\u81ea\u52a8\u7ecf\u9a8c\u63d0\u53d6\u673a\u5236\uff0c\u4ece Agent \u6267\u884c\u8fc7\u7a0b\u4e2d\u81ea\u52a8\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u6a21\u5f0f\u548c\u7ecf\u9a8c\uff0c\u5b58\u50a8\u5230\u7ecf\u9a8c\u5e93\u4f9b\u540e\u7eed\u590d\u7528\u3002"}),"\n",(0,i.jsx)(n.h3,{id:"\u6838\u5fc3\u6982\u5ff5",children:"\u6838\u5fc3\u6982\u5ff5"}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"\u6982\u5ff5"}),(0,i.jsx)(n.th,{children:"\u8bf4\u660e"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"LearningExtractor"})}),(0,i.jsx)(n.td,{children:"\u5b66\u4e60\u63d0\u53d6\u5668\uff0c\u4ece\u4e0a\u4e0b\u6587\u4e2d\u63d0\u53d6\u5b66\u4e60\u8bb0\u5f55"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"LearningRepository"})}),(0,i.jsx)(n.td,{children:"\u5b66\u4e60\u4ed3\u5e93\uff0c\u8d1f\u8d23\u5b66\u4e60\u8bb0\u5f55\u7684\u6301\u4e45\u5316\u5b58\u50a8"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"LearningStrategy"})}),(0,i.jsx)(n.td,{children:"\u5b66\u4e60\u7b56\u7565\uff0c\u534f\u8c03\u63d0\u53d6\u5668\u548c\u4ed3\u5e93"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"LearningExecutor"})}),(0,i.jsx)(n.td,{children:"\u5b66\u4e60\u6267\u884c\u5668\uff0c\u6267\u884c\u5b66\u4e60\u6d41\u7a0b"})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"LearningContext"})}),(0,i.jsx)(n.td,{children:"\u5b66\u4e60\u4e0a\u4e0b\u6587\uff0c\u5305\u542b Agent \u6267\u884c\u4fe1\u606f"})]})]})]}),"\n",(0,i.jsx)(n.h3,{id:"\u5b66\u4e60\u89e6\u53d1\u65f6\u673a",children:"\u5b66\u4e60\u89e6\u53d1\u65f6\u673a"}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"\u65f6\u673a"}),(0,i.jsx)(n.th,{children:"\u8bf4\u660e"}),(0,i.jsx)(n.th,{children:"\u914d\u7f6e\u9879"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:"Agent \u6267\u884c\u54
10e"}),(0,i.jsx)(n.td,{children:"\u5b8c\u6574\u4f1a\u8bdd\u7ed3\u675f\u540e\u63d0\u53d6\u7ecf\u9a8c"}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"online.after-agent.enabled"})})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:"\u6a21\u578b\u8c03\u7528\u540e"}),(0,i.jsx)(n.td,{children:"\u6bcf\u6b21 LLM \u8c03\u7528\u540e\u63d0\u53d6\u6a21\u5f0f"}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"online.after-model.enabled"})})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:"\u5de5\u5177\u6267\u884c\u540e"}),(0,i.jsx)(n.td,{children:"\u5de5\u5177\u8c03\u7528\u5b8c\u6210\u540e\u63d0\u53d6\u8bb0\u5f55"}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"online.tool-interceptor.enabled"})})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:"\u79bb\u7ebf\u6279\u91cf"}),(0,i.jsx)(n.td,{children:"\u5b9a\u65f6\u4efb\u52a1\u6279\u91cf\u5904\u7406\u5386\u53f2\u6570\u636e"}),(0,i.jsx)(n.td,{children:(0,i.jsx)(n.code,{children:"offline.enabled"})})]})]})]}),"\n",(0,i.jsx)(n.h3,{id:"\u5de5\u4f5c\u6d41\u7a0b",children:"\u5de5\u4f5c\u6d41\u7a0b"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{children:"Agent \u6267\u884c\u5b8c\u6210\n        \u2502\n        \u25bc\n\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\u2510\n\u2502         LearningContext                  \u2502\n\u2502   \u6536\u96c6\uff1a\u8f93\u5165\u3001\u8f93\u51fa\u3001\u4ee3\u7801\u3001\u5de5\u5177\u8c03\u7528\u7b49        \u2502\n\u2514\u2500\u2500\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\u2500\u2500\u2500\u2500\u2500\u2518\n                 \u25bc\n\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\u2510\n\u2502         LearningExtractor               \u2502\n\u2502   \u5224\u65ad shouldLearn() \u2192 extract()        \u2502\n\u2514\u2500\u2500\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\u2500\u2500\u2500\u2500\u2500\u2518\n                 \u25bc\n\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\u2510\n\u2502         LearningRepository              \u2502\n\u2502   \u4fdd\u5b58\u5b66\u4e60\u8bb0\u5f55\u5230\u5b58\u50a8                      \u2502\n\u2514\u2500\u2500\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\u2500\u2500\u2500\u2500\u2500\u2518\n                 \u25bc\n         \u7ecf\u9a8c\u5e93\u66f4\u65b0\u5b8c\u6210\n"})}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"2-\u5feb\u901f\u63a5\u5165\u65b9\u5f0f",children:"2. \u5feb\u901f\u63a5\u5165\u65b9\u5f0f"}),"\n",(0,i.jsx)(n.h3,{id:"\u6b65\u9aa4-1\u914d\u7f6e\u5b66\u4e60\u6a21\u5757",children:"\u6b65\u9aa4 1\uff1a\u914d\u7f6e\u5b66\u4e60\u6a21\u5757"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-yaml",children:"# application.yml\nspring:\n  ai:\n    alibaba:\n      codeact:\n        extension:\n          learning:\n            enabled: true\n            online:\n              enabled: true\n              after-agent:\n                enabled: true\n                learning-types:\n                  - experience    # \u63d0\u53d6\u7ecf\u9a8c\n            async:\n              enabled: true\n              core-pool-size: 2\n              max-pool-size: 4\n"})}),"\n",(0,i.jsx)(n.h3,{id:"\u6b65\u9aa4-2\u5b9e\u73b0\u81ea\u5b9a\u4e49-learningextractor",children:"\u6b65\u9aa4 2\uff1a\u5b9e\u73b0\u81ea\u5b9a\u4e49 LearningExtractor"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-java",children:'import 
1com.alibaba.assistant.agent.extension.learning.spi.LearningExtractor;\nimport com.alibaba.assistant.agent.extension.learning.model.LearningContext;\nimport com.alibaba.assistant.agent.extension.experience.model.Experience;\nimport com.alibaba.assistant.agent.extension.experience.model.ExperienceType;\nimport org.springframework.stereotype.Component;\nimport java.util.List;\nimport java.util.ArrayList;\n\n@Component\npublic class CodePatternExtractor implements LearningExtractor<Experience> {\n\n    @Override\n    public boolean shouldLearn(LearningContext context) {\n        // \u5224\u65ad\u662f\u5426\u9700\u8981\u5b66\u4e60\n        // \u901a\u8fc7 customData \u5224\u65ad\u6267\u884c\u662f\u5426\u6210\u529f\n        Object isSuccess = context.getCustomData().get("success");\n        return Boolean.TRUE.equals(isSuccess) && \n               !context.getToolCallRecords().isEmpty();\n    }\n\n    @Override\n    public List<Experience> extract(LearningContext context) {\n        List<Experience> experiences = new ArrayList<>();\n        \n        // \u4ece\u6267\u884c\u4e0a\u4e0b\u6587\u4e2d\u63d0\u53d6\u7ecf\u9a8c\n        // \u901a\u8fc7 customData \u83b7\u53d6\u7528\u6237\u8f93\u5165\u548c\u751f\u6210\u7684\u4ee3\u7801\n        String userInput = (String) context.getCustomData().get("userInput");\n        String generatedCode = (String) context.getCustomData().get("generatedCode");\n        String output = (String) context.getCustomData().get("output");\n        \n        // \u521b\u5efa\u4ee3\u7801\u7ecf\u9a8c\n        Experience exp = new Experience();\n        exp.setType(ExperienceType.CODE);\n        exp.setTitle("\u4ee3\u7801\u6a21\u5f0f: " + summarize(userInput));\n        exp.setContent(String.format("""\n            ## \u7528\u6237\u9700\u6c42\n            %s\n            \n            ## \u89e3\u51b3\u65b9\u6848\n            ```python\n            %s\n            ```\n            \n            ## \u6267\u884c\u7ed3\u679c\n            %s\n            """, userInput, generatedCode, output));\n        \n        experiences.add(exp);\n        return experiences;\n    }\n\n    @Override\n    public String getSupportedLearningType() {\n        return "experience";\n    }\n\n    @Override\n    public Class<Experience> getRecordType() {\n        return Experience.class;\n    }\n    \n    private String summarize(String input) {\n        if (input == null) return "";\n        return input.length() > 50 ? input.substring(0, 50) + "..." : input;\n    }\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"\u6b65\u9aa4-3\u5b9e\u73b0-learningrepository\u53ef\u9009",children:"\u6b65\u9aa4 3\uff1a\u5b9e\u73b0 LearningRepository\uff08\u53ef\u9009\uff09"}),"\n",(0,i.jsx)(n.p,{children:"\u4f7f\u7528\u9ed8\u8ba4\u7684\u5185\u5b58/Store \u5b9e\u73b0\uff0c\u6216\u81ea\u5b9a\u4e49\uff1a"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-java",children:"import com.alibaba.assistant.agent.extension.learning.spi.LearningRepository;\nimport com.alibaba.assistant.agent.extension.learning.model.LearningSearchRequest;\nimport com.alibaba.assistant.agent.extension.experience.model.Experience;\nimport org.springframework.stereotype.Component;\nimport java.util.List;\n\n@Component\npublic class DatabaseLearningRepository implements LearningRepository<Experience> {\n\n    private final ExperienceDao experienceDao;\n\n    @Override\n    public void save(String namespace, String key, Experience record) {\n        record.setId(key);\n        experienceDao.insert(record);\n    }\n\n    @Override\n    public void saveBatch(String namespace, List<Experience> records) {\n        experienceDao.batchInsert(records);\n    }\n\n    @Override\n    public Experience get(String namespace, String key) {\n        return experienceDao.findById(key);\n    }\n\n    @Override\n    public List<Experience> search(LearningSearchRequest request) {\n        return experienceDao.search(request.getQuery(), request.getLimit());\n    }\n\n    @Override\n    public void delete(String namespace, String key) {\n        experienceDao.deleteById(key);\n    }\n\n    @Override\n    public Class<Experience>
1 getSupportedRecordType() {\n        return Experience.class;\n    }\n}\n"})}),"\n",(0,i.jsx)(n.hr,{}),"\n",(0,i.jsx)(n.h2,{id:"3-\u5b66\u4e60\u4e0a\u4e0b\u6587",children:"3. \u5b66\u4e60\u4e0a\u4e0b\u6587"}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.code,{children:"LearningContext"})," \u5305\u542b Agent \u6267\u884c\u7684\u5b8c\u6574\u4fe1\u606f\uff1a"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-java",children:"// \u83b7\u53d6\u5b66\u4e60\u4e0a\u4e0b\u6587\u4e2d\u7684\u4fe1\u606f\nObject overAllState = context.getOverAllState();                      // Agent \u6267\u884c\u72b6\u6001\nList<Object> conversationHistory = context.getConversationHistory();  // \u5bf9\u8bdd\u5386\u53f2\nList<ToolCallRecord> toolCalls = context.getToolCallRecords();        // \u5de5\u5177\u8c03\u7528\u8bb0\u5f55\nList<ModelCallRecord> modelCalls = context.getModelCallRecords();     // \u6a21\u578b\u8c03\u7528\u8bb0\u5f55\nMap<String, Object> customData = context.getCustomData();             // \u81ea\u5b9a\u4e49\u6570\u636e\nLearningTriggerSource triggerSource = context.getTriggerSource();     // \u89e6\u53d1\u6765\u6e90\n"})})]})}function x(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.