Docs: add agent starter flows (#3969)

This commit is contained in:
Mendon Kissling 2024-10-09 11:01:50 -04:00 committed by GitHub
commit 09fbcb2a16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 454 additions and 0 deletions

View file

@ -0,0 +1,307 @@
# Agents
Agent components are used to define the behavior and capabilities of AI agents in your flow. Agents can interact with APIs, databases, and other services, but can also use LLMs as a reasoning engine to decide which course to take in your flow.
## CSV Agent
This component creates a CSV agent from a CSV file and LLM.
### Parameters
#### Inputs
| Name | Type | Description |
|------|------|-------------|
| llm | LanguageModel | Language model to use for the agent |
| path | File | Path to the CSV file |
| agent_type | String | Type of agent to create (zero-shot-react-description, openai-functions, or openai-tools) |
#### Outputs
| Name | Type | Description |
|------|------|-------------|
| agent | AgentExecutor | CSV agent instance |
## CrewAI Agent
This component represents an Agent of CrewAI, allowing for the creation of specialized AI agents with defined roles, goals, and capabilities within a crew.
For more information, see the [CrewAI documentation](https://docs.crewai.com/core-concepts/Agents/).
### Parameters
#### Inputs
| Name | Display Name | Info |
|------|--------------|------|
| role | Role | The role of the agent |
| goal | Goal | The objective of the agent |
| backstory | Backstory | The backstory of the agent |
| tools | Tools | Tools at agent's disposal |
| llm | Language Model | Language model that will run the agent |
| memory | Memory | Whether the agent should have memory or not |
| verbose | Verbose | Enables verbose output |
| allow_delegation | Allow Delegation | Whether the agent is allowed to delegate tasks to other agents |
| allow_code_execution | Allow Code Execution | Whether the agent is allowed to execute code |
| kwargs | kwargs | Additional keyword arguments for the agent |
#### Outputs
| Name | Display Name | Info |
|------|--------------|------|
| output | Agent | The constructed CrewAI Agent object |
## Hierarchical Crew
This component represents a group of agents, managing how they should collaborate and the tasks they should perform in a hierarchical structure. This component allows for the creation of a crew with a manager overseeing the task execution.
For more information, see the [CrewAI documentation](https://docs.crewai.com/how-to/Hierarchical/).
### Parameters
#### Inputs
| Name | Display Name | Info |
|------|--------------|------|
| agents | Agents | List of Agent objects representing the crew members |
| tasks | Tasks | List of HierarchicalTask objects representing the tasks to be executed |
| manager_llm | Manager LLM | Language model for the manager agent (optional) |
| manager_agent | Manager Agent | Specific agent to act as the manager (optional) |
| verbose | Verbose | Enables verbose output for detailed logging |
| memory | Memory | Specifies the memory configuration for the crew |
| use_cache | Use Cache | Enables caching of results |
| max_rpm | Max RPM | Sets the maximum requests per minute |
| share_crew | Share Crew | Determines if the crew information is shared among agents |
| function_calling_llm | Function Calling LLM | Specifies the language model for function calling |
#### Outputs
| Name | Display Name | Info |
|------|--------------|------|
| crew | Crew | The constructed Crew object with hierarchical task execution |
## JSON Agent
This component creates a JSON agent from a JSON or YAML file and an LLM.
### Parameters
#### Inputs
| Name | Type | Description |
|------|------|-------------|
| llm | LanguageModel | Language model to use for the agent |
| path | File | Path to the JSON or YAML file |
#### Outputs
| Name | Type | Description |
|------|------|-------------|
| agent | AgentExecutor | JSON agent instance |
## OpenAI Tools Agent
This component creates an OpenAI Tools Agent using LangChain.
For more information, see the [LangChain documentation](https://python.langchain.com/v0.1/docs/modules/agents/agent_types/openai_tools/).
### Parameters
#### Inputs
| Name | Type | Description |
|------|------|-------------|
| llm | LanguageModel | Language model to use for the agent (must be tool-enabled) |
| system_prompt | String | System prompt for the agent |
| user_prompt | String | User prompt template (must contain 'input' key) |
| chat_history | List[Data] | Optional chat history for the agent |
| tools | List[Tool] | List of tools available to the agent |
#### Outputs
| Name | Type | Description |
|------|------|-------------|
| agent | AgentExecutor | OpenAI Tools Agent instance |
## OpenAPI Agent
This component creates an OpenAPI Agent to interact with APIs defined by OpenAPI specifications.
For more information, see the LangChain documentation on OpenAPI Agents.
### Parameters
#### Inputs
| Name | Type | Description |
|------|------|-------------|
| llm | LanguageModel | Language model to use for the agent |
| path | File | Path to the OpenAPI specification file (JSON or YAML) |
| allow_dangerous_requests | Boolean | Whether to allow potentially dangerous API requests |
#### Outputs
| Name | Type | Description |
|------|------|-------------|
| agent | AgentExecutor | OpenAPI Agent instance |
## SQL Agent
This component creates a SQL Agent to interact with SQL databases.
### Parameters
#### Inputs
| Name | Type | Description |
|------|------|-------------|
| llm | LanguageModel | Language model to use for the agent |
| database_uri | String | URI of the SQL database to connect to |
| extra_tools | List[Tool] | Additional tools to provide to the agent (optional) |
#### Outputs
| Name | Type | Description |
|------|------|-------------|
| agent | AgentExecutor | SQL Agent instance |
## Sequential Crew
This component represents a group of agents with tasks that are executed sequentially. This component allows for the creation of a crew that performs tasks in a specific order.
For more information, see the [CrewAI documentation](https://docs.crewai.com/how-to/Sequential/).
### Parameters
#### Inputs
| Name | Display Name | Info |
|------|--------------|------|
| tasks | Tasks | List of SequentialTask objects representing the tasks to be executed |
| verbose | Verbose | Enables verbose output for detailed logging |
| memory | Memory | Specifies the memory configuration for the crew |
| use_cache | Use Cache | Enables caching of results |
| max_rpm | Max RPM | Sets the maximum requests per minute |
| share_crew | Share Crew | Determines if the crew information is shared among agents |
| function_calling_llm | Function Calling LLM | Specifies the language model for function calling |
#### Outputs
| Name | Display Name | Info |
|------|--------------|------|
| crew | Crew | The constructed Crew object with sequential task execution |
## Sequential task agent
This component creates a CrewAI Task and its associated Agent, allowing for the definition of sequential tasks with specific agent roles and capabilities.
For more information, see the [CrewAI documentation](https://docs.crewai.com/how-to/Sequential/).
### Parameters
#### Inputs
| Name | Display Name | Info |
|------|--------------|------|
| role | Role | The role of the agent |
| goal | Goal | The objective of the agent |
| backstory | Backstory | The backstory of the agent |
| tools | Tools | Tools at agent's disposal |
| llm | Language Model | Language model that will run the agent |
| memory | Memory | Whether the agent should have memory or not |
| verbose | Verbose | Enables verbose output |
| allow_delegation | Allow Delegation | Whether the agent is allowed to delegate tasks to other agents |
| allow_code_execution | Allow Code Execution | Whether the agent is allowed to execute code |
| agent_kwargs | Agent kwargs | Additional kwargs for the agent |
| task_description | Task Description | Descriptive text detailing task's purpose and execution |
| expected_output | Expected Task Output | Clear definition of expected task outcome |
| async_execution | Async Execution | Boolean flag indicating asynchronous task execution |
| previous_task | Previous Task | The previous task in the sequence (for chaining) |
#### Outputs
| Name | Display Name | Info |
|------|--------------|------|
| task_output | Sequential Task | List of SequentialTask objects representing the created task(s) |
## Tool Calling Agent
This component creates a Tool Calling Agent using LangChain.
### Parameters
#### Inputs
| Name | Type | Description |
|------|------|-------------|
| llm | LanguageModel | Language model to use for the agent |
| system_prompt | String | System prompt for the agent |
| user_prompt | String | User prompt template (must contain 'input' key) |
| chat_history | List[Data] | Optional chat history for the agent |
| tools | List[Tool] | List of tools available to the agent |
#### Outputs
| Name | Type | Description |
|------|------|-------------|
| agent | AgentExecutor | Tool Calling Agent instance |
## Vector Store Agent
This component creates a Vector Store Agent using LangChain.
### Parameters
#### Inputs
| Name | Type | Description |
|------|------|-------------|
| llm | LanguageModel | Language model to use for the agent |
| vectorstore | VectorStoreInfo | Vector store information for the agent to use |
#### Outputs
| Name | Type | Description |
|------|------|-------------|
| agent | AgentExecutor | Vector Store Agent instance |
## Vector Store Router Agent
This component creates a Vector Store Router Agent using LangChain.
### Parameters
#### Inputs
| Name | Type | Description |
|------|------|-------------|
| llm | LanguageModel | Language model to use for the agent |
| vectorstores | List[VectorStoreInfo] | List of vector store information for the agent to route between |
#### Outputs
| Name | Type | Description |
|------|------|-------------|
| agent | AgentExecutor | Vector Store Router Agent instance |
## XML Agent
This component creates an XML Agent using LangChain.
The agent uses XML formatting for tool instructions to the Language Model.
### Parameters
#### Inputs
| Name | Type | Description |
|------|------|-------------|
| llm | LanguageModel | Language model to use for the agent |
| user_prompt | String | Custom prompt template for the agent (includes XML formatting instructions) |
| tools | List[Tool] | List of tools available to the agent |
#### Outputs
| Name | Type | Description |
|------|------|-------------|
| agent | AgentExecutor | XML Agent instance |

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 KiB

View file

@ -0,0 +1,49 @@
# Dynamic Agent
Build a **Dynamic Agent** flow for an agentic application using the CrewAI.
An **agent** uses an LLM as its "brain" to reason through tasks and select among the connected tools to complete them.
This flow uses [CrewAI](https://docs.crewai.com/) to manage a [Hierarchical crew](https://docs.crewai.com/how-to/Hierarchical/) of **Agents** as they perform a sequence of **Tasks**.
CrewAI agents have **Roles**, **Goals**, and **Backstories** that define their behavior and interactions with other agents. Agents in a Hierarchical Crew are managed by a single agent with a **Manager** role, which is connected to an **Open AI** LLM component to reason through the tasks and select the appropriate tools to complete them.
This flow is "dynamic" because it uses the **Chat input** component's text to define a CrewAI agent's Role, Goal, and Backstory. The created agent then uses the connected tools to research and complete the **Task** created from the **Chat input** component.
## Prerequisites
To use this flow, you need an [OpenAI API key](https://platform.openai.com/) and a [Search API key](https://www.searchapi.io/).
## Open Langflow and start a new project
Click **New Project**, and then select the **Dynamic Agent** project.
This opens a starter project with the necessary components to run an agentic application using CrewAI.
The **Dynamic Agent** flow consists of these components:
* The **Chat Input** component accepts user input to the chat.
* The **Prompt** component combines the user input with a user-defined prompt.
* The **OpenAI** model component sends the user input and prompt to the OpenAI API and receives a response.
* The **Chat Output** component prints the flow's output to the chat.
* The **CrewAI Agent** component is an autonomous unit programmed to perform tasks, make decisions, and communicate with other agents.
* The **Crew AI Crew** component represents a collaborative group of agents working together to achieve a set of tasks. This Crew can manage work **sequentially** or **hierarchically**.
* The **Crew AI Task** component is a specific assignment to be completed by agents.
This task can be **sequential** or **hierarchical** depending on the Crew's configuration.
* The **SearchAPI** tool performs web searches using the **SearchAPI.io** API.
* The **Yahoo Finance News Tool** component creates a tool for retrieving news from Yahoo Finance.
## Run the Dynamic Agent flow
1. Add your credentials to the OpenAI and SearchAPI components using Langflow's Global Variables:
- Click **Settings**, then **Global Variables**.
- Click **Add New**.
- Name your variable and paste your API key in the **Value** field.
- In the **Apply To Fields** field, select the field to apply this variable to.
- Click **Save Variable**.
2. In the **Chat output** component, click ▶️ Play to start the end-to-end application flow.
A **Chat output built successfully** message and a ✅ Check on all components indicate that the flow ran successfully.
3. Click **Playground** to start a chat session.
You should receive a detailed, helpful answer to the question defined in the **Chat input** component.
Now that your query has completed the journey from **Chat input** to **Chat output**, you have completed the **Dynamic Agent** flow.

View file

@ -0,0 +1,54 @@
# Simple Agent
Build a **Simple Agent** flow for an agentic application using the Tool-calling agent.
An **agent** uses an LLM as its "brain" to select among the connected tools and complete its tasks.
In this flow, the **Tool-calling agent** reasons using an **Open AI** LLM to solve math problems. It will select the **Calculator** tool for simpler math, and the **Python REPL** tool (with the Python `math` library) for more complex problems.
## Prerequisites
To use this flow, you need an OpenAI API key.
## Open Langflow and start a new project
Click **New Project**, and then select the **Simple Agent** project.
This opens a starter project with the necessary components to run an agentic application using the Tool-calling agent.
## Simple Agent flow
![](./starter-flow-simple-agent.png)
The **Simple Agent** flow consists of these components:
* The **Tool calling agent** component uses the connected LLM to reason through the user's input and select among the connected tools to complete its task.
* The **Python REPL tool** component executes Python code in a REPL (Read-Evaluate-Print Loop) interpreter.
* The **Calculator** component performs basic arithmetic operations.
* The **Chat Input** component accepts user input to the chat.
* The **Prompt** component combines the user input with a user-defined prompt.
* The **Chat Output** component prints the flow's output to the chat.
* The **OpenAI** model component sends the user input and prompt to the OpenAI API and receives a response.
## Run the Simple Agent flow
1. Add your credentials to the Open AI component.
2. In the **Chat output** component, click ▶️ Play to start the end-to-end application flow.
A **Chat output built successfully** message and a ✅ Check on all components indicate that the flow ran successfully.
3. Click **Playground** to start a chat session.
4. Enter a simple math problem, like `2 + 2`, and then make sure the bot responds with the correct answer.
5. To confirm the REPL interpreter is working, prompt the `math` library directly with `math.sqrt(4)` and see if the bot responds with `4`.
6. The agent will also reason through more complex word problems. For example, prompt the agent with the following math problem:
```plain
The equation 24x2+25x47ax2=8x353ax2 is true for all values of x≠2a, where a is a constant.
What is the value of a?
A) -16
B) -3
C) 3
D) 16
```
The agent should respond with `B`.
Now that your query has completed the journey from **Chat input** to **Chat output**, you have completed the **Simple Agent** flow.

View file

@ -0,0 +1,44 @@
# Travel Planning Agent
Build a **Travel Planning Agent** flow for an agentic application using the multiple Tool-calling agents.
An **agent** uses an LLM as its "brain" to select among the connected tools and complete its tasks.
In this flow, multiple **Tool-calling agents** reason using an **Open AI** LLM to plan a travel journey. Each agent is given a different responsibility defined by its **System Prompt** field.
The **Chat input** defines where the user wants to go, and passes the result to the **City Selection** agent. The **Local Expert** agent then adds information based on the selected cities, and the **Travel Concierge** assembles a seven day travel plan in Markdown.
All agents have access to the **Search API** and **URL Content Fetcher** components, while only the Travel Concierge can use the **Calculator** for computing the trip costs.
## Prerequisites
To use this flow, you need an [OpenAI API key](https://platform.openai.com/) and a [Search API key](https://www.searchapi.io/).
## Open Langflow and start a new project
Click **New Project**, and then select the **Travel Planning Agent** project.
This opens a starter project with the necessary components to run an agentic application using multiple Tool-calling agents.
## Travel Planning Agent flow
![](./starter-flow-travel-planning-agent.png)
The **Travel Planning Agent** flow consists of these components:
* Multiple **Tool calling agent** components that use the connected LLM to reason through the user's input and select among the connected tools to complete their tasks.
* The **Calculator** component performs basic arithmetic operations.
* The **URL Content Fetcher** component scrapes content from a given URL.
* The **Chat Input** component accepts user input to the chat.
* The **Chat Output** component prints the flow's output to the chat.
* The **OpenAI** model component sends the user input and prompt to the OpenAI API and receives a response.
## Run the Travel Planning Agent flow
1. Add your credentials to the Open AI and Search API components.
2. In the **Chat output** component, click ▶️ Play to start the end-to-end application flow.
A **Chat output built successfully** message and a ✅ Check on all components indicate that the flow ran successfully.
3. Click **Playground** to start a chat session.
You should receive a detailed, helpful answer to the journey defined in the **Chat input** component.
Now that your query has completed the journey from **Chat input** to **Chat output**, you have completed the **Travel Planning Agent** flow.