Skip to content

About

A multi-agent AI research app built with LangGraph, Flask, and Ollama. Dynamically designs specialist agent teams to solve and stream complex tasks in real-time.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Researcher

Researcher is a web app that builds a small team of AI agents for each task you give it. A supervisor passes the work between the agents, and a finalizer merges what they produce into one answer. You can watch each agent's contribution appear as it is written.

It is built with LangGraph, Flask and Groq. Each agent runs on the model that suits its skill, so the coder, the reviewer and the writer can all use different models.

How it works

flowchart LR
    T([Task]) --> D[Team designer]
    D -- "2–5 agents,<br/>one skill each" --> S{Supervisor}
    S -- next agent --> A1[Agent]
    S -- next agent --> A2[Agent]
    S -- next agent --> A3[Agent]
    A1 --> S
    A2 --> S
    A3 --> S
    S -- FINISH --> F[Finalizer]
    F --> R([Final answer])
Loading
  1. Team design. An LLM reads the task and designs 2 to 5 specialist agents. Each agent gets a name, a role prompt and one skill: planning, research, coding, review, analysis, writing or general. If the designer's output can't be used, a fixed fallback team takes over: Planner, Researcher, Coder and Reviewer.
  2. Routing. Before each step, the supervisor reads the conversation so far and picks the next agent, or FINISH. It only needs to route, so it sees the first and last 600 characters of each long reply rather than the whole text. It also explains why it chose that agent, and the UI shows the explanation with each step. After 10 agent replies, or once the run's time budget has passed, the supervisor stops routing and hands over to the finalizer, so every run ends with an answer.
  3. Specialist work. The chosen agent runs on the model assigned to its skill. Its reply is added to the shared conversation, and control goes back to the supervisor.
  4. Finalizing. When the supervisor chooses FINISH, the finalizer combines the team's work into one Markdown answer. Where there is a reviewed version of any code, it uses that version.

If Groq refuses a role's model (for example, 429 Too Many Requests once that model's rate limit is used up), that call is retried on GROQ_MODEL instead of failing the run.

Features

  • A new team of agents for every task, with each agent's model chosen by its skill
  • Live streaming over Server-Sent Events, or a single blocking request
  • A live workflow graph of the run: each node lights up while it works, the edges show where the supervisor sent the work, and the execution path lists every step in order with its duration. Select a step or a node to see the supervisor's reasoning, an agent's output, or where a run failed or was stopped
  • A timeline of agent contributions that shows the supervisor's routing reason for each step
  • Answers rendered as Markdown and sanitized with DOMPurify, with code highlighting
  • Stop, Clear and Copy buttons, Ctrl + Enter to run, and a light/dark theme
  • A JSON API you can use without the UI
  • Optional login (HTTP Basic) and a cap on concurrent runs
  • Security headers on every response (a Content Security Policy that allows only the exact CDN files the page uses, X-Frame-Options, nosniff, Cross-Origin-Opener-Policy, Permissions-Policy, and HSTS over HTTPS) and limits on request size

Quick start

Prerequisites: Python 3.10 or newer, and a Groq API key. You can create a key at https://console.groq.com/keys.

git clone https://github.com/Aminul1993/Researcher.git
cd Researcher

python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activate

pip install -r requirements.lock

requirements.lock installs the exact, hash-checked versions that CI tests. pip install -r requirements.txt also works and picks the newest versions within the supported ranges.

Copy the example settings file, then set GROQ_API_KEY in .env to your key:

# Windows
copy .env.example .env
# macOS / Linux
cp .env.example .env

Start the server:

python app.py

Then open http://127.0.0.1:5000 and describe a task. To see a full run, click Try an example.

Configuration

All settings are environment variables. The app loads them from .env when it starts and reads them once, so restart the server after changing them. .env.example lists every variable with its default value.

Groq

Variable Default Description
GROQ_API_KEY — Required. Your Groq API key. Without it, API calls return 503.
GROQ_BASE_URL https://api.groq.com URL of the Groq API. Change it only to go through a proxy.
GROQ_MODEL openai/gpt-oss-120b Default model. It is used for any role that has no model of its own, and when a role's model is refused or rate-limited.

Models per role

To change the model for a role or skill, set GROQ_MODEL_<ROLE>. For example, GROQ_MODEL_CODING=llama-3.3-70b-versatile.

Role / skill Variable Default model
Supervisor GROQ_MODEL_SUPERVISOR openai/gpt-oss-20b
Team designer GROQ_MODEL_DESIGNER openai/gpt-oss-120b
Finalizer GROQ_MODEL_FINALIZER openai/gpt-oss-120b
planning GROQ_MODEL_PLANNING llama-3.3-70b-versatile
research GROQ_MODEL_RESEARCH llama-3.3-70b-versatile
coding GROQ_MODEL_CODING openai/gpt-oss-120b
review GROQ_MODEL_REVIEW llama-3.3-70b-versatile
analysis GROQ_MODEL_ANALYSIS openai/gpt-oss-120b
writing GROQ_MODEL_WRITING llama-3.3-70b-versatile
general — GROQ_MODEL

All of these defaults were Groq production models as of 2026-11-10. Groq's model list shows the current ones. Preview models also work, but Groq can withdraw them at short notice. The supervisor and the team designer call the models through tool calling, so any model you pick for those roles must support tool calls.

Groq limits the requests and tokens each model can serve per minute and per day, and the free plan's limits are low (see Groq's rate limits). The limits apply per model, so the defaults spread the roles over three models. When a call is rate-limited, the Groq client retries it twice, waiting as long as Groq asks (up to a minute), and then the call moves to GROQ_MODEL. A single long call, such as the finalizer's at the end of a long run, can need more tokens than a model allows per minute. If Groq rejects it as too large, give that role a model with a higher limit, or use a paid plan.

Server

Variable Default Description
FLASK_HOST 127.0.0.1 Address the development server binds to.
FLASK_PORT 5000 Port of the development server.
FLASK_DEBUG off Set to 1, true or yes to turn on Flask debug mode.
LOG_LEVEL INFO Python logging level.
TRUSTED_PROXIES 0 Number of reverse proxies in front of the app whose X-Forwarded-* headers to trust. See Deployment.

Login and limits

Every run uses your Groq API key, so set APP_PASSWORD before the server is reachable from anywhere but your own machine.

Variable Default Description
APP_PASSWORD empty (login off) When set, the page and the API require HTTP Basic login. /api/health and static files stay public. Use it only over HTTPS.
APP_USERNAME admin Username for the login.
MAX_CONCURRENT_RUNS 4 Runs allowed at the same time in each server process. Further runs get 429 with a Retry-After header. A run's slot is freed when it finishes or its client disconnects.
RUN_TIME_BUDGET_SECONDS 600 Time budget per run. Once it has passed, the supervisor stops routing and the finalizer answers with the work done so far. The agent call in progress and the finalizer still run, so a run can take somewhat longer.

Logs

Each run gets a 12-character run ID. Every log line written during the run carries it in brackets, and so does a line for each model call with its latency and token counts. The API returns the ID in the X-Run-ID response header, in the start stream event and in the /api/run result, so a failed run can be traced in the logs.

2026-10-16 10:12:03 INFO     agents.telemetry [3f9a1c27b0d4]: Coder call on gpt-oss:120b took 14.2s (1830 input / 912 output tokens)
2026-10-16 10:12:41 INFO     agents.runner [3f9a1c27b0d4]: Workflow finished in 52.7s: 2 agent steps, 7 model calls, 9120 input / 3302 output tokens

API

Every endpoint accepts and returns JSON. Errors come back as {"status": "error", "error": "<message>"} with a matching HTTP status code.

GET /api/health

Returns the default model and the model used by each role and skill.

{ "status": "ok", "model": "gpt-oss:120b", "role_models": { "supervisor": "gemma4:31b", "coding": "gpt-oss:120b", "...": "..." } }

POST /api/run

Runs the whole workflow and returns the result in one response.

curl -X POST http://127.0.0.1:5000/api/run \
  -H "Content-Type: application/json" \
  -d '{"task": "Compare SQLite and PostgreSQL for a small web app."}'
{
  "status": "success",
  "task": "Compare SQLite and PostgreSQL for a small web app.",
  "run_id": "3f9a1c27b0d4",
  "team": [
    { "name": "Researcher", "role": "Summarise the strengths and limits of each database.", "skill": "research", "model": "nemotron-3-ultra" }
  ],
  "team_generated": true,
  "models": { "supervisor": "gemma4:31b", "designer": "gpt-oss:120b", "finalizer": "gpt-oss:120b" },
  "steps": [
    { "step": 1, "agent": "Researcher", "message": "…", "reason": "…", "model": "nemotron-3-ultra" }
  ],
  "final_response": "…"
}

POST /api/stream

Takes the same request body as /api/run, but streams the run as Server-Sent Events while it happens:

Event Payload
start { "task", "run_id" }
team { "agents": [{ "name", "role", "skill", "model" }], "generated", "models" }
routing { "next_agent", "reason" }, sent each time the supervisor picks the next step
step { "step", "agent", "message", "reason", "model" }, one per agent contribution
final { "message", "model" }, the merged answer
done { "status": "success" }
error { "status": "error", "error" }
curl -N -X POST http://127.0.0.1:5000/api/stream \
  -H "Content-Type: application/json" \
  -d '{"task": "Write a Python function that validates an IPv4 address."}'

While a model call is in progress the stream sends a : keepalive comment line every 15 seconds, so proxies don't close the connection. SSE clients ignore comment lines. If the client disconnects, the run stops once the model call in progress has finished.

Limits and error codes

Limit Value
Task length 4,000 characters
Request body 64 KB (larger bodies return 413)
Agents per team 5
Agent steps per run 10. After the 10th reply the finalizer answers with the work done so far.
Time per run RUN_TIME_BUDGET_SECONDS (default 600). After that the finalizer answers with the work done so far.
Concurrent runs MAX_CONCURRENT_RUNS (default 4) per server process. Further runs return 429.
Model timeout 300 seconds for each model reply. A timeout returns 504.

Other status codes: 400 for an invalid request body, 401 when login is on and the credentials are missing or wrong, 429 when every run slot is busy (retry after the Retry-After seconds) or Groq's rate limit was still reached after retrying and falling back, 502 when Groq returns any other error (bad key, model not found, request too large), and 503 when GROQ_API_KEY is missing.

Using the workflow from Python

You can also use the orchestration code without the web server:

from dotenv import load_dotenv
from agents.workflow import run_workflow, stream_workflow

load_dotenv()

# Generate a team and wait for the final answer
result = run_workflow("Outline a migration plan from REST to GraphQL.")
print(result["final_response"])

# Use a fixed team and handle events as they arrive
team = {
    "Coder": "Write the requested Python code.",
    "Reviewer": "Check the code for bugs and suggest fixes.",
}
for event in stream_workflow("Write a thread-safe LRU cache.", agent_registry=team):
    if event["type"] == "step":
        print(f"[{event['agent']}] {event['message'][:80]}…")

run_workflow and stream_workflow both accept agent_registry and llm arguments, and the keyword-only run_id and time_budget (seconds). Pass any LangChain chat model as llm to use that one model for every role. To see run IDs in your own logs, attach agents.workflow.RunIdFilter to your log handler and add %(run_id)s to its format. Every module logs under the agents logger.

Settings are read from the environment once, on first use. Call load_dotenv() before the first workflow call, as above, or call agents.workflow.reload_settings() after changing the environment. An unusable agent_registry (an empty team, duplicate or reserved names, or names containing | or :) raises InvalidTeamError, a WorkflowError with status 400 that is also a ValueError.

Deployment

python app.py starts Flask's development server. In production, serve the app factory with a threaded WSGI server so that streaming responses don't block other requests:

pip install -r requirements.lock   # includes gunicorn on Linux and macOS
gunicorn --worker-class gthread --threads 8 "app:create_app()"

Each run holds a server thread for its whole duration, so keep --threads at MAX_CONCURRENT_RUNS + 2 or more. The page and the health check then stay reachable while every run slot is busy. The cap applies per process, so with several gunicorn workers the total is workers × MAX_CONCURRENT_RUNS.

Set APP_PASSWORD and serve the app over HTTPS before exposing it: HTTP Basic sends the password with every request.

If you put a reverse proxy in front of the app, turn off response buffering for /api/stream. The app sends X-Accel-Buffering: no, which nginx respects. If the proxy terminates TLS, set TRUSTED_PROXIES to the number of proxies in front of the app, so the app trusts their X-Forwarded-* headers and sends Strict-Transport-Security on HTTPS requests. Leave it at 0 when clients can reach the app directly, or they could spoof those headers.

Development

Install the pinned development tools and run the same checks as CI. The tests use a scripted fake model, so they make no network calls and need no API key:

pip install -r requirements-dev.lock
ruff check .
mypy
pytest --cov
pip-audit -r requirements.lock --require-hashes --disable-pip

Dependencies

requirements.txt and requirements-dev.txt list the supported version ranges. requirements.lock and requirements-dev.lock pin every package, including indirect ones, with hashes, for all platforms and Python 3.10 and newer. After changing a range, or to pick up new releases, regenerate both locks with uv:

uv pip compile requirements.txt --universal --python-version 3.10 --generate-hashes --no-header -o requirements.lock
uv pip compile requirements-dev.txt --universal --python-version 3.10 --generate-hashes --no-header -c requirements.lock -o requirements-dev.lock

Front-end libraries

Bootstrap, Bootstrap Icons, marked, DOMPurify and highlight.js load from CDNs, pinned by Subresource Integrity hashes. Their URLs and hashes live only in CDN_STYLES and CDN_SCRIPTS in app.py: the page template and the Content Security Policy are both built from them, and the policy allows those exact files rather than whole CDN hosts. To upgrade a library, change its URL there and replace its hash with the output of:

curl -s <url> | openssl dgst -sha384 -binary | openssl base64 -A

Project structure

Researcher/
├── app.py               # Flask app factory, routes, SSE streaming, error handling, security headers
├── agents/
│   ├── workflow.py      # Public API: re-exports the names below for `from agents.workflow import ...`
│   ├── config.py        # Settings from the environment, limits, roles, skills, default models
│   ├── errors.py        # Client-safe WorkflowError and its subclasses
│   ├── schemas.py       # Graph state, API records, structured-output schemas
│   ├── messages.py      # Reading model replies and presenting them to models
│   ├── models.py        # Groq clients and falling back to the default model
│   ├── team.py          # Team designer and skill inference
│   ├── routing.py       # Supervisor, with the step and time budgets
│   ├── graph.py         # Agent and finalizer nodes, graph builder
│   ├── telemetry.py     # Run IDs, per-call latency and token logging
│   └── runner.py        # stream_workflow, run_workflow, error mapping
├── templates/
│   └── index.html       # Single-page UI (Bootstrap 5)
├── static/
│   ├── css/style.css
│   └── js/
│       ├── app.js       # Streaming client, timeline, roster, theme toggle
│       └── graph.js     # Live workflow graph, execution path and step details
├── tests/               # pytest suite; fakes.py holds the offline chat model
├── .github/workflows/   # CI: ruff, mypy, pytest with coverage, pip-audit
├── .env.example         # Every setting with its default; copy to .env
├── pyproject.toml       # Tool configuration (pytest, coverage, ruff, mypy)
├── requirements.txt     # Supported version ranges
├── requirements.lock    # Exact pinned versions with hashes
├── requirements-dev.txt
├── requirements-dev.lock
└── LICENSE

License

MIT

About

A multi-agent AI research app built with LangGraph, Flask, and Ollama. Dynamically designs specialist agent teams to solve and stream complex tasks in real-time.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages