Find answers from the community

Updated 2 months ago

I want to create an agent that takes a query and rephrase it for an airline company

I want to create an agent that takes a query and rephrase it for an airline company
k
D
6 comments
Please stand by @Doğan as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
To create an agent that takes a query and rephrases it, you can use the LlamaIndex framework. Here's a general outline of how you can do it:

  1. Define your Query Engine Tools: These are the tools that your agent will use to process queries. In your case, you might want to create a tool that is specific to the airline industry. You can create a Query Engine Tool using the QueryEngineTool class from llama_index.core.tools. Here's an example of how to do it:
Plain Text
from llama_index.core.agent import ReActAgent
from llama_index.core.tools import QueryEngineTool

# NOTE: airline_index is a SimpleVectorIndex instance
airline_engine = airline_index.as_query_engine(similarity_top_k=3)

query_engine_tools = [
    QueryEngineTool(
        query_engine=airline_engine,
        metadata=ToolMetadata(
            name="airline_query",
            description="Provides information about airlines. "
            "Use a detailed plain text question as input to the tool.",
        ),
        return_direct=False,
    ),
]

Source ()

  1. Create your Agent: Once you have your tools defined, you can create your agent. You can use the ReActAgent class from llama_index.core.agent to do this. Here's an example:
Plain Text
# initialize ReAct agent
agent = ReActAgent.from_tools(query_engine_tools, llm=llm, verbose=True)

Source ()

  1. Handle Clarification: If a user's query is unclear, you can use a QueryUnderstandingAgentWorker to ask the user for clarification. Here's an example of how to do it:
```python
from llama_index.core.agent import QueryUnderstandingAgentWorker
callback_manager = llm.callback_manager
agent_worker = QueryUnderstandingAgentWorker.from_tools(
tools,
llm=llm,
callback_manager=callback_manager,
)
agent = AgentRunner(agent_worker, callback_manager=callback_manager)
`` **Source** (<https://github.com/jerryjliu/llama_index/blob/main/llama-index-packs/llama-index-packs-query-understanding-agent/examples/query_understanding_agent.ipynb>) Please note that you'll need to replace airline_index with your actual index for airline data, and llm` with your chosen language model.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
I want to create an agent that takes a sentence and rephrase it for an airline company
@kapa.ai
Let me check the knowledge base for you. One moment! :books:
----------------------
To create an agent that takes a sentence and rephrases it for an airline company, you can use the LlamaIndex framework. However, the knowledge sources provided do not contain specific information on how to create a rephrasing tool or agent.

The general process would involve creating a tool that can rephrase sentences in the context of an airline company. This tool would need to be trained on a dataset of sentences and their rephrased versions in the airline context. Once this tool is created, it can be used to create an agent using the OpenAIAgent or ReActAgent classes from llama_index.core.agent.

Here's a general example of how to create an agent with a tool:

Plain Text
from llama_index.core.agent import OpenAIAgent
from llama_index.core.tools import FunctionTool

# Define your rephrasing tool
def rephrase_for_airline(sentence):
    # Implement your rephrasing logic here
    pass

rephrase_tool = FunctionTool.from_defaults(fn=rephrase_for_airline)

# Create your agent
agent = OpenAIAgent.from_tools([rephrase_tool], llm=llm, verbose=True)


Please note that you'll need to replace rephrase_for_airline with your actual rephrasing function, and llm with your chosen language model.

For more detailed information on creating custom tools and agents, you can refer to the LlamaIndex documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord