Agente com Ferramenta RAG

Saiba como criar um agente com uma ferramenta RAG predefinida.

Exemplo de Agente de Suporte

Neste exemplo, criamos um agente de suporte equipado com uma ferramenta RAG agentic pré-construída.

As ferramentas RAG permitem que o agente use bases de conhecimento para responder a perguntas fundamentadas em documentos. Para criar uma base de conhecimento e obter seu ID, siga este guia.


Informações: As ferramentas RAG são executadas no lado do servidor na Nuvem do OCI.

A implementação é um RAG agêntico em que o sistema age mais como um agente autônomo do que como um recuperador passivo e gerador.


Você também pode passar vários IDs da base de conhecimento para o AgenticRagTool.

Python

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()

Java

SupportAgent.java

package demos.singleTurnSingleTool.SupportAgent;

import com.oracle.bmc.ConfigFileReader;
import com.oracle.bmc.adk.agent.Agent;
import com.oracle.bmc.adk.agent.RunOptions;
import com.oracle.bmc.adk.client.AgentClient;
import com.oracle.bmc.adk.tools.prebuilt.AgenticRagTool;
import com.oracle.bmc.adk.run.RunResponse;
import com.oracle.bmc.auth.BasicAuthenticationDetailsProvider;
import com.oracle.bmc.auth.SessionTokenAuthenticationDetailsProvider;

import java.util.Arrays;

public class SupportAgent {
  public static void main(String[] args) throws Exception {
    final String configLocation = "~/.oci/config";
    final String configProfile = "DEFAULT";

   // Assuming the knowledge base is already provisioned
   final String knowledgeBaseId = "ocid1.genaiagentknowledgebase...";

    BasicAuthenticationDetailsProvider authProvider =
            new SessionTokenAuthenticationDetailsProvider(
                    ConfigFileReader.parse(configLocation, configProfile));

    AgentClient agentClient = AgentClient.builder()
        .authProvider(authProvider)
        .region("us-chicago-1")
        .build();

    Agent agent = Agent.builder()
            .client(agentClient)
            .agentEndpointId("ocid1.genaiagentendpoint...")
            .instructions("Answer question using the OCI RAG tool.")
            .tools(
                Arrays.asList(
                    AgenticRagTool.builder().knowledgeBaseIds(Arrays.asList(knowledgeBaseId)).build()))
            .build();

    agent.setup();

    final String input = "Tell me about Oracle Cloud Infrastructure.";
    final Integer maxStep = 3;
    final RunOptions runOptions = RunOptions.builder().maxSteps(maxStep).build();
    RunResponse response = agent.run(input, runOptions);
    response.prettyPrint();
  }
}