I’m working with llama-index, OpenAI, and Zapier NLA to build an agent that can handle different tasks. The problem is my OpenAIAgent keeps using only the first tool from my tool collection and completely ignores the rest.
Steps I’ve taken:
- Created a custom ZapierToolSpec class to handle function calls differently
- Confirmed that my_zapier_spec.to_tool_list() gives back several tools
- Used the tool collection with
OpenAIAgent.from_tools()but it won’t consider other options
import dotenv
import os
from llama_hub.tools.zapier.base import ZapierToolSpec
from llama_index.agent.openai import OpenAIAgent
from llama_index.llms.openai import OpenAI
from llama_index.core.tools.function_tool import FunctionTool
dotenv.load_dotenv()
OPENAI_KEY = os.getenv("OPENAI_API_KEY")
ZAPIER_KEY = os.getenv("ZAPIER_NLA_API_KEY")
model = OpenAI(model="gpt-4o", api_key=OPENAI_KEY)
class MyZapierToolSpec(ZapierToolSpec):
def to_tool_list(self):
base_tools = super().to_tool_list()
updated_tools = []
for item in base_tools:
base_function = item.fn
def updated_function(*params, **keyword_params):
if "keyword_params" in keyword_params and isinstance(keyword_params["keyword_params"], dict):
keyword_params = keyword_params["keyword_params"]
return base_function(**keyword_params)
updated_tools.append(FunctionTool(fn=updated_function, metadata=item.metadata))
return updated_tools
my_zapier_spec = MyZapierToolSpec(api_key=ZAPIER_KEY)
tool_collection = my_zapier_spec.to_tool_list()
print(f"Available tools: {tool_collection}")
my_agent = OpenAIAgent.from_tools(tools=tool_collection, verbose=True, llm=model)
user_request = "Schedule a calendar appointment called 'Team Meeting' for next day at 3 PM."
print(my_agent.chat(user_request))
What should happen: The agent picks the right tool based on what I’m asking for.
What actually happens: It always goes with the first tool in the list, no matter if another one fits better.