Integrating Langfuse with IPFLY-Powered AI Agents for Enterprise Observability Enhanced Enterprise AI Observability via Langfuse and IPFLY Integration

Langfuse is an open-source LLM engineering platform that offers observability, tracing, and monitoring capabilities for AI agents. This is crucial for enterprise-grade use cases, particularly those involving compliance tracking, where reliability and transparency are non-negotiable.

When building compliance-focused AI agents using LangChain, the biggest challenge lies in gaining unrestricted access to authoritative web data, such as regulatory updates and government guidelines.

Integrating Langfuse into an IPFLY-powered AI Agent for Enterprise Observability
Integrating Langfuse into an IPFLY-powered AI Agent for Enterprise Observability

Introducing Langfuse, AI Agent Observability, and the Role of IPFLY

Enterprise-level AI agents, especially those designed for compliance tracking, rely on two critical pillars: accurate web data for staying updated with regulations like GDPR and CCPA, and complete observability to validate decisions, track costs, and ensure adherence to compliance standards.

Langfuse: Provides end-to-end tracing, metrics, and debugging for LLM applications. It enables teams to monitor every step of an AI agent’s workflow, from prompts to tool calls and responses, ensuring full visibility.

LangChain: Orchestrates the AI agent’s logic, connecting LLMs to external tools such as web scrapers to retrieve data. LangChain acts as the central framework for managing the agent’s operations.

IPFLY: Eliminates web data access bottlenecks with proxy solutions designed for AI. It offers a network of over 90 million global IPs across 190+ countries, including static/dynamic residential proxies and datacenter proxies. These features enable:

  • Dynamic Residential Proxies: Mimic real user behavior to avoid detection and blocking, ensuring consistent data retrieval.
  • Static Residential Proxies: Provide continuous access to trusted regulatory websites, guaranteeing reliable data sources.
  • Datacenter Proxies: Handle large-scale crawling tasks efficiently, facilitating comprehensive data collection.

IPFLY’s global coverage allows for accessing region-specific compliance data, ensuring comprehensive regulatory adherence.

Together, these tools create an enterprise-grade tech stack: IPFLY equips the agent with high-quality web data, LangChain manages the workflow, and Langfuse ensures complete visibility into performance and reliability.

Why Integrate Langfuse into Your AI Agent?

AI agents used for compliance interact with sensitive documents, external web data, and complex regulatory rules. Blind spots in these interactions can lead to costly errors or non-compliance. Langfuse addresses this issue by:

  • Providing End-to-End Tracing: Monitoring every tool call (e.g., IPFLY web scraper) and data source to validate insights and ensure data accuracy.
  • Tracking Key Metrics: Measuring latency, LLM costs, and web crawling success rates, which are crucial for optimizing IPFLY proxy usage and overall efficiency.
  • Enabling Rapid Debugging: Identifying failed crawls, outdated prompts, or LLM hallucinations through detailed logging, allowing for quick resolution of issues.
  • Supporting Compliance: Creating an immutable record of agent behavior for auditing purposes, ensuring transparency and accountability.

When paired with IPFLY, Langfuse not only ensures your agent functions correctly but also demonstrates that it operates in a reliable and compliant manner.

How to Track a Compliance AI Agent with Langfuse (LangChain + IPFLY)

We will build an enterprise-grade compliance AI agent that can:

  1. Load internal PDF documents (e.g., data processing workflows) for analysis.
  2. Analyze the PDF to identify privacy and regulatory risks.
  3. Use IPFLY proxies to search for the latest regulations (SERP data) and scrape authoritative sources (government websites).
  4. Generate a compliance report that includes references from both internal documents and web data.
  5. Integrate Langfuse for complete workflow tracking, ensuring visibility at every step.

Prerequisites

Before starting, ensure you have the following:

  • Python 3.10 or higher installed.
  • An OpenAI API key (or API key for another LLM provider).
  • An IPFLY account with an API key and access to dynamic residential proxies.
  • A Langfuse account with configured public and secret API keys.
  • Basic familiarity with LangChain and Python programming.

Step #1: Set Up Your LangChain AI Agent Project

Create a project directory and a virtual environment:


mkdir compliance-ai-agent-ipfly-langfuse
cd compliance-ai-agent-ipfly-langfuse
python -m venv .venv
# Activate: macOS/Linux → source .venv/bin/activate; Windows → .venv\Scripts\activate
pip install langchain langchain-openai langgraph langchain-community pypdf python-dotenv langfuse requests

Create two files: agent.py (for core logic) and .env (for credentials):


compliance-ai-agent-ipfly-langfuse/
├── .venv/
├── agent.py
└── .env

Step #2: Configure Environment Variable Reading

In agent.py, load environment variables to securely store sensitive credentials:


from dotenv import load_dotenv
load_dotenv()  # Load variables from the .env file

Add your credentials to the .env file. We will populate the IPFLY, Langfuse, and OpenAI keys in subsequent steps:


OPENAI_API_KEY=""
IPFLY_API_KEY=""
IPFLY_PROXY_ENDPOINT="http://[USERNAME]:[PASSWORD]@proxy.ipfly.com:8080"
LANGFUSE_SECRET_KEY=""
LANGFUSE_PUBLIC_KEY=""
LANGFUSE_BASE_URL=""

Step #3: Prepare Your IPFLY Account

IPFLY powers the AI agent’s web data collection, including SERP searches and regulatory website scraping. Here’s how to set it up:

  1. Log into your IPFLY account and generate an API key (under “Account Settings”).
  2. Note your proxy endpoint, which includes your username, password, and port (provided in the IPFLY dashboard).
  3. For compliance use cases, choose dynamic residential proxies (to avoid blocking on government/regulatory websites) or static residential proxies (for consistent access to trusted sources).

Key benefits of IPFLY in this agent:

  • 90+ Million Real User IPs: Mimic human browsing to bypass anti-bot tools and CAPTCHAs.
  • Coverage in 190+ Countries: Scrape multi-jurisdictional regulations, such as CCPA for the US and PIPEDA for Canada.
  • Multi-Layer IP Filtering: Ensures that blacklisted IPs are not used, maintaining compliance with data collection rules.
  • 99.9% Uptime: Guarantees continuous access to critical regulatory data, ensuring timely information retrieval.

Step #4: Build IPFLY Tools for LangChain

Create custom LangChain tools to handle SERP searches and web scraping using IPFLY proxies. Add the following to agent.py:


import requests
from bs4 import BeautifulSoup
from langchain.tools import Tool
import os
import json

class IPFLYSERPTool(Tool):
    """Tool for retrieving SERP data for regulatory search queries using IPFLY proxies."""

    def __init__(self):
        super().__init__(
            name="ipfly_serp_search",
            description="Searches Google for regulatory keywords (e.g., 'GDPR data retention') using IPFLY proxies. Returns the top 5 search results, prioritizing government websites.",
            func=self.run
        )
        self.proxy = os.getenv("IPFLY_PROXY_ENDPOINT")

    def run(self, query: str) -> str:
        """Executes a SERP search using IPFLY proxies."""
        params = {"q": query, "hl": "en", "gl": "us"}  # Customizable for regional regulations (e.g., "eu" for GDPR)
        headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}

        try:
            response = requests.get("https://www.google.com/search",
                params=params,
                proxies={"http": self.proxy, "https": self.proxy},
                headers=headers,
                timeout=30)
            response.raise_for_status()
            soup = BeautifulSoup(response.text, "html.parser")
            results = []

            # Extract the top 5 natural search results, prioritizing government websites
            for g in soup.find_all("div", class_="g")[:5]:
                title = g.find("h3").get_text(strip=True) if g.find("h3") else None
                url = g.find("a")["href"] if g.find("a") else None
                if title and url and ("gov" in url or "regulatory" in url):
                    results.append({"title": title, "url": url})

            return json.dumps(results, indent=2)
        except Exception as e:
            return f"SERP search failed: {str(e)}"

class IPFLYWebScraperTool(Tool):
    """Tool for scraping regulatory websites using IPFLY proxies (returns content in Markdown format)."""

    def __init__(self):
        super().__init__(
            name="ipfly_web_scraper",
            description="Scrapes regulatory websites (e.g., government sites) using IPFLY proxies. Returns clean Markdown-formatted text for LLM analysis.",
            func=self.run
        )
        self.proxy = os.getenv("IPFLY_PROXY_ENDPOINT")

    def run(self, url: str) -> str:
        """Scrapes a webpage using IPFLY proxies."""
        headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}

        try:
            response = requests.get(
                url,
                proxies={"http": self.proxy, "https": self.proxy},
                headers=headers,
                timeout=30)
            response.raise_for_status()
            soup = BeautifulSoup(response.text, "html.parser")

            # Extract main content (remove ads/navigation)
            for script in soup(["script", "style", "nav", "aside", "footer"]):
                script.decompose()

            text = soup.get_text(strip=True, separator="\n")
            lines = [line.strip() for line in text.split("\n") if line.strip()]
            markdown = "\n\n".join(lines[:50])  # Limit to 50 lines to fit LLM context

            return f"Source: {url}\n\n{markdown}"
        except Exception as e:
            return f"Web scraping failed: {str(e)}"

# Initialize IPFLY tools
ipfly_serp_tool = IPFLYSERPTool()
ipfly_scraper_tool = IPFLYWebScraperTool()

Step #5: Integrate the LLM

Add OpenAI (or your preferred LLM) to agent.py to provide analytical capabilities for the agent:


from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="gpt-5-mini",  # Replace with your LLM (e.g., gpt-4o)
    api_key=os.getenv("OPENAI_API_KEY")
)

Step #6: Define the Compliance AI Agent

Combine the LLM, IPFLY tools, and a system prompt to create the agent. Add the following to agent.py:


from langchain.agents import create_agent
from langchain_core.prompts import PromptTemplate

# System prompt for compliance tracking
system_prompt = """
You are a compliance tracking expert. Your role is to analyze internal documents for privacy/regulatory risks and validate them using real-time web data obtained with IPFLY proxies.
Follow these rules:
1. Analyze the input PDF to identify key regulatory aspects (e.g., data retention, deletion).
2. Generate 2-3 concise SERP queries (max 5 words) to find updated regulations.
3. Use ipfly_serp_search to retrieve top regulatory websites (prioritize government sources).
4. Use ipfly_web_scraper to extract content from those websites.
5. Create a report that includes:
   - Citations from the internal PDF.
   - Insights from the scraped web data.
   - Clear compliance recommendations.
6. Only use sources obtained from the IPFLY proxies and the input PDF—never hallucinate information.
"""

# List of tools (IPFLY + LLM)
tools = [ipfly_serp_tool, ipfly_scraper_tool]

# Create the agent (powered by LangGraph)
agent = create_agent(
    llm=llm,
    tools=tools,
    system_prompt=system_prompt
)

Step #7: Load the PDF and Create the Prompt

Add logic to load internal PDF documents and generate a prompt for the agent. Add the following to agent.py:


from langchain_community.document_loaders import PyPDFDirectoryLoader

# Create PDF input folder
os.makedirs("./input", exist_ok=True)

# Load PDF document
loader = PyPDFDirectoryLoader("./input")
docs = loader.load()
internal_doc = "\n\n".join([doc.page_content for doc in docs])

# Prompt template for the agent
prompt_template = PromptTemplate.from_template("""
Analyze the following internal document for compliance risks and validate using real-time web data:

PDF Content:
{pdf}

Generate a concise compliance report including PDF citations and scraped regulatory insights.
""")

# Create the final prompt
prompt = prompt_template.format(pdf=internal_doc)

Step #8: Set Up Langfuse for Observability

  1. Create a Langfuse account (a free tier is available) and navigate to “Project Settings” → “API Keys.”
  2. Generate public and secret keys and add them to your .env file (as shown in Step #2).

Step #9: Integrate Langfuse Tracing

Add Langfuse tracing to the agent to monitor every step (tool calls, LLM outputs, latency). Update agent.py:


from langfuse import get_client
from langfuse.langchain import CallbackHandler

# Initialize Langfuse client
langfuse = get_client(
    secret_key=os.getenv("LANGFUSE_SECRET_KEY"),
    public_key=os.getenv("LANGFUSE_PUBLIC_KEY"),
    base_url=os.getenv("LANGFUSE_BASE_URL")
)

# Create Langfuse callback handler
langfuse_handler = CallbackHandler()

Step #10: Final Code

Your complete agent.py file should look like this:


import os
import json
import requests
from dotenv import load_dotenv
from bs4 import BeautifulSoup
from langchain.tools import Tool
from langchain_openai import ChatOpenAI
from langchain.agents import create_agent
from langchain_core.prompts import PromptTemplate
from langchain_community.document_loaders import PyPDFDirectoryLoader
from langfuse import get_client
from langfuse.langchain import CallbackHandler

# Load environment variables
load_dotenv()

# ------------------------------
# Langfuse Setup
# ------------------------------
langfuse = get_client(
    secret_key=os.getenv("LANGFUSE_SECRET_KEY"),
    public_key=os.getenv("LANGFUSE_PUBLIC_KEY"),
    base_url=os.getenv("LANGFUSE_BASE_URL")
)
langfuse_handler = CallbackHandler()

# ------------------------------
# Build IPFLY Tools for LangChain
# ------------------------------
class IPFLYSERPTool(Tool):
    def __init__(self):
        super().__init__(
            name="ipfly_serp_search",
            description="Searches Google for regulatory keywords using IPFLY proxies. Returns the top 5 government/regulatory websites.",
            func=self.run
        )
        self.proxy = os.getenv("IPFLY_PROXY_ENDPOINT")

    def run(self, query: str) -> str:
        params = {"q": query, "hl": "en", "gl": "us"}
        headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}

        try:
            response = requests.get("https://www.google.com/search",
                params=params,
                proxies={"http": self.proxy, "https": self.proxy},
                headers=headers,
                timeout=30)
            response.raise_for_status()
            soup = BeautifulSoup(response.text, "html.parser")
            results = []

            for g in soup.find_all("div", class_="g")[:5]:
                title = g.find("h3").get_text(strip=True) if g.find("h3") else None
                url = g.find("a")["href"] if g.find("a") else None
                if title and url and ("gov" in url or "regulatory" in url):
                    results.append({"title": title, "url": url})

            return json.dumps(results, indent=2)
        except Exception as e:
            return f"SERP search failed: {str(e)}"

class IPFLYWebScraperTool(Tool):
    def __init__(self):
        super().__init__(
            name="ipfly_web_scraper",
            description="Scrapes regulatory websites using IPFLY proxies. Returns content in Markdown format.",
            func=self.run
        )
        self.proxy = os.getenv("IPFLY_PROXY_ENDPOINT")

    def run(self, url: str) -> str:
        headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"}

        try:
            response = requests.get(
                url,
                proxies={"http": self.proxy, "https": self.proxy},
                headers=headers,
                timeout=30)
            response.raise_for_status()
            soup = BeautifulSoup(response.text, "html.parser")

            for script in soup(["script", "style", "nav", "aside", "footer"]):
                script.decompose()

            text = soup.get_text(strip=True, separator="\n")
            lines = [line.strip() for line in text.split("\n") if line.strip()]
            markdown = "\n\n".join(lines[:50])

            return f"Source: {url}\n\n{markdown}"
        except Exception as e:
            return f"Web scraping failed: {str(e)}"

# Initialize IPFLY tools
ipfly_serp_tool = IPFLYSERPTool()
ipfly_scraper_tool = IPFLYWebScraperTool()

# ------------------------------
# LLM Integration
# ------------------------------
llm = ChatOpenAI(
    model="gpt-5-mini",
    api_key=os.getenv("OPENAI_API_KEY")
)

# ------------------------------
# Compliance AI Agent Definition
# ------------------------------
system_prompt = """
You are a compliance tracking expert. Analyze internal PDFs for privacy/regulatory risks and validate using real-time web data obtained with IPFLY proxies.
1. Identify key privacy/regulatory aspects from the PDF.
2. Generate 2-3 concise SERP queries (max 5 words).
3. Use ipfly_serp_search to find top government/regulatory websites.
4. Use ipfly_web_scraper to extract content from those websites.
5. Create a report including PDF citations, web insights, and compliance recommendations.
Only use data obtained from the PDF and IPFLY proxies—do not hallucinate information.
"""

tools = [ipfly_serp_tool, ipfly_scraper_tool]
agent = create_agent(llm=llm, tools=tools, system_prompt=system_prompt)

# ------------------------------
# Load PDF and Create Prompt
# ------------------------------
os.makedirs("./input", exist_ok=True)
loader = PyPDFDirectoryLoader("./input")
docs = loader.load()
internal_doc = "\n\n".join([doc.page_content for doc in docs])

prompt_template = PromptTemplate.from_template("""
Analyze this internal document for compliance risks and validate using real-time web data:

PDF Content:
{pdf}

Generate a compliance report including PDF citations and scraped regulatory insights.
""")

prompt = prompt_template.format(pdf=internal_doc)

# ------------------------------
# Execute Agent with Langfuse Tracing
# ------------------------------
if __name__ == "__main__":
    print("Executing compliance AI agent with Langfuse tracing...")

    for step in agent.stream(
        {"messages": [{"role": "user", "content": prompt}]},
        stream_mode="values",
        config={"callbacks": [langfuse_handler]}
    ):
        step["messages"][-1].pretty_print()

Step #11: Run the Agent

  1. Place a compliance-related PDF (e.g., data-processing-workflow.pdf) in the ./input folder.
  2. Execute the agent:

python agent.py

The agent will:

  • Analyze the PDF to identify regulatory risks (e.g., “data retention”).
  • Use IPFLY’s SERP tool to search for updated rules (e.g., “GDPR data retention”).
  • Use IPFLY’s web scraper to crawl top government websites (e.g., europa.eu).
  • Generate a compliance report with citations.
  • Langfuse will automatically trace every step—from IPFLY proxy calls to LLM outputs.

Step #12: Inspect Agent Traces in Langfuse

  1. Log into your Langfuse dashboard.
  2. Navigate to the “Traces” tab—you will see a new trace record for the agent execution.
  3. Click on the trace record to explore:
    • Tool Calls: View IPFLY SERP/scraper requests, including proxy usage and response data.
    • LLM Interactions: Examine prompts, outputs, and latency.
    • Metrics: Track crawling success rates, LLM costs, and overall execution time.

Key insights from Langfuse:

  • Verify IPFLY proxy performance (e.g., 100% success rate in crawling government sites).
  • Identify bottlenecks (e.g., SERP search latency—adjust IPFLY proxy type to datacenter for speed).
  • Audit compliance (e.g., confirm that the agent only uses government data scraped by IPFLY).

Next Steps to Enhance the Agent

  1. Prompt Management: Use Langfuse’s prompt library to version control compliance prompts.
  2. Custom Langfuse Dashboards: Track IPFLY proxy success rates, LLM costs, and compliance report quality.
  3. IPFLY Proxy Optimization: Use static residential proxies for repetitive crawls (e.g., monthly GDPR updates) for improved consistency.
  4. Report Export: Add logic to save compliance reports as PDFs for auditing.
  5. Multi-Region Support: Use IPFLY’s regional IPs to crawl multi-jurisdictional regulations (e.g., US CCPA, Canada PIPEDA).

Conclusion

Integrating Langfuse with LangChain AI agents powered by IPFLY proxies provides enterprise-grade observability and reliability—essential for compliance use cases. Langfuse offers transparency by tracking every agent action, while IPFLY ensures unrestricted access to high-quality regulatory data.

Together, these tools address the biggest challenges in enterprise AI agents:

  • Data Access: IPFLY’s 90+ million global proxies bypass blocking and geo-restrictions.
  • Observability: Langfuse tracks every step for auditing and optimization.
  • Compliance: Immutable records of data sources and agent logic.

Whether you’re building compliance agents, market research tools, or customer support bots, the combination of IPFLY, Langfuse, and LangChain delivers a powerful, transparent, and scalable tech stack.

Ready to build your own observable AI agent? Start with IPFLY’s free trial, Langfuse’s free tier, and the code from this guide—unlock the full potential of web data for enterprise AI.