> ## Documentation Index
> Fetch the complete documentation index at: https://docs.llmstudio.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a tool agent

This guide outlines how to build a tool calling agent using Langchain + LLMstudio.

## 1. Set up your tools

Start by defining the tools your agent is going to have access to.

```python theme={null}
from langchain.tools import tool

@tool
def buy_ticket(destination: str):
    """Use this to buy a ticket"""
    return "Bought ticket number 270924"

@tool
def get_departure(ticket_number: str):
    """Use this to fetch the departure time of a train"""
    return "8:25 AM"
```

## 2. Setup your .env

Create a `.env` file on the root of your project with the the credentials for the providers you want to use.

<Tabs>
  <Tab title="OpenAI">
    ```
    OPENAI_API_KEY="YOUR_API_KEY"
    ```
  </Tab>

  <Tab title="VertexAI">
    ```
    GOOGLE_API_KEY="YOUR_API_KEY"
    ```
  </Tab>

  <Tab title="Azure">
    ```
    AZURE_BASE_URL="YOUR_MODEL_ENDPOINT"
    AZURE_API_KEY="YOUR_API_KEY"
    ```
  </Tab>
</Tabs>

## 3. Set up your model using LLMstudio

Use LLMstudio to choose the provider and model you want to use.

<Tabs>
  <Tab title="OpenAI">
    ```python theme={null}
    model = ChatLLMstudio(model_id='openai/gpt-4o')
    ```
  </Tab>

  <Tab title="VertexAI">
    ```python theme={null}
    model = ChatLLMstudio(model_id='vertexai/gemini-1.5-flash')
    ```
  </Tab>

  <Tab title="Azure">
    ```python theme={null}
    model = ChatLLMstudio(model_id='azure/Meta-Llama-3.1-70B-Instruct')
    ```
  </Tab>
</Tabs>

## 4. Build the agent

Set up your agent and agent executor using Langchain.

```python theme={null}
from langchain import hub
from langchain.agents import AgentExecutor, create_openai_tools_agent

prompt = hub.pull("hwchase17/openai-tools-agent")
agent = create_openai_tools_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)

input = "Can you buy me a ticket to madrid?"

# Using with chat history
agent_executor.invoke(
    {
        "input": input,
    }
)
```
