DOC: How to properly initialize Function Agent as a Tool for other Agent
Labels: name: area: agent, name: auto:question, name: auto:documentation

### Issue with current documentation:

I would like to get clarification of proper setting of Function Agents as Tools for other Agents.

In [Agent Tools Docs](https://python.langchain.com/docs/modules/agents/tools/) said that **tools can be even other agents but there are lack of examples** 

I have implemented the following code with 2 approaches - Inheriting from the `BaseTool` interface to convert a Function Agent into a Tool object and I have also tried `Tool.from_function()` approach. My goal is to pre-define custom business formulas to be executed precisely as required and OpenAI Functions suit my needs well. For this purpose, I must use the Function Agent and I have followed this [Custom functions with OpenAI Functions Agent guide](https://python.langchain.com/docs/modules/agents/how_to/custom-functions-with-openai-functions-agent). However, there's a need to use other types of tools as well, requiring the initialization of different Agent types to invoke them. I'm seeking a solution where I can have a centralized Agent capable of invoking other agents. Currently, I can see only a solution using Classification Chain model for this purpose as provided below cases don't work 



### Current Behavior

The current structure of the code exhibits the following issues:

- The `function_agent` executes FOO OpenAI Function and other tasks perfectly.
- The `main_agent` throws errors and occasionally manages to execute the FOO OpenAI function. Not sure why it's able to run successfully once in time.

### Desired Behavior

I would like the `functions_agent` to function seamlessly within the `main_agent` so that it performs the same well.

I believe there might be an issue with how the `message query` is being passed to OpenAI Python Functions in the two distinct approaches outlined below. Can you please offer guidance on the correct method to initialize the Function agent as a tool for another agent or suggest an alternative approach to achieve the desired behavior. Thank you

```python

from langchain.agents import initialize_agent
from langchain.chat_models import ChatOpenAI
from langchain.agents import AgentType, Tool
from pydantic import BaseModel, Field
from langchain.tools import BaseTool
from typing import Type
from dotenv import load_dotenv, find_dotenv

_ = load_dotenv(find_dotenv())


def foo(target):
    """Useful when you want to get current mean and std
    """
    return {"TARGET": target, "number": 123}


class FooFuncInput(BaseModel):
    """Inputs parsed from LLM for 'foo' function"""
    target: str = Field(description="Allows for manual interaction using either hands or legs. "
                                    "allowable values: {`hands`, `legs`} ")


class FooFuncTool(BaseTool):
    name = "foo"
    description = f"""
        Calculate {name} business function.
        """
    args_schema: Type[BaseModel] = FooFuncInput
    return_direct = True
    verbose = False

    def _run(self, target: str):
        response = foo(target)
        return response

    def _arun(self):
        raise NotImplementedError("foo does not support async")


def get_function_tools():
    tools = [
        FooFuncTool(),
    ]
    return tools


functions_agent = initialize_agent(
    tools=get_function_tools(),
    llm=ChatOpenAI(model="gpt-3.5-turbo", temperature=0),
    agent=AgentType.OPENAI_FUNCTIONS,
    verbose=True,
    max_iterations=1,
    early_stopping_method="generate"
)


class AGENT_FUNCTION_TOOL(BaseTool):
    name = "AGENT_FUNCTION_TOOL"
    description = """
                Useful for when you need to calculate business functions
                Names of allowable business functions: `ATT`, `DDT`, `FOO`
                """
    return_direct = True
    verbose = True

    def _run(self, query: str):
        response = functions_agent.run(query)
        return response

    def _arun(self):
        raise NotImplementedError("AGENT_FUNCTION_TOOL does not support async")


tools = [
    AGENT_FUNCTION_TOOL(),

    # Tool.from_function(
    #     func=functions_agent.run,
    #     name="Defined Business functions agent",
    #     description="""
    #         Useful for when you need to calculate business functions
    #         Names of allowable business functions: `ATT`, `DDT`, `FOO`
    #         """),
]

assistant_target = 'business management'

agent_kwargs = \
    {'prefix': f'You are friendly {assistant_target} assistant.'
               f'questions related to {assistant_target}. You have access to the following tools:'}

main_agent = initialize_agent(
    tools=tools,
    llm=ChatOpenAI(model="gpt-3.5-turbo", temperature=0),
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
    max_iterations=1,
    early_stopping_method="generate",
    agent_kwargs=agent_kwargs
)

message = 'calculate business function `FOO` and do it with bare hands'
main_agent.run(message)

```

Also I have tried using `Tool.from_function()` method  as explained on [reddit can an agent be a tool thread](https://www.reddit.com/r/LangChain/comments/13618qu/can_an_agent_be_a_tool/) but it looks like `message` query is not properly passed to OpenAI python Functions also. 

```python
Tool.from_function(
    func=functions_agent.run,
    name="Defined Business functions agent",
    description="""
            Useful for when you need to calculate business functions
            Names of allowable business functions: `ATT`, `DDT`, `FOO`
            """),
```

---------
Executed script using `main_agent` with `AGENT_FUNCTION_TOOL`, class implemented from `BaseTool` langchain interface
![Screenshot from 2023-09-09 13-50-02](https://github.com/langchain-ai/langchain/assets/23149363/40854487-8bd3-49cf-86f3-58183c16f8df)

---------
Executed script using `main_agent` with `Tool.from_function()` 
![Screenshot from 2023-09-09 13-52-48](https://github.com/langchain-ai/langchain/assets/23149363/c3e26e59-cf7b-4631-9ac9-ce4a4eb8f951)

---------
Executing script using `functions_agent` and desired behavior:
![Screenshot from 2023-09-09 14-20-30](https://github.com/langchain-ai/langchain/assets/23149363/a13ea5db-c09b-4c37-8e92-9ba796d6dc2a)



### Idea or request for content:

How to properly use Function Agents as Tools which consequently can be used by other Agents.