RAGツールを使用したエージェント
事前構築済のRAGツールを使用してエージェントを作成する方法について学習します。
サポート・エージェントの例
この例では、事前構築済みのエージェントRAGツールを備えたサポートエージェントを作成します。
RAGツールを使用すると、エージェントはナレッジ・ベースを使用して、ドキュメントに基づいた質問に回答できます。ナレッジ・ベースを作成し、そのIDを取得するには、このガイドに従います。
情報: RAGツールは、OCI Cloudのサーバー側で実行されます。
実装はエージェントRAGで、システムはパッシブ・リトリバーやジェネレータではなく自律エージェントのように動作します。
複数のナレッジ・ベースIDをAgenticRagTool
に渡すこともできます。
support_agent.py
from oci.addons.adk import Agent, AgentClient
from oci.addons.adk.tool.prebuilt import AgenticRagTool
def main():
client = AgentClient(
auth_type="api_key",
profile="DEFAULT",
region="us-chicago-1"
)
# Assuming the knowledge base is already provisioned
knowledge_base_id = "ocid1.genaiagentknowledgebase..."
# Create a RAG tool that uses the knowledge base
# The tool name and description are optional, but strongly recommended for LLM to understand the tool.
rag_tool = AgenticRagTool(
name="OCI RAG tool",
description="Use this tool to answer questions about Oracle Cloud Infrastructure (OCI).",
knowledge_base_ids=[knowledge_base_id],
)
# Create the agent with the RAG tool
agent = Agent(
client=client,
agent_endpoint_id="ocid1.genaiagentendpoint...",
instructions="Answer question using the OCI RAG tool.",
tools=[rag_tool]
)
# Set up the agent once
agent.setup()
# Run the agent with a user query
input = "Tell me about Oracle Cloud Infrastructure."
response = agent.run(input)
response.pretty_print()
if __name__ == "__main__":
main()