> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 知识工具

`KnowledgeTools` 工具集支持 Agent 从知识库中搜索、检索和分析信息。此工具集与 `AgentKnowledge` 集成，并提供了一个结构化的工作流程，用于在响应用户之前查找和评估相关信息。

该工具集实现了一个“思考 → 搜索 → 分析”的循环，允许 Agent：

1. 思考问题并规划搜索查询
2. 在知识库中搜索相关信息
3. 分析结果以确定其是否充分或是否需要进一步搜索

通过提供查找、评估和综合知识的工具，这种方法显著提高了 Agent 提供准确信息的能力。

该工具集包含以下工具：

* `think`：一个用于规划、头脑风暴关键词和改进方法的便笺板。这些想法仅限于 Agent 内部，不会显示给用户。
* `search`：针对知识库执行查询以检索相关文档。
* `analyze`：评估返回的文档是否正确和充分，并确定是否需要进一步搜索。

## 示例

以下是如何使用 `KnowledgeTools` 工具集的示例：

```python theme={null}
from agno.agent import Agent
from agno.embedder.openai import OpenAIEmbedder
from agno.knowledge.url import UrlKnowledge
from agno.models.openai import OpenAIChat
from agno.tools.knowledge import KnowledgeTools
from agno.vectordb.lancedb import LanceDb, SearchType

# 创建一个包含来自 URL 的信息的知识库
agno_docs = UrlKnowledge(
    urls=["https://docs.agno.com/llms-full.txt"],
    # 使用 LanceDB 作为向量数据库，并将嵌入存储在 `agno_docs` 表中
    vector_db=LanceDb(
        uri="tmp/lancedb",
        table_name="agno_docs",
        search_type=SearchType.hybrid,
        embedder=OpenAIEmbedder(id="text-embedding-3-small"),
    ),
)

knowledge_tools = KnowledgeTools(
    knowledge=agno_docs,
    think=True,
    search=True,
    analyze=True,
    add_few_shot=True,
)

agent = Agent(
    model=OpenAIChat(id="gpt-4o"),
    tools=[knowledge_tools],
    show_tool_calls=True,
    markdown=True,
)

if __name__ == "__main__":
    # 加载知识库，首次运行时注释掉此行
    agno_docs.load(recreate=True)
    agent.print_response("How do I build multi-agent teams with Agno?", stream=True)
```

该工具集附带默认说明和少量示例（few-shot examples），以帮助 Agent 有效地使用这些工具。以下是配置它们的方法：

```python theme={null}
from agno.tools.knowledge import KnowledgeTools

knowledge_tools = KnowledgeTools(
    knowledge=my_knowledge_base,
    think=True,                # 启用 think 工具
    search=True,               # 启用 search 工具
    analyze=True,              # 启用 analyze 工具
    add_instructions=True,     # 添加默认说明
    add_few_shot=True,         # 添加少量示例
    few_shot_examples=None,    # 可选的自定义少量示例
)
```
