mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 02:34:29 +00:00
85 lines
3.4 KiB
Text
85 lines
3.4 KiB
Text
---
|
|
sidebar_position: 4
|
|
---
|
|
# Agents
|
|
|
|
The core idea of agents is to use an LLM to choose a sequence of actions to take.
|
|
In chains, a sequence of actions is hardcoded (in code).
|
|
In agents, a language model is used as a reasoning engine to determine which actions to take and in which order.
|
|
|
|
There are several key components here:
|
|
|
|
## Agent
|
|
|
|
This is the class responsible for deciding what step to take next.
|
|
This is powered by a language model and a prompt.
|
|
This prompt can include things like:
|
|
|
|
1. The personality of the agent (useful for having it respond in a certain way)
|
|
2. Background context for the agent (useful for giving it more context on the types of tasks it's being asked to do)
|
|
3. Prompting strategies to invoke better reasoning (the most famous/widely used being [ReAct](https://arxiv.org/abs/2210.03629))
|
|
|
|
LangChain provides a few different types of agents to get started.
|
|
Even then, you will likely want to customize those agents with parts (1) and (2).
|
|
For a full list of agent types see [agent types](/docs/modules/agents/agent_types/)
|
|
|
|
## Tools
|
|
|
|
Tools are functions that an agent calls.
|
|
There are two important considerations here:
|
|
|
|
1. Giving the agent access to the right tools
|
|
2. Describing the tools in a way that is most helpful to the agent
|
|
|
|
Without both, the agent you are trying to build will not work.
|
|
If you don't give the agent access to a correct set of tools, it will never be able to accomplish the objective.
|
|
If you don't describe the tools properly, the agent won't know how to properly use them.
|
|
|
|
LangChain provides a wide set of tools to get started, but also makes it easy to define your own (including custom descriptions).
|
|
For a full list of tools, see [here](/docs/modules/agents/tools/)
|
|
|
|
## Toolkits
|
|
|
|
Often the set of tools an agent has access to is more important than a single tool.
|
|
For this LangChain provides the concept of toolkits - groups of tools needed to accomplish specific objectives.
|
|
There are generally around 3-5 tools in a toolkit.
|
|
|
|
LangChain provides a wide set of toolkits to get started.
|
|
For a full list of toolkits, see [here](/docs/modules/agents/toolkits/)
|
|
|
|
## AgentExecutor
|
|
|
|
The agent executor is the runtime for an agent.
|
|
This is what actually calls the agent and executes the actions it chooses.
|
|
Pseudocode for this runtime is below:
|
|
|
|
```python
|
|
next_action = agent.get_action(...)
|
|
while next_action != AgentFinish:
|
|
observation = run(next_action)
|
|
next_action = agent.get_action(..., next_action, observation)
|
|
return next_action
|
|
```
|
|
|
|
While this may seem simple, there are several complexities this runtime handles for you, including:
|
|
|
|
1. Handling cases where the agent selects a non-existent tool
|
|
2. Handling cases where the tool errors
|
|
3. Handling cases where the agent produces output that cannot be parsed into a tool invocation
|
|
4. Logging and observability at all levels (agent decisions, tool calls) either to stdout or [LangSmith](https://smith.langchain.com).
|
|
|
|
## Other types of agent runtimes
|
|
|
|
The `AgentExecutor` class is the main agent runtime supported by LangChain.
|
|
However, there are other, more experimental runtimes we also support.
|
|
These include:
|
|
|
|
- [Plan-and-execute Agent](/docs/modules/agents/agent_types/plan_and_execute.html)
|
|
- [Baby AGI](/docs/use_cases/autonomous_agents/baby_agi.html)
|
|
- [Auto GPT](/docs/use_cases/autonomous_agents/autogpt.html)
|
|
|
|
## Get started
|
|
|
|
import GetStarted from "@snippets/modules/agents/get_started.mdx"
|
|
|
|
<GetStarted/>
|