How to Build Human-in-the-Loop Plan-and-Execute AI Agents with Explicit User Approval Using LangGraph and Streamlit


app_code = r'''
import os, json, uuid
import streamlit as st
from typing import TypedDict, List, Dict, Any, Optional
from pydantic import BaseModel, Field
from openai import OpenAI


from langgraph.graph import StateGraph, START, END
from langgraph.types import Command, interrupt
from langgraph.checkpoint.memory import InMemorySaver




def tool_search_flights(origin: str, destination: str, depart_date: str, return_date: str, budget_usd: int) -> Dict[str, Any]:
   options = [
       {"airline": "SkyJet", "route": f"{origin}->{destination}", "depart": depart_date, "return": return_date, "price_usd": int(budget_usd*0.55)},
       {"airline": "AeroBlue", "route": f"{origin}->{destination}", "depart": depart_date, "return": return_date, "price_usd": int(budget_usd*0.70)},
       {"airline": "Nimbus Air", "route": f"{origin}->{destination}", "depart": depart_date, "return": return_date, "price_usd": int(budget_usd*0.62)},
   ]
   options = sorted(options, key=lambda x: x["price_usd"])
   return {"tool": "search_flights", "top_options": options[:2]}


def tool_search_hotels(city: str, nights: int, budget_usd: int, preferences: List[str]) -> Dict[str, Any]:
   base = max(60, int(budget_usd / max(nights, 1)))
   picks = [
       {"name": "Central Boutique", "city": city, "nightly_usd": int(base*0.95), "notes": ["walkable", "great reviews"]},
       {"name": "Riverside Stay", "city": city, "nightly_usd": int(base*0.80), "notes": ["quiet", "good value"]},
       {"name": "Modern Loft Hotel", "city": city, "nightly_usd": int(base*1.10), "notes": ["new", "gym"]},
   ]
   if "luxury" in [p.lower() for p in preferences]:
       picks = sorted(picks, key=lambda x: -x["nightly_usd"])
   else:
       picks = sorted(picks, key=lambda x: x["nightly_usd"])
   return {"tool": "search_hotels", "top_options": picks[:2]}


def tool_build_day_by_day(city: str, days: int, vibe: str) -> Dict[str, Any]:
   blocks = []
   for d in range(1, days+1):
       blocks.append({
           "day": d,
           "morning": f"{city}: coffee + a must-see landmark",
           "afternoon": f"{city}: {vibe} activity + local lunch",
           "evening": f"{city}: sunset spot + dinner + optional night walk"
       })
   return {"tool": "draft_itinerary", "days": blocks}
'''



Source link

  • Related Posts

    Alibaba Qwen Team Releases Qwen3.5-397B MoE Model with 17B Active Parameters and 1M Token Context for AI agents

    Alibaba Cloud just updated the open-source landscape. Today, the Qwen team released Qwen3.5, the newest generation of their large language model (LLM) family. The most powerful version is Qwen3.5-397B-A17B. This…

    Google DeepMind Proposes New Framework for Intelligent AI Delegation to Secure the Emerging Agentic Web for Future Economies

    The AI industry is currently obsessed with ‘agents’—autonomous programs that do more than just chat. However, most current multi-agent systems rely on brittle, hard-coded heuristics that fail when the environment…

    Leave a Reply

    Your email address will not be published. Required fields are marked *