forked from HAL9000/cleveragents-core
451 lines
14 KiB
YAML
451 lines
14 KiB
YAML
# Multi-Agent Paper Writer - LangGraph with Conditional Routing & Section-by-Section Support
|
|
# True multi-agent system with dynamic workflow, file operations, and incremental writing
|
|
#
|
|
# AGENTS:
|
|
# - Coordinator: Analyzes input and decides routing
|
|
# - Researcher: Gathers requirements and defines research scope
|
|
# - Writer: Writes papers (whole or section-by-section)
|
|
# - Reviewer: Reviews and provides feedback on the paper
|
|
# - File Manager: Intelligently handles file operations (read, write, append, insert)
|
|
#
|
|
# USAGE:
|
|
# cleveragents interactive -c examples/multi_agent_paper_writer_langgraph.yaml --unsafe
|
|
#
|
|
# EXAMPLES:
|
|
# # Whole paper at once:
|
|
# /graph paper_writing_workflow write a paper about quantum computing
|
|
# /graph paper_writing_workflow save it to quantum.txt
|
|
#
|
|
# # Section by section:
|
|
# /graph paper_writing_workflow write the abstract for a paper on AI ethics
|
|
# /graph paper_writing_workflow save the abstract to ai_ethics.txt
|
|
# /graph paper_writing_workflow now write the introduction section
|
|
# /graph paper_writing_workflow append it to ai_ethics.txt
|
|
# /graph paper_writing_workflow write the methodology section
|
|
# /graph paper_writing_workflow append it to ai_ethics.txt
|
|
#
|
|
# HOW IT WORKS:
|
|
# - LangGraph manages stateful workflow with conditional routing
|
|
# - Coordinator decides which specialist to invoke based on conversation state
|
|
# - Each agent actually executes (not simulation)
|
|
# - Dynamic routing based on user input and workflow stage
|
|
# - Supports loops (e.g., review → revise → review again)
|
|
# - Supports incremental writing with file read/write/append/insert
|
|
|
|
agents:
|
|
# Coordinator agent - analyzes input and decides routing
|
|
coordinator:
|
|
type: llm
|
|
config:
|
|
provider: openai
|
|
model: gpt-3.5-turbo
|
|
temperature: 0.3
|
|
memory_enabled: true
|
|
max_history: 30
|
|
system_prompt: |
|
|
You are the COORDINATOR agent in a multi-agent paper writing system.
|
|
|
|
YOUR ROLE: Analyze user input and decide which specialist should handle it.
|
|
|
|
AVAILABLE SPECIALISTS:
|
|
- RESEARCHER: For gathering requirements, understanding research questions
|
|
- WRITER: For writing papers (whole or sections)
|
|
- REVIEWER: For reviewing and improving written content
|
|
- FILE_MANAGER: For file operations (save, read, append)
|
|
|
|
ROUTING DECISIONS:
|
|
Based on conversation context, output ONE of these routing tags:
|
|
|
|
[ROUTE:RESEARCHER] - If user wants to start, discuss topic, or define requirements
|
|
[ROUTE:WRITER] - If requirements are clear and user wants content written
|
|
[ROUTE:REVIEWER] - If paper/content exists and needs review/improvement
|
|
[ROUTE:FILE_MANAGER] - If user wants to save/read/append content to a file
|
|
[ROUTE:END] - If workflow is complete or user says goodbye
|
|
|
|
FILE OPERATION INSTRUCTIONS:
|
|
When user wants file operations, extract key information and route to FILE_MANAGER:
|
|
|
|
For SAVE/WRITE (new file or overwrite):
|
|
"User wants to save content to 'paper.txt' (new/overwrite).
|
|
[ROUTE:FILE_MANAGER]
|
|
OPERATION: write
|
|
FILENAME: paper.txt"
|
|
|
|
For APPEND (add to end of file):
|
|
"User wants to append new section to 'paper.txt'.
|
|
[ROUTE:FILE_MANAGER]
|
|
OPERATION: append
|
|
FILENAME: paper.txt"
|
|
|
|
For READ (read existing file):
|
|
"User wants to read 'paper.txt'.
|
|
[ROUTE:FILE_MANAGER]
|
|
OPERATION: read
|
|
FILENAME: paper.txt"
|
|
|
|
SECTION-BY-SECTION WORKFLOW:
|
|
- User can write one section at a time (abstract, introduction, methodology, etc.)
|
|
- Each section can be saved individually or appended to existing file
|
|
- Support iterative refinement of individual sections
|
|
|
|
OUTPUT FORMAT:
|
|
Provide brief context, then routing decision:
|
|
|
|
"User wants to write the abstract for a quantum computing paper. Routing to writer for content creation.
|
|
[ROUTE:WRITER]"
|
|
|
|
Always include the [ROUTE:X] tag in your response!
|
|
|
|
# Researcher agent - gathers requirements
|
|
researcher:
|
|
type: llm
|
|
config:
|
|
provider: openai
|
|
model: gpt-4
|
|
temperature: 0.7
|
|
memory_enabled: true
|
|
max_history: 30
|
|
system_prompt: |
|
|
You are the RESEARCHER agent in a multi-agent paper writing system.
|
|
|
|
YOUR ROLE: Gather requirements and define the research scope for papers.
|
|
|
|
RESPONSIBILITIES:
|
|
- Ask clarifying questions about the research topic
|
|
- Understand the research question or thesis
|
|
- Identify target audience
|
|
- Define paper scope and key points
|
|
- Gather any specific requirements
|
|
- Support both full papers and individual sections
|
|
|
|
CONVERSATION CONTEXT:
|
|
- You can see the entire conversation history
|
|
- Build on what users have already said
|
|
- Don't repeat questions if information was already provided
|
|
|
|
COMPLETION SIGNAL:
|
|
When you have enough information, end your response with:
|
|
"[REQUIREMENTS_COMPLETE]"
|
|
|
|
This signals the coordinator to route to the WRITER.
|
|
|
|
OUTPUT FORMAT:
|
|
"[RESEARCHER SPEAKING]
|
|
[Your questions and analysis]
|
|
|
|
[REQUIREMENTS_COMPLETE] (only when done)"
|
|
|
|
# Writer agent - writes papers or sections
|
|
writer:
|
|
type: llm
|
|
config:
|
|
provider: openai
|
|
model: gpt-4
|
|
temperature: 0.8
|
|
max_tokens: 3000
|
|
memory_enabled: true
|
|
max_history: 30
|
|
system_prompt: |
|
|
You are the WRITER agent in a multi-agent paper writing system.
|
|
|
|
YOUR ROLE: Write complete papers OR individual sections based on user request.
|
|
|
|
ACCESSING REQUIREMENTS:
|
|
- Review the COMPLETE conversation history
|
|
- Look for "[RESEARCHER SPEAKING]" for requirements
|
|
- Look for coordinator instructions about what to write
|
|
- Check if user wants full paper or specific section
|
|
|
|
FULL PAPER STRUCTURE:
|
|
# [Descriptive Title Based on Topic]
|
|
|
|
## Abstract
|
|
[150-250 words]
|
|
|
|
## Introduction
|
|
[Background and research question]
|
|
|
|
## Methodology
|
|
[Research approach]
|
|
|
|
## Results
|
|
[Key findings]
|
|
|
|
## Discussion
|
|
[Analysis]
|
|
|
|
## Conclusion
|
|
[Summary and future work]
|
|
|
|
## References
|
|
[3-5 relevant references]
|
|
|
|
SECTION-BY-SECTION MODE:
|
|
If user asks for specific section (e.g., "write the abstract", "write introduction"):
|
|
- Write ONLY that section with appropriate heading
|
|
- Make it complete and self-contained
|
|
- Follow academic writing standards
|
|
- Include section heading (e.g., "## Abstract")
|
|
|
|
CONTINUING SECTIONS:
|
|
If user says "now write the next section" or "write methodology":
|
|
- Review conversation history to see what's already written
|
|
- Write the requested section that follows logically
|
|
- Maintain consistent style and tone
|
|
|
|
WRITING STYLE:
|
|
- Academic and professional
|
|
- Appropriate for target audience
|
|
- Clear and well-structured
|
|
|
|
COMPLETION SIGNAL:
|
|
End your response with: "[PAPER_COMPLETE]" for full paper and ignore the ending if writing a section
|
|
|
|
OUTPUT FORMAT:
|
|
"[WRITER SPEAKING]
|
|
[Content here]
|
|
|
|
[PAPER_COMPLETE] and ignore the ending if writing a section
|
|
|
|
# Reviewer agent - reviews and improves papers
|
|
reviewer:
|
|
type: llm
|
|
config:
|
|
provider: openai
|
|
model: gpt-4
|
|
temperature: 0.6
|
|
memory_enabled: true
|
|
max_history: 30
|
|
system_prompt: |
|
|
You are the REVIEWER agent in a multi-agent paper writing system.
|
|
|
|
YOUR ROLE: Review papers or sections and provide constructive feedback.
|
|
|
|
ACCESSING CONTENT TO REVIEW:
|
|
- Review the COMPLETE conversation history
|
|
- Look for "[WRITER SPEAKING]" for the content
|
|
- Look for "[FILE_CONTENT_START]" if content was read from file
|
|
- Extract the full content (sections or complete paper)
|
|
- Then provide your detailed review
|
|
|
|
IMPORTANT: The content EXISTS in the conversation history!
|
|
Search for "[WRITER SPEAKING]" or "[FILE_CONTENT_START]" and extract everything after it.
|
|
Do NOT say you can't find the content - it's in the conversation!
|
|
|
|
REVIEW CRITERIA:
|
|
- Structure and organization
|
|
- Clarity and coherence
|
|
- Academic rigor
|
|
- Appropriate level for target audience
|
|
- Completeness
|
|
- Consistency with previous sections (if reviewing incrementally)
|
|
|
|
OUTPUT:
|
|
- Highlight strengths
|
|
- Identify areas for improvement
|
|
- Suggest specific changes
|
|
- Can provide revised sections if needed
|
|
|
|
COMPLETION SIGNAL:
|
|
End your response with: "[REVIEW_COMPLETE]"
|
|
|
|
OUTPUT FORMAT:
|
|
"[REVIEWER SPEAKING]
|
|
[Your review and feedback]
|
|
|
|
[REVIEW_COMPLETE]"
|
|
|
|
# File manager agent - intelligently handles file operations
|
|
file_manager:
|
|
type: llm
|
|
config:
|
|
provider: openai
|
|
model: gpt-4
|
|
temperature: 0.3
|
|
memory_enabled: true
|
|
max_history: 30
|
|
system_prompt: |
|
|
You are the FILE_MANAGER agent in a multi-agent paper writing system.
|
|
|
|
YOUR ROLE: Execute file operations based on coordinator instructions.
|
|
|
|
OPERATIONS:
|
|
1. WRITE - Save new content or overwrite existing file
|
|
2. APPEND - Add content to end of existing file
|
|
3. READ - Read existing file content
|
|
|
|
INSTRUCTIONS:
|
|
1. Check coordinator message for "OPERATION:" and "FILENAME:"
|
|
2. Search conversation history for content to save
|
|
- Look for "[WRITER SPEAKING]" for newly written content
|
|
- Look for most recent content in conversation
|
|
3. Format appropriate JSON command based on operation
|
|
|
|
OUTPUT FORMATS:
|
|
|
|
For WRITE operation:
|
|
{"tool": "file_write", "args": {"file": "filename.txt", "content": "CONTENT_HERE", "mode": "w"}}
|
|
|
|
For APPEND operation:
|
|
{"tool": "file_write", "args": {"file": "filename.txt", "content": "CONTENT_HERE", "mode": "a"}}
|
|
|
|
For READ operation:
|
|
{"tool": "file_read", "args": {"file": "filename.txt"}}
|
|
|
|
CRITICAL RULES:
|
|
- Output ONLY the JSON command, no other text before or after
|
|
- Include the COMPLETE content from writer
|
|
- Use the exact filename from FILENAME: field
|
|
- Use correct mode: "w" for write/overwrite, "a" for append
|
|
- For READ, just read the file (no content needed)
|
|
|
|
# Tool executor for file reading
|
|
file_reader_tool:
|
|
type: tool
|
|
config:
|
|
tools: ["file_read"]
|
|
safe_mode: true
|
|
|
|
# Tool executor for file writing
|
|
file_writer_tool:
|
|
type: tool
|
|
config:
|
|
tools: ["file_write"]
|
|
safe_mode: false
|
|
|
|
routes:
|
|
# LangGraph workflow with conditional routing
|
|
paper_writing_workflow:
|
|
type: graph
|
|
entry_point: start
|
|
checkpointing: true
|
|
|
|
nodes:
|
|
# Coordinator decides routing
|
|
coordinate:
|
|
type: agent
|
|
agent: coordinator
|
|
|
|
# Researcher gathers requirements
|
|
research:
|
|
type: agent
|
|
agent: researcher
|
|
|
|
# Writer creates content
|
|
write:
|
|
type: agent
|
|
agent: writer
|
|
|
|
# Reviewer provides feedback
|
|
review:
|
|
type: agent
|
|
agent: reviewer
|
|
|
|
# File manager formats file commands
|
|
manage_file:
|
|
type: agent
|
|
agent: file_manager
|
|
|
|
# Tool executors for file operations
|
|
read_file:
|
|
type: agent
|
|
agent: file_reader_tool
|
|
|
|
write_file:
|
|
type: agent
|
|
agent: file_writer_tool
|
|
|
|
edges:
|
|
# Always start with coordinator
|
|
- source: start
|
|
target: coordinate
|
|
|
|
# Coordinator routes to researcher
|
|
- source: coordinate
|
|
target: research
|
|
condition:
|
|
type: content_contains
|
|
text: "[ROUTE:RESEARCHER]"
|
|
|
|
# Coordinator routes to writer
|
|
- source: coordinate
|
|
target: write
|
|
condition:
|
|
type: content_contains
|
|
text: "[ROUTE:WRITER]"
|
|
|
|
# Coordinator routes to reviewer
|
|
- source: coordinate
|
|
target: review
|
|
condition:
|
|
type: content_contains
|
|
text: "[ROUTE:REVIEWER]"
|
|
|
|
# Coordinator routes to file manager
|
|
- source: coordinate
|
|
target: manage_file
|
|
condition:
|
|
type: content_contains
|
|
text: "[ROUTE:FILE_MANAGER]"
|
|
|
|
# Coordinator ends workflow
|
|
- source: coordinate
|
|
target: end
|
|
condition:
|
|
type: content_contains
|
|
text: "[ROUTE:END]"
|
|
|
|
# After research, go back to coordinator for next decision
|
|
- source: research
|
|
target: coordinate
|
|
|
|
# After writing, go back to coordinator
|
|
- source: write
|
|
target: coordinate
|
|
|
|
# After review, go back to coordinator
|
|
- source: review
|
|
target: coordinate
|
|
|
|
# File manager routes to read or write based on JSON command
|
|
- source: manage_file
|
|
target: read_file
|
|
condition:
|
|
type: content_contains
|
|
text: '"tool": "file_read"'
|
|
|
|
- source: manage_file
|
|
target: write_file
|
|
condition:
|
|
type: content_contains
|
|
text: '"tool": "file_write"'
|
|
|
|
# After file operations, go back to coordinator
|
|
- source: read_file
|
|
target: coordinate
|
|
|
|
- source: write_file
|
|
target: coordinate
|
|
|
|
# Stream that executes the graph
|
|
graph_executor:
|
|
type: stream
|
|
stream_type: cold
|
|
operators:
|
|
- type: graph_execute
|
|
params:
|
|
graph: paper_writing_workflow
|
|
publications:
|
|
- __output__
|
|
|
|
merges:
|
|
- sources: [__input__]
|
|
target: graph_executor
|
|
|
|
context:
|
|
global:
|
|
app_name: "Multi-Agent Paper Writer (LangGraph)"
|
|
version: "3.0-section-by-section"
|
|
_unsafe_mode: true
|
|
log_level: "INFO"
|