Build Agentic Workflow using OpenAGI and HuggingFace models

Community Article Published June 26, 2024

Overview

At AI Planet, we created OpenAGI to democratize access to human-like agents, aiming to solve real-life problems through AI. OpenAGI provides a flexible framework for developers to build autonomous agents that plan, reason, and act independently, offering more than traditional LLM applications.

Key Features

  1. Flexible Agent Architecture: Supports sequential, parallel, and dynamic communication patterns.
  2. Streamlined Integration: Simplifies the setup process, overcoming common obstacles in agent development.
  3. Automated & Manual Configuration: Offers both automatic and manual configuration options for detailed customization.

Applications

  • Education: Personalized learning experiences and administrative task automation.
  • Finance: Fraud detection, risk assessment, personalized advice, and trading automation.
  • Healthcare: Patient monitoring, health recommendations, data management, and disease diagnosis.

Future Scope

We are enhancing agents to improve through experience and feedback, aiming for specialized agents that excel at specific tasks over time, such as expert front-end developers.

Comparison: LLMs vs. Agents

Feature LLM Applications Agents/Assistants
Core Function Synthesizing information Autonomous planning and decision-making
Learning Method Supervised/unsupervised from datasets Continual learning from new experiences
Decision Making Based on data patterns Complex, ethical, and long-term decision-making
Autonomy Limited by programming High autonomy, goal-setting
Physical Interaction None, digital tasks Physical world interaction

Workers, Agents, and Planners

Worker

Workers are specialized classes that carry out tasks assigned by Admin. They utilize tools like LLMs, search engines, and document writers to complete their tasks.Let’s start by installing the framework and importing the necessary modules. Next, we’ll set up the environment variables required to configure the large language model.

pip install openagi
from openagi.actions.files import WriteFileAction
from openagi.actions.tools.ddg_search import DuckDuckGoNewsSearch
from openagi.actions.tools.webloader import WebBaseContextTool
from openagi.agent import Admin
from openagi.memory import Memory
from openagi.planner.task_decomposer import TaskPlanner
from openagi.worker import Worker
from openagi.llms.hf import HuggingFaceModel
import os

os.environ["HUGGINGFACE_ACCESS_TOKEN"] = "<your-hf-access-token>"

config =HuggingFaceModel.load_from_env_config()
llm =HuggingFaceModel(config=config)

We define the role of each worker to establish their responsibilities. Additionally, we provide instructions, which describe how the LLM should behave in its role. These instructions can also include backstory and other relevant details to aid in generating the desired output.

# define the role and instructions to each worker in granular 

researcher = Worker(
    role="Researcher",
    instructions="sample instruction.", #replace with your detailed instruction based on use case
    actions=[
        DuckDuckGoNewsSearch,
        WebBaseContextTool,
    ],
)
writer = Worker(
    role="Writer",
    instructions="sample instruction.", #replace with your detailed instruction based on use case
    actions=[
        DuckDuckGoNewsSearch,
        WebBaseContextTool,
    ],
)
reviewer = Worker(
    role="Reviewer",
    instructions="sample instruction.", #replace with your detailed instruction based on use case
    actions=[
        DuckDuckGoNewsSearch,
        WebBaseContextTool,
        WriteFileAction,
    ],
)

Admin (Agent)

The Admin class is the central component in OpenAGI, responsible for planning and executing tasks. It uses LLMs, memory, and various actions to perform tasks autonomously. The primary components,TaskWorker, provide a structured way to define and execute tasks. The TaskWorker class specializes in executing specific tasks assigned by the planner.Assign the Workers to the Admin in the order and then run the Admin object.

# define the Admin with Planner, Memory and LLM. Further assign the workers in order
admin = Admin(
    planner=TaskPlanner(human_intervene=False),
    memory=Memory(),
    llm=llm,
)

# Assign sub-tasks to workers
admin.assign_workers([researcher, writer, reviewer])

res = admin.run(
    query="Write a blog post.",
    description="sample description.", #replace with your detailed description based on use case
)

Co-author: Shivaya Pandey

Join the Community

Eager to explore OpenAGI and contribute to the project?

Explore the GitHub repo:

GitHub

Also, feel free to open issues, make pull requests to contribute, and don’t forget to ⭐️ the repo to stay updated with the latest developments.

OpenAGI documentation:

OpenAGI

By collaborating with the community, we can continue to improve OpenAGI and drive innovation in the AI field.

You can reach out to us on the Discord:

Join the AI Planet Discord Server!