Manual literature reviews are a tax on research velocity. With an autogen agent team literature review automation setup, you can delegate discovery, extraction, and synthesis to specialized agents that talk to each other until they produce a structured survey. This guide walks through a working pipeline you can run against arXiv today.
Step 1: Define agent roles and responsibilities
A literature review needs more than a single prompt. Split the work across four agents: a searcher, a summarizer, a critic, and a synthesizer. Each runs as an AssistantAgent with a tight system message.
System prompts
SEARCHER_SYS = """You are a literature search agent. Given a topic, call the arxiv_search tool to retrieve relevant papers. Return only paper IDs and titles, no commentary."""
SUMMARIZER_SYS = """You are a summarizer. Given a paper ID, fetch its abstract via the arxiv_fetch tool and produce a 150-word summary with methodology, results, and limitations."""
CRITIC_SYS = """You are a critic. Given summaries, flag gaps, contradictions, and low-quality methods. Be concise."""
SYNTHESIZER_SYS = """You are a synthesizer. Given critiques and summaries, write a cohesive markdown review with sections: Introduction, Themes, Open Problems, References. End with 'FINAL REPORT'."""
Create the agents with a shared llm_config (defined next).
from autogen import AssistantAgent
searcher = AssistantAgent("searcher", system_message=SEARCHER_SYS, llm_config=llm_config)
summarizer = AssistantAgent("summarizer", system_message=SUMMARIZER_SYS, llm_config=llm_config)
critic = AssistantAgent("critic", system_message=CRITIC_SYS, llm_config=llm_config)
synthesizer = AssistantAgent("synthesizer", system_message=SYNTHESIZER_SYS, llm_config=llm_config)
Step 2: Configure the LLM backend
AutoGen expects an OpenAI-style config. Use a gateway that won’t fall over when one provider rate-limits you. Pointing api_base at an OpenAI-compatible endpoint such as n4n.ai gives you automatic fallback across 240+ models and per-token metering without changing agent code.
llm_config = {
"model": "gpt-4o-mini",
"api_key": "YOUR_KEY",
"base_url": "https://api.n4n.ai/v1", # OpenAI-compatible, fails over silently
"temperature": 0.2,
"max_tokens": 2048,
}
If you run locally, swap in lm_studio or ollama base URLs. Keep temperature low; literature synthesis rewards precision over creativity.
Step 3: Give agents a paper retrieval tool
The searcher and summarizer need ground truth. Wrap the arxiv PyPI package in two functions and expose them through a UserProxyAgent.
import arxiv
def arxiv_search(topic: str, max_results: int = 5) -> str:
client = arxiv.Client()
search = arxiv.Search(query=topic, max_results=max_results, sort_by=arxiv.SortCriterion.Relevance)
results = []
for paper in client.results(search):
results.append(f"{paper.entry_id} | {paper.title}")
return "\n".join(results)
def arxiv_fetch(entry_id: str) -> str:
client = arxiv.Client()
search = arxiv.Search(id_list=[entry_id.split("/abs/")[-1]])
paper = next(client.results(search))
return paper.summary
Register them:
from autogen import UserProxyAgent
tool_agent = UserProxyAgent(
"tool_agent",
human_input_mode="NEVER",
code_execution_config=False,
function_map={"arxiv_search": arxiv_search, "arxiv_fetch": arxiv_fetch},
)
The tool_agent never speaks; it only executes registered functions when another agent requests them.
Step 4: Wire up the group chat
AutoGen’s GroupChat cycles messages among participants. Set a max round to avoid runaway loops, and let the synthesizer terminate.
from autogen import GroupChat, GroupChatManager
group = GroupChat(
agents=[searcher, summarizer, critic, synthesizer, tool_agent],
messages=[],
max_round=12,
speaker_selection_method="round_robin",
)
manager = GroupChatManager(group=group, llm_config=llm_config)
task = "Review recent work on retrieval-augmented generation for code search. Use arxiv_search then arxiv_fetch."
tool_agent.initiate_chat(manager, message=task)
The round-robin order forces searcher → summarizer → critic → synthesizer each cycle. When synthesizer prints FINAL REPORT, max_round or a custom is_termination_msg stops the chat.
Termination hook
def is_final(msg):
return "FINAL REPORT" in msg.get("content", "")
group = GroupChat(
agents=[searcher, summarizer, critic, synthesizer, tool_agent],
messages=[],
max_round=12,
speaker_selection_method="round_robin",
is_termination_msg=is_final,
)
Step 5: Run the pipeline and verify output
Execute the script. The manager prints the conversation; redirect it or capture group.messages to write a file.
import json
with open("review_log.json", "w") as f:
json.dump(group.messages, f, indent=2)
Verify success by checking two things:
review_log.jsoncontains a message fromsynthesizerwith the stringFINAL REPORT.- The synthesized markdown has the four required sections.
A quick assertion:
final = [m for m in group.messages if m["name"] == "synthesizer" and "FINAL REPORT" in m["content"]]
assert final, "Synthesizer never produced final report"
assert all(sec in final[-1]["content"] for sec in ["Introduction", "Themes", "Open Problems", "References"])
print("Literature review generated successfully")
Step 6: Harden for real corpora
arXiv abstracts are enough for a survey draft, but full PDFs need extraction. Add a pdf_fetch tool using pymupdf and chunk into 4k-token windows before summarization. Cache tool outputs in a local dict keyed by paper ID to avoid re-fetching; AutoGen won’t do this for you.
Also set max_tokens per call and use provider cache-control hints if your gateway forwards them. For example, n4n.ai honors client routing directives and forwards cache-control, so repeated abstract fetches hit cache instead of burning tokens.
If a provider returns 429, the gateway flips to a backup model; your agent code stays identical. That’s the difference between a demo and a pipeline you can leave running.
What you shipped
You now have an autogen agent team literature review automation flow that discovers papers, summarizes them, critiques the summaries, and writes a structured review. Extend it by adding a fact_checker agent that queries downstream APIs, or swap the arxiv tool for a vector DB over your private corpus. The agent topology is the lever; the tools are interchangeable.