Itinai.com llm large language model structure neural network f4a47649 bac3 4c47 9657 40c8c084d268 2
Itinai.com llm large language model structure neural network f4a47649 bac3 4c47 9657 40c8c084d268 2

Creating an AI Agent-Based System with LangGraph: Putting a Human in the Loop

Creating an AI Agent-Based System with LangGraph: Putting a Human in the Loop

Creating an AI Agent with Human Oversight

Introduction

In this tutorial, we will enhance our AI agent by adding a human oversight feature. This allows a person to monitor and approve the agent’s actions using LangGraph. Let’s see how we can implement this.

Setting Up the Agent

We will start from our previous setup. First, we need to install the necessary packages and set up our environment.

Installation Commands:

  • Install required libraries:
  • pip install langgraph==0.2.53 langgraph-checkpoint==2.0.6 langgraph-sdk==0.1.36 langchain-groq langchain-community langgraph-checkpoint-sqlite==2.0.1

Environment Variables:

  • Set your API keys:
  • os.environ['TAVILY_API_KEY'] = "<TAVILY_API_KEY>"
  • os.environ['GROQ_API_KEY'] = "<GROQ_API_KEY>"

Defining the Agent

We will create an agent class that handles messages and actions. This class will include:

  • Calling the OpenAI model for responses.
  • Checking for actions that need to be taken.
  • Executing those actions using specified tools.

Setting Up the Agent State

We will modify how messages are stored in the agent’s state. This allows us to replace messages with the same ID instead of just adding new ones.

Adding a Human in the Loop

To ensure human oversight, we will add a parameter that requires manual approval before the agent takes any action. This makes sure that a human can review decisions before they are executed.

Running the Agent

We will initialize the agent with a prompt and run it to see how it operates. The agent will respond to queries and pause for human approval before executing any actions.

Interactive Human Approval

We will implement a loop that prompts the user for approval before continuing. If the user decides not to proceed, the agent will stop its actions.

Conclusion

You can now involve a human in the decision-making process of your AI agent. Experiment with different settings to see how the agent behaves with human oversight.

Get Started with AI

If you want to integrate AI into your business, consider these steps:

  • Identify Automation Opportunities: Find areas that can benefit from AI.
  • Define KPIs: Measure the impact of your AI initiatives.
  • Select an AI Solution: Choose tools that fit your needs.
  • Implement Gradually: Start small, gather data, and expand.

For AI management advice, contact us at hello@itinai.com. For ongoing insights, follow us on Telegram t.me/itinainews or Twitter @itinaicom.

Discover how AI can transform your business processes at itinai.com.

List of Useful Links:

Itinai.com office ai background high tech quantum computing 0002ba7c e3d6 4fd7 abd6 cfe4e5f08aeb 0

Vladimir Dyachkov, Ph.D
Editor-in-Chief itinai.com

I believe that AI is only as powerful as the human insight guiding it.

Unleash Your Creative Potential with AI Agents

Competitors are already using AI Agents

Business Problems We Solve

  • Automation of internal processes.
  • Optimizing AI costs without huge budgets.
  • Training staff, developing custom courses for business needs
  • Integrating AI into client work, automating first lines of contact

Large and Medium Businesses

Startups

Offline Business

100% of clients report increased productivity and reduced operati

AI news and solutions