File size: 4,078 Bytes
2705160
 
62ad9da
 
 
2705160
 
 
 
d123508
 
 
2705160
 
f844f16
d7b323e
f844f16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7b323e
 
 
954a1b2
f844f16
954a1b2
 
 
 
 
f844f16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
---
title: Template Final Assignment
emoji: πŸ•΅πŸ»β€β™‚οΈ
colorFrom: indigo
colorTo: indigo
sdk: gradio
sdk_version: 5.25.2
app_file: app.py
pinned: false
hf_oauth: true
# optional, default duration is 8 hours/480 minutes. Max duration is 30 days/43200 minutes.
hf_oauth_expiration_minutes: 480
---

# LangGraph Multi-Agent System with Langfuse v3 Observability

A sophisticated multi-agent system built with LangGraph that follows best practices for state management, tracing, and iterative workflows. Features comprehensive Langfuse v3 observability with OpenTelemetry integration.

## Architecture Overview

The system implements an iterative research/code loop with specialized agents:

```
User Query β†’ Lead Agent β†’ Research Agent β†’ Code Agent β†’ Lead Agent (loop) β†’ Answer Formatter β†’ Final Answer
```

## Key Features

- **πŸ€– Multi-Agent Workflow**: Specialized agents for research, computation, and formatting
- **πŸ“Š Langfuse v3 Observability**: Complete tracing with OTEL integration and predictable span naming
- **πŸ”„ Iterative Processing**: Intelligent routing between research and computational tasks
- **🎯 GAIA Compliance**: Exact-match answer formatting for benchmark evaluation
- **πŸ’Ύ Memory System**: Vector store integration for learning and caching
- **πŸ› οΈ Tool Integration**: Web search, Wikipedia, ArXiv, calculations, and code execution

## Quick Start

### Environment Setup

Create an `env.local` file with required API keys:

```bash
# LLM API
GROQ_API_KEY=your_groq_api_key

# Search Tools
TAVILY_API_KEY=your_tavily_api_key

# Observability (Langfuse v3)
LANGFUSE_PUBLIC_KEY=your_langfuse_public_key
LANGFUSE_SECRET_KEY=your_langfuse_secret_key
LANGFUSE_HOST=https://cloud.langfuse.com

# Memory (Optional)
SUPABASE_URL=your_supabase_url
SUPABASE_SERVICE_KEY=your_supabase_service_key
```

### Running the System

**Important**: Use `uv run` for proper dependency management:

```bash
# Run the multi-agent system test
uv run python test_new_multi_agent_system.py

# Test Langfuse v3 observability
uv run python test_observability.py

# Run the main application
uv run python app.py
```

### Basic Usage

```python
import asyncio
from langgraph_agent_system import run_agent_system

async def main():
    result = await run_agent_system(
        query="What is the capital of Maharashtra?",
        user_id="user_123",
        session_id="session_456"
    )
    print(f"Answer: {result}")

asyncio.run(main())
```

## Observability Dashboard

After running queries, check your traces at: **https://cloud.langfuse.com**

The system provides:
- 🎯 **Predictable Span Naming**: `agent/<role>`, `tool/<name>`, `llm/<model>`
- πŸ”— **Session Tracking**: User and session continuity across conversations  
- πŸ“ˆ **Cost & Latency Metrics**: Automatic aggregation by span type
- 🌐 **OTEL Integration**: Automatic trace correlation across services

## Deployment

### For Hugging Face Spaces

To generate a `requirements.txt` file compatible with **Python 3.10** for deployment:

```bash
uv pip compile pyproject.toml --python 3.10 -o requirements.txt

# Remove Windows-specific packages
# Linux / macOS (bash)
sed -i '/^pywin32==/d' requirements.txt

# Windows (PowerShell)
(Get-Content requirements.txt) -notmatch '^pywin32==' | Set-Content requirements.txt
```

### Environment Variables for Production

Set these in your deployment environment:
- `GROQ_API_KEY` - Required for LLM inference
- `TAVILY_API_KEY` - Required for web search
- `LANGFUSE_PUBLIC_KEY` - Required for observability
- `LANGFUSE_SECRET_KEY` - Required for observability
- `LANGFUSE_HOST` - Langfuse endpoint (default: https://cloud.langfuse.com)

## Documentation

For detailed architecture, configuration, and usage instructions, see:
- **[Multi-Agent System Guide](README_MULTI_AGENT_SYSTEM.md)** - Complete system documentation
- **[Supabase Setup](README_SUPABASE.md)** - Memory system configuration

## Configuration Reference

Check out the Hugging Face Spaces configuration reference at https://huggingface.co/docs/hub/spaces-config-reference