llama_index icon indicating copy to clipboard operation
llama_index copied to clipboard

[Bug]: Function name misplace with fn name

Open nhantran0506 opened this issue 10 months ago • 5 comments

Bug Description

Hi, I am using FunctionAgent to code my custom agent, but I always get the error that the agent rather using the name of the tool, it using the fn name which leading to result that it couldn't access the tool

Please help me.

Version

0.12.19

Steps to Reproduce

Here is my code for the tools tools = [ FunctionTool.from_defaults( name="search_artist", description="Search artist in vector store.", async_fn=artist_util.search_artist, fn_schema = SearchArtistPara, return_direct=True ), ]

And here is the SearchArtistPara

class SearchArtistPara(BaseModel): query: str = Field( description="The search query string used to find artists in vector database. May contain need information such as location, etc" ) location: Optional[str] = Field(description="Artist location", default="") service_offer: Optional[str] = Field( description="Service offer by artist.", default="" ) limit: Optional[int] = Field( description="The maximum search results to return.", default=5, ) alpha: Optional[int] = Field( description="The relevance factor or weight applied to search results for hybrid search.", default=0.4, )

When I tracking the tool name using handler = _agent.run(user_msg=user_query, chat_history=chat_history) event_id = None async for event in handler.stream_events(): if isinstance(event, ToolCall): if event_id != event.tool_id: tool_msg.append( f"Use tool {event.tool_name} with input {event.tool_kwargs}" ) logger.info( f"Try : {len(tool_msg)} {event.tool_name} {event.tool_kwargs}" ) event_id = event.tool_id response = await handler

I get the log as Try : 1 SearchArtistPara {'limit': 10.0, 'query': 'artist can dragon dance', 'location': 'new york'}

Relevant Logs/Tracbacks


nhantran0506 avatar Feb 20 '25 02:02 nhantran0506

The issue you're encountering seems to be related to the FunctionAgent using the function name instead of the specified tool name. In your setup, you've defined the tool with the name "search_artist", but the logs indicate that the tool is being referred to by the schema name "SearchArtistPara".

This behavior might be due to how the FunctionTool.from_defaults method associates the tool name with the function name. By default, if a tool name is not explicitly provided, it uses the function name. However, in your case, you have provided a tool name, so it should be using "search_artist" instead of "SearchArtistPara".

Here are a few things you can check or try:

  1. Ensure Correct Tool Name Usage: Double-check that the FunctionTool.from_defaults method is correctly using the provided tool name. You might want to verify if there are any overrides or misconfigurations elsewhere in your code that could affect this behavior.

  2. Debugging: Add additional logging to confirm that the tool is being initialized with the correct name. You can log the tool's metadata right after its creation to ensure it reflects the expected name.

  3. Version-Specific Issues: Since you're using version 0.12.19, there might be a version-specific issue or bug. Although I couldn't find any known issues related to tool name resolution in this version, you might want to check the release notes or any recent bug fixes that could address this problem.

If these steps don't resolve the issue, consider reviewing the implementation details of the FunctionAgent and FunctionTool to ensure there are no underlying bugs or misconfigurations affecting the tool name resolution.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Feb 20 '25 02:02 dosubot[bot]

The log you gave indicates that it's calling the tool correctly no? Pretty sure providing your own schema will override the name and description you pass in

logan-markewich avatar Feb 20 '25 02:02 logan-markewich

@logan-markewich yes, the log is it's calling the tool. If provided my own schema will override the name then is there any way I still provide the schema but keep the real function name ?

nhantran0506 avatar Feb 20 '25 02:02 nhantran0506

@nhantran0506 hmm, so the schema is what the LLM ends up seeing. So when the llm calls a tool, it uses the name from the schema

logan-markewich avatar Feb 20 '25 03:02 logan-markewich

@logan-markewich Yes, that right

nhantran0506 avatar Feb 20 '25 03:02 nhantran0506

Hi, @nhantran0506. I'm Dosu, and I'm helping the LlamaIndex team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • You reported a bug in the FunctionAgent where the tool name is replaced by the function schema name, causing errors.
  • I suggested checking the FunctionTool.from_defaults method and ensuring the correct tool name is used.
  • Logan-markewich noted that providing a custom schema might override the tool name and confirmed that the schema name is used by the LLM.
  • You are seeking a way to provide a schema while retaining the original function name.

Next Steps

  • Please confirm if this issue is still relevant to the latest version of the LlamaIndex repository. If so, you can keep the discussion open by commenting on the issue.
  • Otherwise, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar May 22 '25 16:05 dosubot[bot]