AutogenMultiAgent / src /agents /wikipediaagent.py
genaitiwari's picture
refinement of llamaindex tool
ac85c1d
# from some_module import WikipediaToolSpec, ReActAgent # Ensure you have the correct imports
# from some_llm_module import llm # Import the LLM you're using
from llama_index.core import Settings
from llama_index.core.agent import ReActAgent
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
from llama_index.tools.wikipedia import WikipediaToolSpec
class WikipediaAgent:
def __init__(self, llm):
self.llm = llm
self.wikipedia_tool = None
self.agent = None
def create_agent(self, max_iterations=8, verbose=True):
# Create the Wikipedia tool specification
wiki_spec = WikipediaToolSpec()
# Get the search Wikipedia tool
self.wikipedia_tool = wiki_spec.to_tool_list()
# Create the ReActAgent with the Wikipedia tool
self.agent = ReActAgent.from_tools(
tools=self.wikipedia_tool,
llm=self.llm,
max_iterations=max_iterations,
verbose=verbose
)
return self.agent
# Usage
# wiki_agent = WikipediaAgent(llm)
# agent = wiki_agent.create_agent()