Skip to main content
Loading navigation
Back to prompt library

Build a Multi-Tool LlamaIndex Agent

Linked challenge: Agent for Enterprise M&A Due Diligence

Prompt source

implementation25 lines6 sectionsNo variables1 code block
Implement a LlamaIndex agent that can query both your created `VectorStoreIndex` and a simulated web search tool (which could be Skyvern-powered or a simple mock function). The agent should be able to decide which tool to use based on the user's M&A query. Use `OpenAIAgent` or a custom `ReActAgent` pattern from LlamaIndex. Provide code for tool definition and agent initialization. Ensure Gemini 2.5 Pro is configured as the agent's underlying LLM.

```python
from llama_index.core.tools import FunctionTool
from llama_index.agent.openai import OpenAIAgent # Or other agent types
from llama_index.llms.gemini import Gemini

# Example simulated web search tool (replace with Skyvern integration)
def simulated_web_search(query: str) -> str:
    if 'market share' in query:
        return "Acme Corp has 15% market share in data management."
    return "No relevant web result found."

web_search_tool = FunctionTool.from_defaults(
    fn=simulated_web_search, 
    name="web_search", 
    description="Searches the web for up-to-date information."
)

# Assuming 'index' is already defined from previous step
query_engine = index.as_query_engine()

# Define the agent
agent_llm = Gemini(model="gemini-pro", temperature=0.0)
agent = OpenAIAgent(
    llm=agent_llm,
    tools=[web_search_tool, query_engine.as_tool(name="internal_docs_qa", description="Query internal M&A documents.")],
    verbose=True
)
```