Skip to main content
Glama
ANINDASAU

Multi-Agent Research Assistant MCP Server

by ANINDASAU
README.md
# Multi-Agent Research Assistant & MCP Server

This project implements the assignment in two small parts:

1. A LangGraph multi-agent workflow with one Supervisor and two specialist workers.
2. A FastMCP server with two tools and a client that calls those tools.

The language model is **Ollama**, so no OpenAI API key is required.

## 1. What The Project Demonstrates

The Supervisor receives a question and chooses the appropriate worker:

```text
User question
		 |
		 v
Supervisor Agent
		 |------------------------------|
		 v                              v
Research Agent                 Analysis Agent
		 |                              |
		 v                              v
Knowledge-base tool             Comparison tool
```

For a question that needs both workers, the Supervisor asks the Research Agent for evidence first, then gives that evidence to the Analysis Agent.

The MCP part is independent of the LangGraph part:

```text
MCP Client ---> FastMCP Server
										|------ get_weather(city)
										|------ get_news(topic)
```

## 2. Prerequisites

- Windows PowerShell
- Python 3.10 or newer
- Ollama
- An Ollama model such as `llama3.2`

The repository already contains the requested virtual environment at `multivenv`.

## 3. Installation

Open PowerShell in the project directory:

```powershell
cd D:\LLMEngg_8-Multi-Agent-Research-Assistant-MCP-Server
.\multivenv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
Copy-Item .env.example .env
```

If PowerShell does not allow activation, use the virtual environment directly for every command:

```powershell
.\multivenv\Scripts\python.exe -m pip install -r requirements.txt
```

Do not use a different system Python. Otherwise imports such as `langchain_core` may be missing.

## 4. Configure Ollama

Start Ollama in a separate terminal. If Ollama is already running as a desktop application, skip `ollama serve`.

```powershell
ollama serve
ollama pull llama3.2
```

The default configuration in `.env` is:

```env
OLLAMA_MODEL=llama3.2
OLLAMA_BASE_URL=http://localhost:11434
```

You can use another model, but it must support chat and tool calling well enough for LangGraph. For example:

```env
OLLAMA_MODEL=qwen2.5:7b
```

## 5. Run The Multi-Agent Assistant

Run a research-only question:

```powershell
python main.py "What does MCP do?"
```

This should route to the Research Agent, which searches `data/knowledge_base.txt`.

Run an analysis question:

```powershell
python main.py "Compare these two ideas: solar power uses sunlight; wind power uses moving air."
```

This should route to the Analysis Agent, which uses `compare_texts`.

Run a collaboration question:

```powershell
python main.py "Research solar and wind power, then compare their main trade-offs."
```

This question needs both workers. The expected workflow is:

1. The Supervisor calls `ask_research_agent`.
2. The Research Agent calls `search_knowledge_base`.
3. The Supervisor sends the evidence to `ask_analysis_agent`.
4. The Analysis Agent calls `compare_texts`.
5. The Supervisor returns one final answer.

The default question can also be run without an argument:

```powershell
python main.py
```

## 6. Run The MCP Demonstration

The client calls both FastMCP tools:

```powershell
python -m mcp_client.client
```

Expected output is similar to:

```text
Weather: Cloudy, 15 C
News: Mock headline: New developments in artificial intelligence are being monitored by the research team.
```

The client uses FastMCP's in-process client transport so the demonstration is reliable and easy to run locally. It still uses the real MCP client/server protocol. The standalone server can be started for an MCP-compatible host with:

```powershell
python mcp_server/server.py
```

That standalone server uses MCP stdio transport.

## 7. Run Tests

```powershell
python -m pytest -q
```

The tests cover the deterministic tools without requiring Ollama or a model download. The LangGraph construction can also be checked without making a model request:

```powershell
$env:OLLAMA_MODEL = "llama3.2"
python -c "from agents.supervisor import build_supervisor; build_supervisor(); print('Supervisor created')"
```

## 8. File Structure

```text
agents/
	model.py             Shared ChatOllama configuration
	research_agent.py    Research worker created with create_react_agent
	analysis_agent.py    Analysis worker created with create_react_agent
	supervisor.py        Supervisor and wrapped worker tools

tools/
	research_tool.py     Local knowledge-base lookup tool
	analysis_tool.py     Structured two-text comparison tool

data/
	knowledge_base.txt   Local evidence used by the Research Agent

mcp_server/
	server.py            FastMCP server and its two tools

mcp_client/
	client.py            Client demonstration calling both MCP tools

main.py                Command-line entry point for the Supervisor
tests/                  Deterministic tool tests
requirements.txt        Python dependencies
.env.example            Ollama configuration template
```

## 9. Assignment Objective Checklist

| Assignment objective | Implementation |
|---|---|
| Build a Supervisor agent | `agents/supervisor.py` |
| Build a Research Agent with `create_react_agent` | `agents/research_agent.py` |
| Build an Analysis Agent with `create_react_agent` | `agents/analysis_agent.py` |
| Give Research Agent an information-retrieval tool | `tools/research_tool.py` and `data/knowledge_base.txt` |
| Give Analysis Agent a two-snippet comparison tool | `tools/analysis_tool.py` |
| Wrap workers as tools for the Supervisor | `ask_research_agent` and `ask_analysis_agent` |
| Add role-specific system prompts | Each agent module defines its own prompt |
| Build an MCP server with at least two tools | `mcp_server/server.py` |
| Demonstrate an MCP client calling the tools | `mcp_client/client.py` |
| Test research, analysis, and collaboration scenarios | Commands in Section 5 |

## 10. Troubleshooting

### `No module named langchain_core`

The system Python is being used. Activate `multivenv` or use the direct interpreter path:

```powershell
.\multivenv\Scripts\python.exe main.py "What does MCP do?"
```

### `connection refused` from Ollama

Start Ollama and confirm the model exists:

```powershell
ollama serve
ollama list
ollama pull llama3.2
```

### The model does not call tools

Use a tool-capable chat model, keep the question explicit, and try the collaboration example from Section 5. Small or older models may answer directly without using a tool.

### The knowledge base returns no answer

The Research Agent only searches the local file. Add more paragraphs to `data/knowledge_base.txt` and rerun the question.

## 11. Important Scope Note

This is a simple educational implementation. The knowledge base is a mock local data source, weather and news are mock MCP results, and the LLM routing is tested manually with Ollama. The deterministic tools are covered by automated tests.