Getting Started: Agent Executors
Agents use an LLM to determine which actions to take and in what order. An action can either be using a tool and observing its output, or returning to the user.
When used correctly agents can be extremely powerful. In this tutorial, we show you how to easily use agents through the simplest, highest level API.
In order to load agents, you should understand the following concepts:
- Tool: A function that performs a specific duty. This can be things like: Google Search, Database lookup, code REPL, other chains. The interface for a tool is currently a function that is expected to have a string as an input, with a string as an output.
- LLM: The language model powering the agent.
- Agent: The agent to use. This should be a string that references a support agent class. Because this notebook focuses on the simplest, highest level API, this only covers using the standard supported agents.
For this example, you'll need to set the SerpAPI environment variables in the .env
file.
SERPAPI_API_KEY="..."
Load the LLM
llm, err := ollama.New(ollama.WithModel("llama2"))
if err != nil {
return err
}
Define Tools
search, err := serpapi.New()
if err != nil {
return err
}
agentTools := []tools.Tool{
tools.Calculator{},
search,
}
Create Prompt
prompt := "Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?"
Create the Agent Executor
executor, err := agents.Initialize(
llm,
agentTools,
agents.ZeroShotReactDescription,
agents.WithMaxIterations(3),
)
if err != nil {
return err
}
answer, err := chains.Run(context.Background(), executor, prompt)
fmt.Println(answer)
return err
You can compare this to the base LLM.
baseline, _ := llm.Call(context.Background(), prompt)
fmt.Println(baseline)