File size: 6,411 Bytes
8c6097b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# CLI Demo for DeepDiver Long Writer Multi-Agent System

This CLI demo showcases the multi-agent system that coordinates between PlannerAgent, InformationSeekerAgent, and WriterAgent to handle complex queries and generate comprehensive long-form content.

## Features

- 🧠 **PlannerAgent**: Orchestrates the entire process and coordinates sub-agents
- 🔍 **InformationSeekerAgent**: Performs web research and gathers information  
- ✍️ **WriterAgent**: Creates comprehensive long-form content
- 📊 **Real-time Visualization**: Shows tool calls, reasoning traces, and sub-agent responses
- ⚙️ **Configuration Management**: Loads settings from .env files

## Setup

### 1. Install Dependencies

```bash
cd deepdiver_v2
pip install -r requirements.txt
```

### 2. Configure Environment

Create a `.env` file in the `config/` directory:

```bash
# From the project root
cp env.template config/.env
```

Then edit `config/.env` with your settings:

```bash
# Custom LLM Service Configuration
MODEL_REQUEST_URL=http://your-llm-service-endpoint/v1/chat/completions
MODEL_REQUEST_TOKEN=your-service-token
MODEL_NAME=pangu_auto

# MCP Server Configuration
MCP_SERVER_URL=http://localhost:6274/mcp
MCP_AUTH_TOKEN=
MCP_USE_STDIO=true

# Agent Iteration Limits
PLANNER_MAX_ITERATION=20
INFORMATION_SEEKER_MAX_ITERATION=30
WRITER_MAX_ITERATION=20

# Mode
PLANNER_MODE=auto # auto, writing, qa

# Other settings...
```

### 3. Start Required Services

Make sure your MCP server is running:

```bash
# Start MCP server (if needed)
python src/tools/mcp_server_standard.py
```

## Usage

### Interactive Mode (Recommended)

```bash
python cli/demo.py
```

This will start an interactive session where you can enter queries and see the full execution flow.

### Single Query Mode

```bash
python cli/demo.py -q "Write a comprehensive analysis of artificial intelligence trends in 2024"
```

### Configuration Only

```bash
python cli/demo.py --config-only
```

### Debug Mode (Verbose Logging)

```bash
python cli/demo.py --debug -q "Debug a specific query"
```

### Quiet Mode (Clean Output)

```bash
python cli/demo.py --quiet -q "Run with minimal output"
```

### Create Sample Configuration

```bash
python cli/demo.py --create-env
```

## Example Queries

### For Information Seeking Tasks:
- "What are the latest developments in quantum computing?"
- "Research the current state of renewable energy adoption globally"
- "Find information about recent AI breakthroughs in healthcare"

### For Long-form Writing Tasks:
- "Write a comprehensive report on the impact of AI on education"
- "Create an in-depth analysis of climate change mitigation strategies"
- "Generate a detailed guide on sustainable business practices"

## Demo Flow Visualization

The demo provides rich visual feedback showing:

1. **🚀 Task Initiation**: Shows the user query and planner startup
2. **🧠 Agent Reasoning**: Displays the planner's reasoning at each step
3. **🔧 Tool Calls**: Shows what tools are being called with their arguments
4. **📋 Tool Results**: Displays the results from each tool execution
5. **🤝 Sub-Agent Execution**: Shows when sub-agents (InformationSeeker, Writer) are invoked
6. **📊 Sub-Agent Results**: Displays results from sub-agent executions
7. **🏁 Final Result**: Shows the complete execution summary
8. **🔍 Execution Trace**: Detailed step-by-step trace of the entire process

## Output Modes

The CLI demo supports different output modes for different use cases:

### Default Mode
Shows the full rich interface with welcome screen, progress bars, and detailed visualization of all agent interactions.

### Quiet Mode (`--quiet`)
Suppresses all non-essential output, showing only final results. Useful for:
- Integration with scripts or automation
- Focusing on results without process details
- Running in environments where rich output isn't needed

### Debug Mode (`--debug`)
Enables verbose logging with timestamps, showing all internal system messages. Useful for:
- Troubleshooting configuration issues
- Understanding detailed agent behavior
- Development and debugging

```bash
# Examples of different modes
python cli/demo.py --query "Test query"  # Default rich mode
python cli/demo.py --quiet --query "Test query"  # Minimal output
python cli/demo.py --debug --query "Test query"  # Verbose debugging
```

## Troubleshooting

### Configuration Issues

If you see configuration errors:

1. Ensure `config/.env` exists and is properly formatted
2. Check that all required environment variables are set
3. Verify your LLM service endpoint is accessible
4. Confirm MCP server is running and reachable
5. Use `--debug` mode to see detailed error messages

### Agent Initialization Issues

If agent initialization fails:

1. Check MCP server connectivity
2. Verify model configuration is correct
3. Ensure required permissions for workspace directories
4. Check log output for specific error messages

### Tool Execution Issues

If tool calls fail:

1. Verify MCP server is running and has the required tools
2. Check network connectivity for web search/crawler tools
3. Ensure workspace directories exist and are writable
4. Review tool arguments for correctness

## Advanced Usage

### Custom Sub-Agent Configurations

You can customize sub-agent behavior by modifying the configurations in the demo script:

```python
sub_agent_configs = {
    "information_seeker": {
        "model": "your-model",
        "max_iterations": 30,
    },
    "writer": {
        "model": "your-model", 
        "max_iterations": 20,
        "temperature": 0.3,
        "max_tokens": 16384
    }
}
```

### Monitoring and Debugging

Enable debug mode in your `.env` file:

```bash
DEBUG_MODE=true
```

This will provide more detailed logging and error information.

## Architecture Overview

The demo showcases a sophisticated multi-agent architecture:

```
User Query

PlannerAgent (Coordinator)

├── InformationSeekerAgent (Research)
│   ├── Web Search Tools
│   ├── URL Crawling Tools  
│   ├── Document Analysis Tools
│   └── File Management Tools

└── WriterAgent (Content Generation)
    ├── File Reading Tools
    ├── Document QA Tools
    ├── Content Synthesis
    └── Long-form Writing
```

Each agent follows the ReAct pattern (Reasoning + Acting) with iterative refinement until task completion.