Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CrewAI Component Documentation #2519

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions docs/docs/integrations/crewai/agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import Admonition from "@theme/Admonition";
import ThemedImage from "@theme/ThemedImage";
import useBaseUrl from "@docusaurus/useBaseUrl";
import ZoomableImage from "/src/theme/ZoomableImage.js";

# Agent Component

The `CrewAIAgent` component represents an agent of CrewAI. It provides a convenient way to integrate CrewAI agent data into your Langflow workflows.

[CrewAI Reference](https://docs.crewai.com/how-to/LLM-Connections/)

The `CrewAIAgent` component enables you to:

- Define the role, goal, and backstory of the agent
- Specify tools and language models for the agent
- Configure advanced settings such as memory, verbosity, and delegation

## Component Usage

To use the `CrewAIAgent` component in a Langflow flow, follow these steps:

1. Add the `CrewAIAgent` component to your flow.
2. Configure the component by providing the required inputs such as role, goal, and backstory.
3. Connect the component to other nodes in your flow as needed.

## Component Python code

```python
from langflow.custom import Component
from langflow.io import MessageTextInput, Output
from langflow.schema import Data
from langflow.io import BoolInput, DictInput, DropdownInput, MessageTextInput, HandleInput
from crewai import Agent


class CrewAIAgent(Component):
display_name = "CrewAIAgent"
description = "Represents an agent of CrewAI."
documentation: str = "https://docs.crewai.com/how-to/LLM-Connections/"
icon = "CrewAI"

inputs = [
MessageTextInput(name="role", display_name="Role", info="The role of the agent."),
MessageTextInput(name="goal", display_name="Goal", info="The objective of the agent."),
MessageTextInput(name="backstory", display_name="Backstory", info="The backstory of the agent."),
HandleInput(
name="tools",
display_name="Tools",
input_types=["Tool"],
is_list=True,
info="Tools at agents disposal",
value=[],
),
HandleInput(
name="llm",
display_name="Language Model",
info="Language model that will run the agent.",
input_types=["LanguageModel"],
),
BoolInput(
name="memory",
display_name="Memory",
info="Whether the agent should have memory or not",
advanced=True,
value=True,
),
BoolInput(
name="verbose",
display_name="Verbose",
advanced=True,
value=False,
),
BoolInput(
name="allow_delegation",
display_name="Allow Delegation",
info="Whether the agent is allowed to delegate tasks to other agents.",
value=True,
),
DictInput(
name="kwargs",
display_name="kwargs",
info="kwargs of agent.",
is_list=True,
advanced=True,
),
]

outputs = [
Output(display_name="Output", name="output", method="build_output"),
]


def build_output(self) -> Agent:
kwargs = self.kwargs if self.kwargs else {}
agent = Agent(
role=self.role,
goal=self.goal,
backstory=self.backstory,
llm=self.llm,
verbose=self.verbose,
memory=self.memory,
tools=self.tools if self.tools else [],
allow_delegation=self.allow_delegation,
**kwargs
)
self.status = agent
return agent

```

## Example Usage

Here's an example of how to use the `CrewAIAgent` component in a Langflow flow, connecting the `OpenAI` component's output to the CrewAIAgent component.

<ZoomableImage
alt="CrewAIAgent Flow Example"
sources={{
light: "img/crewai/CrewAIAgent_flow_example.png",
dark: "img/crewai/CrewAIAgent_flow_example_dark.png",
}}
style={{ width: "100%", margin: "20px 0" }}
/>

## Best Practices

When using the `CrewAIAgent` component, consider the following best practices:

- Ensure that you have configured the agent's role, goal, and backstory appropriately.

The `CrewAIAgent` component provides a seamless way to integrate CrewAI agent data into your Langflow workflows. By leveraging this component, you can easily define and utilize agent information from CrewAI, enhancing the capabilities of your Langflow applications. Feel free to explore and experiment with the `CrewAIAgent` component to unlock new possibilities in your Langflow projects!

## Troubleshooting

If you encounter any issues while using the `CrewAIAgent` component, consider the following:

- Double-check that your inputs such as role, goal, and backstory are correctly configured.
- Verify that you have installed the necessary dependencies for the component to function properly.
- Check the CrewAI documentation for any updates or changes that may affect the component's functionality.
104 changes: 104 additions & 0 deletions docs/docs/integrations/crewai/crew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import Admonition from "@theme/Admonition";
import ThemedImage from "@theme/ThemedImage";
import useBaseUrl from "@docusaurus/useBaseUrl";
import ZoomableImage from "/src/theme/ZoomableImage.js";

# Crew Component

The `CrewAICrew` component represents a group of agents in CrewAI. It defines how agents collaborate and the tasks they perform, integrating seamlessly into your Langflow workflows.

[CrewAI Reference](https://docs.crewai.com/how-to/LLM-Connections/)

The `CrewAICrew` component enables you to:

- Define tasks and assign agents
- Specify the topic and collaboration process
- Configure advanced settings such as verbosity, memory, cache usage, and maximum RPM

## Component Usage

To use the `CrewAICrew` component in a Langflow flow, follow these steps:

1. Add the `CrewAICrew` component to your flow.
2. Configure the component by providing the required inputs such as tasks, agents, and topic.
3. Connect the component to other nodes in your flow as needed.

## Component Python code

```python
from langflow.custom import Component
from crewai import Crew, Task, Agent, Process
from typing import List, Optional
from langflow.field_typing import Text
from langflow.io import NestedDictInput, DropdownInput, MessageTextInput, HandleInput, IntInput, BoolInput
from langflow.schema.message import Message

class CrewAICrew(Component):
display_name: str = "CrewAICrew"
description: str = "Represents a group of agents, defining how they should collaborate and the tasks they should perform."
documentation: str = "https://docs.crewai.com/how-to/LLM-Connections/"
icon = "CrewAI"

inputs = [
HandleInput(name="tasks", display_name="Tasks", input_types=["Task"], is_list=True),
HandleInput(name="agents", display_name="Agents", input_types=["Agent"], is_list=True),
MessageTextInput(name="topic", display_name="Topic"),
IntInput(name="verbose", display_name="Verbose", value=0, advanced=True),
BoolInput(name="memory", display_name="Memory", value=False, advanced=True),
BoolInput(name="use_cache", display_name="Cache", value=True, advanced=True),
IntInput(name="max_rpm", display_name="Max RPM", value=100, advanced=True),
DropdownInput(name="process", display_name="Process", value=Process.sequential, options=[Process.sequential, Process.hierarchical]),
BoolInput(name="share_crew", display_name="Share Crew", value=False, advanced=True),
NestedDictInput(name="input", display_name="Input", value={"topic": ""}, is_list=True)
]

outputs = [
Output(display_name="Output", name="output", method="build_output"),
]

async def build_output(self) -> Message:
if not self.agents or not self.tasks:
raise ValueError("No agents or tasks have been added.")

response = Crew(
agents=self.agents,
tasks=self.tasks,
process=self.process,
verbose=self.verbose,
memory=self.memory,
cache=self.use_cache,
max_rpm=self.max_rpm,
share_crew=self.share_crew,
)
message = await response.kickoff_async(inputs=self.input)
self.status = message
return message
```

Example Usage
Here's an example of how you can use the `CrewAICrew` component in a Langflow flow, connecting the CrewAIAgent component to the `CrewAITask`, `CrewAIAgent`, and `Chat Input`component, and then passing the output Chat Output component:

<ZoomableImage
alt="CrewAICrew Flow Example"
sources={{
light: "img/crewai/CrewAICrew_flow_example.png",
dark: "img/crewai/CrewAICrew_flow_example_dark.png",
}}
style={{ width: "100%", margin: "20px 0" }}
/>

## Best Practices

When using the `CrewAICrew` component, consider the following best practices:

Clearly define the tasks and assign the appropriate agents.
Configure the collaboration process and advanced settings according to your needs.
The `CrewAICrew` component provides a streamlined way to manage groups of agents and their tasks within your Langflow workflows. By leveraging this component, you can effectively organize and automate agent collaboration, enhancing the efficiency of your Langflow projects. Feel free to explore and experiment with the `CrewAICrew` component to unlock new possibilities in your Langflow projects!

## Troubleshooting

If you encounter any issues while using the `CrewAICrew` component, consider the following:

- Double-check that your inputs such as tasks and agents are correctly configured.
- Verify that you have installed the necessary dependencies for the component to function properly.
- Check the CrewAI documentation for any updates or changes that may affect the component's functionality.
41 changes: 41 additions & 0 deletions docs/docs/integrations/crewai/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Admonition from "@theme/Admonition";
import ThemedImage from "@theme/ThemedImage";
import useBaseUrl from "@docusaurus/useBaseUrl";
import ZoomableImage from "/src/theme/ZoomableImage.js";

# Introduction to CrewAI in Langflow

The CrewAI integration in Langflow enables seamless connectivity with CrewAI components, facilitating automation and improving productivity.

<ZoomableImage
alt="CrewAI Components in Langflow"
sources={{
light: "img/crewai/crewai_bundle.jpg",
dark: "img/crewai/crewai_bundle.jpg",
}}
style={{ width: "100%", margin: "20px 0" }}
/>

#### <a target="\_blank" href="json_files/CrewAI_Components_bundle.json" download>Download CrewAI Components Bundle</a>

### Key Features of CrewAI Integration in Langflow

- **Manage Agents**: Define and manage a group of agents, specifying their tasks and collaboration methods.
- **Task Automation**: Automate task creation and management using CrewAI's capabilities.
- **Process Management**: Define and manage processes for task execution and agent collaboration.

### Potential Use Cases for CrewAI Integration in Langflow

- **Task Automation**: Automate task creation and management using CrewAI's AI capabilities.
- **Agent Collaboration**: Define and manage how agents should collaborate on tasks.
- **Process Management**: Automate and manage processes for task execution and agent collaboration.

### Getting Started with CrewAI Integration in Langflow

1. **Learn about CrewAI Components**: Follow the guide [Understanding CrewAI Components](./setup) to learn how to use CrewAI components effectively.
2. **Configure CrewAI Components**: Provide the necessary parameters to configure the CrewAI components in your Langflow flows.
3. **Connect Components**: Integrate CrewAI components with other Langflow components to build your workflow.
4. **Test and Refine**: Ensure your Langflow flow operates as intended by testing and refining it.
5. **Deploy and Run**: Deploy your Langflow flow to automate CrewAI-related tasks and processes.

The CrewAI integration in Langflow offers a powerful toolset for automation and productivity enhancement. Whether managing tasks, defining agent collaboration, or managing processes, Langflow and CrewAI provide robust solutions for streamlining workflows.
27 changes: 27 additions & 0 deletions docs/docs/integrations/crewai/setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Admonition from "@theme/Admonition";

# Using CrewAI Components in Langflow

Langflow provides the following CrewAI components:

- **[CrewAIAgent](./agent)**: Represents an agent of CrewAI.
- **[CrewAITask](./task)**: Each task must have a description, an expected output, and an agent responsible for execution.
- **[CrewAICrew](./crew)**: Represents a group of agents, defining how they should collaborate and the tasks they should perform.

Refer to the individual component documentation for more details on how to use each component in your Langflow flows.

## Components Compatibility

- **CrewAIAgent**:
- Compatible with CrewAITask and CrewAICrew components.
- **CrewAITask**:
- Compatible with CrewAIAgent and CrewAICrew components.
- **CrewAICrew**:
- Compatible with CrewAIAgent and CrewAITask components.

## Additional Resources

- [CrewAI API Documentation](https://docs.crewai.com/how-to/Creating-a-Crew-and-kick-it-off/)
- [CrewAI Examples](https://github.com/joaomdmoura/crewAI-examples/tree/main)

If you encounter any issues or have questions, please reach out to our support team or consult the Langflow community forums.
Loading
Loading