import{s as nt,n as at,o as Jt}from"../chunks/scheduler.505acc25.js";import{S as Mt,i as it,e as J,s as n,c as U,h as Ut,a as M,d as e,b as a,f as st,g as o,j as i,k as O,l as ot,m as s,n as p,t as T,o as y,p as m}from"../chunks/index.b1175496.js";import{C as pt,H as Ql}from"../chunks/Heading.eda51538.js";import{C as Zl}from"../chunks/CodeBlock.9d480d26.js";import{E as Tt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.ea377ea6.js";function yt(Nl){let u,P,L,D,j,K,b,ll,d,Gl=`还记得我们之前那位得力的管家智能体 Alfred 吗？现在他要迎来重大升级了！
在了解了 LlamaIndex 中的工具后，我们可以赋予 Alfred 新的能力来更好地服务我们。`,tl,I,Al=`不过在继续之前，让我们先回顾一下智能体（如 Alfred）的核心机制。
在第一单元中我们学习到：`,el,C,kl="<p>智能体是一个利用 AI 模型与环境交互以实现用户定义目标的系统。它通过结合推理、规划和动作执行（通常通过外部工具）来完成各种任务。</p>",sl,g,Sl="LlamaIndex 支持<strong>三种主要类型的推理智能体</strong>：",nl,h,Fl='<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/llama-index/agents.png" alt="智能体类型"/>',al,f,_l="<li><code>函数调用智能体</code> - 适用于支持调用特定函数的 AI 模型</li> <li><code>ReAct 智能体</code> - 适用于具有聊天或文本完成能力的 AI 模型，擅长处理复杂推理任务</li> <li><code>高级自定义智能体</code> - 使用更复杂的方法处理高阶任务和工作流</li>",Jl,c,vl='<p>有关高级智能体的更多信息，请访问 <a href="https://github.com/run-llama/llama_index/blob/main/llama-index-core/llama_index/core/agent/workflow/base_agent.py">BaseWorkflowAgent</a></p>',Ml,V,il,r,Rl='<p>您可以通过 <a href="https://huggingface.co/agents-course/notebooks/blob/main/unit2/llama-index/agents.ipynb" target="_blank">这个 Notebook</a> 跟随代码实践（使用 Google Colab 运行）。</p>',Ul,B,$l=`创建智能体时，我们首先需要为其提供<strong>定义其能力的功能/工具集合</strong>。
让我们看看如何使用基础工具创建智能体。当前实现中，智能体会自动使用函数调用 API（如果可用），或标准的 ReAct 智能体循环。`,ol,x,Xl="支持工具/函数 API 的 LLM 是相对较新的技术，它们通过避免特定提示工程、允许 LLM 根据提供的模式创建工具调用，提供了强大的工具调用能力。",pl,E,ql="ReAct 智能体同样擅长复杂推理任务，可与任何具备聊天或文本完成能力的 LLM 配合使用。这类智能体的响应更详细，会展示其决策背后的推理过程。",Tl,W,yl,Q,Yl=`<strong>智能体默认是无状态的</strong>，如需记忆过往交互，需显式使用 <code>Context</code> 对象。
这在需要记忆历史交互的场景中非常有用，例如：需要跨消息保持上下文的聊天机器人，或需要追踪长期任务进度的任务管理器。`,ml,Z,ul,N,Hl='您会注意到 <code>LlamaIndex</code> 中的智能体采用异步模式（使用 Python 的 <code>await</code> 操作符）。如果您是 Python 异步编程的新手，或需要复习相关知识，请参考 <a href="https://docs.llamaindex.ai/en/stable/getting_started/async_python/" rel="nofollow">官方异步编程指南</a>。',cl,G,Ll="现在我们已经掌握基础知识，接下来让我们探索如何为智能体赋予更复杂的工具能力。",rl,A,wl,k,zl=`<strong>智能体增强检索（Agentic RAG）</strong> 是通过智能体实现数据问答的强大范式。我们可以为 Alfred 配备多种工具来辅助问题解答。
但不同于传统 RAG 直接基于文档回答问题，Alfred 能够自主决定是否使用其他工具或流程来响应查询。`,jl,S,Ol='<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit2/llama-index/agentic-rag.png" alt="智能体增强 RAG"/>',bl,F,Pl=`将 <code>QueryEngine</code> 封装为智能体工具非常简单。
在此过程中，我们需要<strong>定义工具名称和描述</strong>，这些元数据将帮助 LLM 正确选择和使用工具。
以下示例演示如何基于<a href="02_components">组件章节</a>创建的 <code>QueryEngine</code> 加载 <code>QueryEngineTool</code>：`,dl,_,Il,v,Cl,R,Dl="<code>AgentWorkflow</code> 类原生支持多智能体系统。通过为每个智能体分配名称和描述，系统可维护单一活跃会话主体，同时允许智能体之间进行任务交接。",gl,$,Kl="通过精准定义每个智能体的职责边界，我们能够有效提升系统响应消息时的整体准确性。",hl,X,lt="<strong>LlamaIndex 中的智能体也可直接作为其他智能体的工具</strong>，这种设计支持构建复杂的定制化场景：",fl,q,Vl,w,tt='<p>还没学够吗？在<a href="https://docs.llamaindex.ai/en/stable/examples/agent/agent_workflow_basic/">《AgentWorkflow 基本介绍》</a>或<a href="https://docs.llamaindex.ai/en/stable/understanding/agent/">《Agent 学习指南》</a>中，您可以了解到更多关于流媒体、上下文序列化和人在环路中的信息！</p>',Bl,Y,et="现在我们已经掌握了 LlamaIndex 中智能体和工具的基础知识，接下来让我们探索如何利用 LlamaIndex 来<strong>创建可配置、易管理的工作流</strong>！",xl,H,El,z,Wl;return j=new pt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),b=new Ql({props:{title:"在 LlamaIndex 中使用智能体",local:"在-llamaindex-中使用智能体",headingTag:"h1"}}),V=new Ql({props:{title:"初始化智能体",local:"初始化智能体",headingTag:"h2"}}),W=new Zl({props:{code:"ZnJvbSUyMGxsYW1hX2luZGV4LmxsbXMuaHVnZ2luZ2ZhY2VfYXBpJTIwaW1wb3J0JTIwSHVnZ2luZ0ZhY2VJbmZlcmVuY2VBUEklMEFmcm9tJTIwbGxhbWFfaW5kZXguY29yZS5hZ2VudC53b3JrZmxvdyUyMGltcG9ydCUyMEFnZW50V29ya2Zsb3clMEFmcm9tJTIwbGxhbWFfaW5kZXguY29yZS50b29scyUyMGltcG9ydCUyMEZ1bmN0aW9uVG9vbCUwQSUwQSUyMyUyMCVFNSVBRSU5QSVFNCVCOSU4OSVFNyVBNCVCQSVFNCVCRSU4QiVFNSVCNyVBNSVFNSU4NSVCNy0tJUU3JUIxJUJCJUU1JTlFJThCJUU2JUIzJUE4JUU5JTg3JThBJUUzJTgwJTgxJUU1JTg3JUJEJUU2JTk1JUIwJUU1JTkwJThEJUU1JTkyJThDJTIwZG9jc3RyaW5ncyUyMCVFOSU4MyVCRCVFNSU4QyU4NSVFNSU5MCVBQiVFNSU5QyVBOCVFOCVBNyVBMyVFNiU5RSU5MCVFNyU5QSU4NCVFNiVBOCVBMSVFNSVCQyU4RiVFNCVCOCVBRCVFRiVCQyU4MSUwQWRlZiUyMG11bHRpcGx5KGElM0ElMjBpbnQlMkMlMjBiJTNBJTIwaW50KSUyMC0lM0UlMjBpbnQlM0ElMEElMjAlMjAlMjAlMjAlMjIlMjIlMjJNdWx0aXBsaWVzJTIwdHdvJTIwaW50ZWdlcnMlMjBhbmQlMjByZXR1cm5zJTIwdGhlJTIwcmVzdWx0aW5nJTIwaW50ZWdlciUyMiUyMiUyMiUwQSUyMCUyMCUyMCUyMHJldHVybiUyMGElMjAqJTIwYiUwQSUwQSUyMyUyMCVFNSU4OCU5RCVFNSVBNyU4QiVFNSU4QyU5NiUyMGxsbSUwQWxsbSUyMCUzRCUyMEh1Z2dpbmdGYWNlSW5mZXJlbmNlQVBJKG1vZGVsX25hbWUlM0QlMjJRd2VuJTJGUXdlbjIuNS1Db2Rlci0zMkItSW5zdHJ1Y3QlMjIpJTBBJTBBJTIzJTIwJUU1JTg4JTlEJUU1JUE3JThCJUU1JThDJTk2JTIwYWdlbnQlMEFhZ2VudCUyMCUzRCUyMEFnZW50V29ya2Zsb3cuZnJvbV90b29sc19vcl9mdW5jdGlvbnMoJTBBJTIwJTIwJTIwJTIwJTVCRnVuY3Rpb25Ub29sLmZyb21fZGVmYXVsdHMobXVsdGlwbHkpJTVEJTJDJTBBJTIwJTIwJTIwJTIwbGxtJTNEbGxtJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> llama_index.llms.huggingface_api <span class="hljs-keyword">import</span> HuggingFaceInferenceAPI
<span class="hljs-keyword">from</span> llama_index.core.agent.workflow <span class="hljs-keyword">import</span> AgentWorkflow
<span class="hljs-keyword">from</span> llama_index.core.tools <span class="hljs-keyword">import</span> FunctionTool

<span class="hljs-comment"># 定义示例工具--类型注释、函数名和 docstrings 都包含在解析的模式中！</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">multiply</span>(<span class="hljs-params">a: <span class="hljs-built_in">int</span>, b: <span class="hljs-built_in">int</span></span>) -&gt; <span class="hljs-built_in">int</span>:
    <span class="hljs-string">&quot;&quot;&quot;Multiplies two integers and returns the resulting integer&quot;&quot;&quot;</span>
    <span class="hljs-keyword">return</span> a * b

<span class="hljs-comment"># 初始化 llm</span>
llm = HuggingFaceInferenceAPI(model_name=<span class="hljs-string">&quot;Qwen/Qwen2.5-Coder-32B-Instruct&quot;</span>)

<span class="hljs-comment"># 初始化 agent</span>
agent = AgentWorkflow.from_tools_or_functions(
    [FunctionTool.from_defaults(multiply)],
    llm=llm
)`,wrap:!1}}),Z=new Zl({props:{code:"JTIzJTIwc3RhdGVsZXNzJTBBcmVzcG9uc2UlMjAlM0QlMjBhd2FpdCUyMGFnZW50LnJ1biglMjJXaGF0JTIwaXMlMjAyJTIwdGltZXMlMjAyJTNGJTIyKSUwQSUwQSUyMyUyMHJlbWVtYmVyaW5nJTIwc3RhdGUlMEFmcm9tJTIwbGxhbWFfaW5kZXguY29yZS53b3JrZmxvdyUyMGltcG9ydCUyMENvbnRleHQlMEElMEFjdHglMjAlM0QlMjBDb250ZXh0KGFnZW50KSUwQSUwQXJlc3BvbnNlJTIwJTNEJTIwYXdhaXQlMjBhZ2VudC5ydW4oJTIyTXklMjBuYW1lJTIwaXMlMjBCb2IuJTIyJTJDJTIwY3R4JTNEY3R4KSUwQXJlc3BvbnNlJTIwJTNEJTIwYXdhaXQlMjBhZ2VudC5ydW4oJTIyV2hhdCUyMHdhcyUyMG15JTIwbmFtZSUyMGFnYWluJTNGJTIyJTJDJTIwY3R4JTNEY3R4KQ==",highlighted:`<span class="hljs-comment"># stateless</span>
response = <span class="hljs-keyword">await</span> agent.run(<span class="hljs-string">&quot;What is 2 times 2?&quot;</span>)

<span class="hljs-comment"># remembering state</span>
<span class="hljs-keyword">from</span> llama_index.core.workflow <span class="hljs-keyword">import</span> Context

ctx = Context(agent)

response = <span class="hljs-keyword">await</span> agent.run(<span class="hljs-string">&quot;My name is Bob.&quot;</span>, ctx=ctx)
response = <span class="hljs-keyword">await</span> agent.run(<span class="hljs-string">&quot;What was my name again?&quot;</span>, ctx=ctx)`,wrap:!1}}),A=new Ql({props:{title:"使用 QueryEngineTools 创建 RAG 智能体",local:"使用-queryenginetools-创建-rag-智能体",headingTag:"h2"}}),_=new Zl({props:{code:"ZnJvbSUyMGxsYW1hX2luZGV4LmNvcmUudG9vbHMlMjBpbXBvcnQlMjBRdWVyeUVuZ2luZVRvb2wlMEElMEFxdWVyeV9lbmdpbmUlMjAlM0QlMjBpbmRleC5hc19xdWVyeV9lbmdpbmUobGxtJTNEbGxtJTJDJTIwc2ltaWxhcml0eV90b3BfayUzRDMpJTIwJTIzJTIwYXMlMjBzaG93biUyMGluJTIwdGhlJTIwcHJldmlvdXMlMjBzZWN0aW9uJTBBJTBBcXVlcnlfZW5naW5lX3Rvb2wlMjAlM0QlMjBRdWVyeUVuZ2luZVRvb2wuZnJvbV9kZWZhdWx0cyglMEElMjAlMjAlMjAlMjBxdWVyeV9lbmdpbmUlM0RxdWVyeV9lbmdpbmUlMkMlMEElMjAlMjAlMjAlMjBuYW1lJTNEJTIybmFtZSUyMiUyQyUwQSUyMCUyMCUyMCUyMGRlc2NyaXB0aW9uJTNEJTIyYSUyMHNwZWNpZmljJTIwZGVzY3JpcHRpb24lMjIlMkMlMEElMjAlMjAlMjAlMjByZXR1cm5fZGlyZWN0JTNERmFsc2UlMkMlMEEpJTBBcXVlcnlfZW5naW5lX2FnZW50JTIwJTNEJTIwQWdlbnRXb3JrZmxvdy5mcm9tX3Rvb2xzX29yX2Z1bmN0aW9ucyglMEElMjAlMjAlMjAlMjAlNUJxdWVyeV9lbmdpbmVfdG9vbCU1RCUyQyUwQSUyMCUyMCUyMCUyMGxsbSUzRGxsbSUyQyUwQSUyMCUyMCUyMCUyMHN5c3RlbV9wcm9tcHQlM0QlMjJZb3UlMjBhcmUlMjBhJTIwaGVscGZ1bCUyMGFzc2lzdGFudCUyMHRoYXQlMjBoYXMlMjBhY2Nlc3MlMjB0byUyMGElMjBkYXRhYmFzZSUyMGNvbnRhaW5pbmclMjBwZXJzb25hJTIwZGVzY3JpcHRpb25zLiUyMCUyMiUwQSk=",highlighted:`<span class="hljs-keyword">from</span> llama_index.core.tools <span class="hljs-keyword">import</span> QueryEngineTool

query_engine = index.as_query_engine(llm=llm, similarity_top_k=<span class="hljs-number">3</span>) <span class="hljs-comment"># as shown in the previous section</span>

query_engine_tool = QueryEngineTool.from_defaults(
    query_engine=query_engine,
    name=<span class="hljs-string">&quot;name&quot;</span>,
    description=<span class="hljs-string">&quot;a specific description&quot;</span>,
    return_direct=<span class="hljs-literal">False</span>,
)
query_engine_agent = AgentWorkflow.from_tools_or_functions(
    [query_engine_tool],
    llm=llm,
    system_prompt=<span class="hljs-string">&quot;You are a helpful assistant that has access to a database containing persona descriptions. &quot;</span>
)`,wrap:!1}}),v=new Ql({props:{title:"创建多智能体系统",local:"创建多智能体系统",headingTag:"h2"}}),q=new Zl({props:{code:"ZnJvbSUyMGxsYW1hX2luZGV4LmNvcmUuYWdlbnQud29ya2Zsb3clMjBpbXBvcnQlMjAoJTBBJTIwJTIwJTIwJTIwQWdlbnRXb3JrZmxvdyUyQyUwQSUyMCUyMCUyMCUyMEZ1bmN0aW9uQWdlbnQlMkMlMEElMjAlMjAlMjAlMjBSZUFjdEFnZW50JTJDJTBBKSUwQSUwQSUyMyUyMERlZmluZSUyMHNvbWUlMjB0b29scyUwQWRlZiUyMGFkZChhJTNBJTIwaW50JTJDJTIwYiUzQSUyMGludCklMjAtJTNFJTIwaW50JTNBJTBBJTIwJTIwJTIwJTIwJTIyJTIyJTIyQWRkJTIwdHdvJTIwbnVtYmVycy4lMjIlMjIlMjIlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBhJTIwJTJCJTIwYiUwQSUwQSUwQWRlZiUyMHN1YnRyYWN0KGElM0ElMjBpbnQlMkMlMjBiJT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QkIlOUYlMEFyZXNwb25zZSUyMCUzRCUyMGF3YWl0JTIwYWdlbnQucnVuKHVzZXJfbXNnJTNEJTIyQ2FuJTIweW91JTIwYWRkJTIwNSUyMGFuZCUyMDMlM0YlMjIp",highlighted:`<span class="hljs-keyword">from</span> llama_index.core.agent.workflow <span class="hljs-keyword">import</span> (
    AgentWorkflow,
    FunctionAgent,
    ReActAgent,
)

<span class="hljs-comment"># Define some tools</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">add</span>(<span class="hljs-params">a: <span class="hljs-built_in">int</span>, b: <span class="hljs-built_in">int</span></span>) -&gt; <span class="hljs-built_in">int</span>:
    <span class="hljs-string">&quot;&quot;&quot;Add two numbers.&quot;&quot;&quot;</span>
    <span class="hljs-keyword">return</span> a + b


<span class="hljs-keyword">def</span> <span class="hljs-title function_">subtract</span>(<span class="hljs-params">a: <span class="hljs-built_in">int</span>, b: <span class="hljs-built_in">int</span></span>) -&gt; <span class="hljs-built_in">int</span>:
    <span class="hljs-string">&quot;&quot;&quot;Subtract two numbers.&quot;&quot;&quot;</span>
    <span class="hljs-keyword">return</span> a - b


<span class="hljs-comment"># 创建智能体配置</span>
<span class="hljs-comment"># 注意：我们可以在此使用 FunctionAgent 或 ReActAgent。</span>
<span class="hljs-comment"># FunctionAgent 适用于具有函数调用 API 的 LLM。</span>
<span class="hljs-comment"># ReActAgent 适用于任何 LLM。</span>
calculator_agent = ReActAgent(
    name=<span class="hljs-string">&quot;calculator&quot;</span>,
    description=<span class="hljs-string">&quot;Performs basic arithmetic operations&quot;</span>,
    system_prompt=<span class="hljs-string">&quot;You are a calculator assistant. Use your tools for any math operation.&quot;</span>,
    tools=[add, subtract],
    llm=llm,
)

query_agent = ReActAgent(
    name=<span class="hljs-string">&quot;info_lookup&quot;</span>,
    description=<span class="hljs-string">&quot;Looks up information about XYZ&quot;</span>,
    system_prompt=<span class="hljs-string">&quot;Use your tool to query a RAG system to answer information about XYZ&quot;</span>,
    tools=[query_engine_tool],
    llm=llm
)

<span class="hljs-comment"># 创建并运行工作流程</span>
agent = AgentWorkflow(
    agents=[calculator_agent, query_agent], root_agent=<span class="hljs-string">&quot;calculator&quot;</span>
)

<span class="hljs-comment"># 运行系统</span>
response = <span class="hljs-keyword">await</span> agent.run(user_msg=<span class="hljs-string">&quot;Can you add 5 and 3?&quot;</span>)`,wrap:!1}}),H=new Tt({props:{source:"https://github.com/huggingface/agents-course/blob/main/units/zh-CN/unit2/llama-index/agents.mdx"}}),{c(){u=J("meta"),P=n(),L=J("p"),D=n(),U(j.$$.fragment),K=n(),U(b.$$.fragment),ll=n(),d=J("p"),d.textContent=Gl,tl=n(),I=J("p"),I.textContent=Al,el=n(),C=J("blockquote"),C.innerHTML=kl,sl=n(),g=J("p"),g.innerHTML=Sl,nl=n(),h=J("p"),h.innerHTML=Fl,al=n(),f=J("ol"),f.innerHTML=_l,Jl=n(),c=J("blockquote"),c.innerHTML=vl,Ml=n(),U(V.$$.fragment),il=n(),r=J("blockquote"),r.innerHTML=Rl,Ul=n(),B=J("p"),B.innerHTML=$l,ol=n(),x=J("p"),x.textContent=Xl,pl=n(),E=J("p"),E.textContent=ql,Tl=n(),U(W.$$.fragment),yl=n(),Q=J("p"),Q.innerHTML=Yl,ml=n(),U(Z.$$.fragment),ul=n(),N=J("p"),N.innerHTML=Hl,cl=n(),G=J("p"),G.textContent=Ll,rl=n(),U(A.$$.fragment),wl=n(),k=J("p"),k.innerHTML=zl,jl=n(),S=J("p"),S.innerHTML=Ol,bl=n(),F=J("p"),F.innerHTML=Pl,dl=n(),U(_.$$.fragment),Il=n(),U(v.$$.fragment),Cl=n(),R=J("p"),R.innerHTML=Dl,gl=n(),$=J("p"),$.textContent=Kl,hl=n(),X=J("p"),X.innerHTML=lt,fl=n(),U(q.$$.fragment),Vl=n(),w=J("blockquote"),w.innerHTML=tt,Bl=n(),Y=J("p"),Y.innerHTML=et,xl=n(),U(H.$$.fragment),El=n(),z=J("p"),this.h()},l(l){const t=Ut("svelte-u9bgzb",document.head);u=M(t,"META",{name:!0,content:!0}),t.forEach(e),P=a(l),L=M(l,"P",{}),st(L).forEach(e),D=a(l),o(j.$$.fragment,l),K=a(l),o(b.$$.fragment,l),ll=a(l),d=M(l,"P",{"data-svelte-h":!0}),i(d)!=="svelte-10d7e98"&&(d.textContent=Gl),tl=a(l),I=M(l,"P",{"data-svelte-h":!0}),i(I)!=="svelte-hkw26n"&&(I.textContent=Al),el=a(l),C=M(l,"BLOCKQUOTE",{"data-svelte-h":!0}),i(C)!=="svelte-1ksbkzo"&&(C.innerHTML=kl),sl=a(l),g=M(l,"P",{"data-svelte-h":!0}),i(g)!=="svelte-17xgwds"&&(g.innerHTML=Sl),nl=a(l),h=M(l,"P",{"data-svelte-h":!0}),i(h)!=="svelte-3nptas"&&(h.innerHTML=Fl),al=a(l),f=M(l,"OL",{"data-svelte-h":!0}),i(f)!=="svelte-fuuhge"&&(f.innerHTML=_l),Jl=a(l),c=M(l,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),i(c)!=="svelte-ilkz"&&(c.innerHTML=vl),Ml=a(l),o(V.$$.fragment,l),il=a(l),r=M(l,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),i(r)!=="svelte-12eyqa1"&&(r.innerHTML=Rl),Ul=a(l),B=M(l,"P",{"data-svelte-h":!0}),i(B)!=="svelte-z71ivx"&&(B.innerHTML=$l),ol=a(l),x=M(l,"P",{"data-svelte-h":!0}),i(x)!=="svelte-x4ueck"&&(x.textContent=Xl),pl=a(l),E=M(l,"P",{"data-svelte-h":!0}),i(E)!=="svelte-p7mr9a"&&(E.textContent=ql),Tl=a(l),o(W.$$.fragment,l),yl=a(l),Q=M(l,"P",{"data-svelte-h":!0}),i(Q)!=="svelte-18rw6xl"&&(Q.innerHTML=Yl),ml=a(l),o(Z.$$.fragment,l),ul=a(l),N=M(l,"P",{"data-svelte-h":!0}),i(N)!=="svelte-66jeeb"&&(N.innerHTML=Hl),cl=a(l),G=M(l,"P",{"data-svelte-h":!0}),i(G)!=="svelte-741za"&&(G.textContent=Ll),rl=a(l),o(A.$$.fragment,l),wl=a(l),k=M(l,"P",{"data-svelte-h":!0}),i(k)!=="svelte-gbmyfe"&&(k.innerHTML=zl),jl=a(l),S=M(l,"P",{"data-svelte-h":!0}),i(S)!=="svelte-10ho98a"&&(S.innerHTML=Ol),bl=a(l),F=M(l,"P",{"data-svelte-h":!0}),i(F)!=="svelte-uxehys"&&(F.innerHTML=Pl),dl=a(l),o(_.$$.fragment,l),Il=a(l),o(v.$$.fragment,l),Cl=a(l),R=M(l,"P",{"data-svelte-h":!0}),i(R)!=="svelte-hio4gu"&&(R.innerHTML=Dl),gl=a(l),$=M(l,"P",{"data-svelte-h":!0}),i($)!=="svelte-bo2cy"&&($.textContent=Kl),hl=a(l),X=M(l,"P",{"data-svelte-h":!0}),i(X)!=="svelte-q3vd3v"&&(X.innerHTML=lt),fl=a(l),o(q.$$.fragment,l),Vl=a(l),w=M(l,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),i(w)!=="svelte-9lkdhc"&&(w.innerHTML=tt),Bl=a(l),Y=M(l,"P",{"data-svelte-h":!0}),i(Y)!=="svelte-19brcgj"&&(Y.innerHTML=et),xl=a(l),o(H.$$.fragment,l),El=a(l),z=M(l,"P",{}),st(z).forEach(e),this.h()},h(){O(u,"name","hf:doc:metadata"),O(u,"content",mt),O(c,"class","tip"),O(r,"class","tip"),O(w,"class","tip")},m(l,t){ot(document.head,u),s(l,P,t),s(l,L,t),s(l,D,t),p(j,l,t),s(l,K,t),p(b,l,t),s(l,ll,t),s(l,d,t),s(l,tl,t),s(l,I,t),s(l,el,t),s(l,C,t),s(l,sl,t),s(l,g,t),s(l,nl,t),s(l,h,t),s(l,al,t),s(l,f,t),s(l,Jl,t),s(l,c,t),s(l,Ml,t),p(V,l,t),s(l,il,t),s(l,r,t),s(l,Ul,t),s(l,B,t),s(l,ol,t),s(l,x,t),s(l,pl,t),s(l,E,t),s(l,Tl,t),p(W,l,t),s(l,yl,t),s(l,Q,t),s(l,ml,t),p(Z,l,t),s(l,ul,t),s(l,N,t),s(l,cl,t),s(l,G,t),s(l,rl,t),p(A,l,t),s(l,wl,t),s(l,k,t),s(l,jl,t),s(l,S,t),s(l,bl,t),s(l,F,t),s(l,dl,t),p(_,l,t),s(l,Il,t),p(v,l,t),s(l,Cl,t),s(l,R,t),s(l,gl,t),s(l,$,t),s(l,hl,t),s(l,X,t),s(l,fl,t),p(q,l,t),s(l,Vl,t),s(l,w,t),s(l,Bl,t),s(l,Y,t),s(l,xl,t),p(H,l,t),s(l,El,t),s(l,z,t),Wl=!0},p:at,i(l){Wl||(T(j.$$.fragment,l),T(b.$$.fragment,l),T(V.$$.fragment,l),T(W.$$.fragment,l),T(Z.$$.fragment,l),T(A.$$.fragment,l),T(_.$$.fragment,l),T(v.$$.fragment,l),T(q.$$.fragment,l),T(H.$$.fragment,l),Wl=!0)},o(l){y(j.$$.fragment,l),y(b.$$.fragment,l),y(V.$$.fragment,l),y(W.$$.fragment,l),y(Z.$$.fragment,l),y(A.$$.fragment,l),y(_.$$.fragment,l),y(v.$$.fragment,l),y(q.$$.fragment,l),y(H.$$.fragment,l),Wl=!1},d(l){l&&(e(P),e(L),e(D),e(K),e(ll),e(d),e(tl),e(I),e(el),e(C),e(sl),e(g),e(nl),e(h),e(al),e(f),e(Jl),e(c),e(Ml),e(il),e(r),e(Ul),e(B),e(ol),e(x),e(pl),e(E),e(Tl),e(yl),e(Q),e(ml),e(ul),e(N),e(cl),e(G),e(rl),e(wl),e(k),e(jl),e(S),e(bl),e(F),e(dl),e(Il),e(Cl),e(R),e(gl),e($),e(hl),e(X),e(fl),e(Vl),e(w),e(Bl),e(Y),e(xl),e(El),e(z)),e(u),m(j,l),m(b,l),m(V,l),m(W,l),m(Z,l),m(A,l),m(_,l),m(v,l),m(q,l),m(H,l)}}}const mt='{"title":"在 LlamaIndex 中使用智能体","local":"在-llamaindex-中使用智能体","sections":[{"title":"初始化智能体","local":"初始化智能体","sections":[],"depth":2},{"title":"使用 QueryEngineTools 创建 RAG 智能体","local":"使用-queryenginetools-创建-rag-智能体","sections":[],"depth":2},{"title":"创建多智能体系统","local":"创建多智能体系统","sections":[],"depth":2}],"depth":1}';function ut(Nl){return Jt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class dt extends Mt{constructor(u){super(),it(this,u,ut,yt,nt,{})}}export{dt as component};
