Reinforcing AppAgent

UFO provides versatile mechanisms to reinforce the AppAgent's capabilities through RAG (Retrieval-Augmented Generation) and other techniques. These enhance the AppAgent's understanding of the task, improving the quality of the generated plans, and increasing the efficiency of the AppAgent's interactions with the application.

We currently support the following reinforcement methods:

Reinforcement Method Description
Learning from Help Documents Reinforce the AppAgent by retrieving knowledge from help documents.
Learning from Bing Search Reinforce the AppAgent by searching for information on Bing to obtain up-to-date knowledge.
Learning from Self-Experience Reinforce the AppAgent by learning from its own successful experiences.
Learning from User Demonstrations Reinforce the AppAgent by learning from action trajectories demonstrated by users.

Knowledge Provision

UFO provides the knowledge to the AppAgent through a context_provision method defined in the AppAgent class:

def context_provision(self, request: str = "") -> None:
    """
    Provision the context for the app agent.
    :param request: The Bing search query.
    """

    # Load the offline document indexer for the app agent if available.
    if configs["RAG_OFFLINE_DOCS"]:
        utils.print_with_color(
            "Loading offline help document indexer for {app}...".format(
                app=self._process_name
            ),
            "magenta",
        )
        self.build_offline_docs_retriever()

    # Load the online search indexer for the app agent if available.

    if configs["RAG_ONLINE_SEARCH"] and request:
        utils.print_with_color("Creating a Bing search indexer...", "magenta")
        self.build_online_search_retriever(
            request, configs["RAG_ONLINE_SEARCH_TOPK"]
        )

    # Load the experience indexer for the app agent if available.
    if configs["RAG_EXPERIENCE"]:
        utils.print_with_color("Creating an experience indexer...", "magenta")
        experience_path = configs["EXPERIENCE_SAVED_PATH"]
        db_path = os.path.join(experience_path, "experience_db")
        self.build_experience_retriever(db_path)

    # Load the demonstration indexer for the app agent if available.
    if configs["RAG_DEMONSTRATION"]:
        utils.print_with_color("Creating an demonstration indexer...", "magenta")
        demonstration_path = configs["DEMONSTRATION_SAVED_PATH"]
        db_path = os.path.join(demonstration_path, "demonstration_db")
        self.build_human_demonstration_retriever(db_path)

The context_provision method loads the offline document indexer, online search indexer, experience indexer, and demonstration indexer for the AppAgent based on the configuration settings in the config_dev.yaml file.

Reference

UFO employs the Retriever class located in the ufo/rag/retriever.py file to retrieve knowledge from various sources. The Retriever class provides the following methods to retrieve knowledge:

Bases: ABC

Class to retrieve documents.

Create a new Retriever.

Source code in rag/retriever.py
41
42
43
44
45
46
47
48
def __init__(self) -> None:
    """
    Create a new Retriever.
    """

    self.indexer = self.get_indexer()

    pass

get_indexer() abstractmethod

Get the indexer.

Returns:
  • The indexer.

Source code in rag/retriever.py
50
51
52
53
54
55
56
@abstractmethod
def get_indexer(self):
    """
    Get the indexer.
    :return: The indexer.
    """
    pass

retrieve(query, top_k, filter=None)

Retrieve the document from the given query. :filter: The filter to apply to the retrieved documents.

Parameters:
  • query (str) –

    The query to retrieve the document from.

  • top_k (int) –

    The number of documents to retrieve.

Returns:
  • The document from the given query.

Source code in rag/retriever.py
58
59
60
61
62
63
64
65
66
67
68
69
def retrieve(self, query: str, top_k: int, filter=None):
    """
    Retrieve the document from the given query.
    :param query: The query to retrieve the document from.
    :param top_k: The number of documents to retrieve.
    :filter: The filter to apply to the retrieved documents.
    :return: The document from the given query.
    """
    if not self.indexer:
        return None

    return self.indexer.similarity_search(query, top_k, filter=filter)