最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why does OpenAIAgent only use the first tool from a Zapier tool list in llama-index? - Stack Overflow

programmeradmin4浏览0评论

I am using llama-index with OpenAI and Zapier NLA to create an agent that can execute multiple actions. However, my OpenAIAgent only selects the first tool from the list and ignores the others.

What I Have Done

  • I implemented a custom ZapierToolSpec to modify function execution.
  • I verified that zapier_spec.to_tool_list() returns multiple tools.
  • I passed the tool list to OpenAIAgent.from_tools() but it still only picks the first one.
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_API_KEY = os.getenv("OPENAI_API_KEY")
ZAPIER_NLA_API_KEY = os.getenv("ZAPIER_NLA_API_KEY")

llm = OpenAI(model="gpt-4o", api_key=OPENAI_API_KEY)

class CustomZapierToolSpec(ZapierToolSpec):
    def to_tool_list(self):
        original_tools = super().to_tool_list()
        modified_tools = []
        
        for tool in original_tools:
            original_fn = tool.fn

            def new_fn(*args, **kwargs):
                if "kwargs" in kwargs and isinstance(kwargs["kwargs"], dict):
                    kwargs = kwargs["kwargs"]
                return original_fn(**kwargs)

            modified_tools.append(FunctionTool(fn=new_fn, metadata=tool.metadata))

        return modified_tools

zapier_spec = CustomZapierToolSpec(api_key=ZAPIER_NLA_API_KEY)
tools = zapier_spec.to_tool_list()

print(f"Tools available: {tools}")  

agent = OpenAIAgent.from_tools(tools=tools, verbose=True, llm=llm)

query = "Create a new calendar event named 'Meeting' for tomorrow at 2 PM."

print(agent.chat(query))

Expected Behavior:

The agent should be able to pick the correct tool dynamically instead of always selecting the first one.

Actual Behavior:

Only the first tool in tools is ever used, even if another tool is more appropriate for the query.

发布评论

评论列表(0)

  1. 暂无评论