Wire up all agents with LLM calls

- Worldsmith, Character Lead, Voice, Editor agents now call LLM
- All nonfiction agents wired (Researcher, Analyst, Writer, FactChecker, Editor)
- Orchestrator fully wired with agent pipeline
- Add python-dotenv dependency
This commit is contained in:
2026-03-12 18:42:15 +00:00
parent e151cee69f
commit dec5aae09a
7 changed files with 584 additions and 462 deletions
+110 -182
View File
@@ -1,14 +1,16 @@
"""Nonfiction agents for Opus Orchestrator.
Based on Nonfiction Fortress Level 1-3 methodology.
All agents are wired up to call the LLM.
"""
# Researcher Agent
from typing import Any
from opus_orchestrator.agents.base import AgentResponse, BaseAgent
# ============== RESEARCHER AGENT ==============
RESEARCHER_SYSTEM_PROMPT = """## Role: The Researcher
You are The Researcher — responsible for information gathering, source finding, fact collection, and data mining.
@@ -36,21 +38,13 @@ You are The Researcher — responsible for information gathering, source finding
## Source Types and Credibility
**Primary Sources**
- Original data
- First-hand accounts
- Official documents
- Expert interviews
- Original data, First-hand accounts, Official documents, Expert interviews
**Secondary Sources**
- Academic papers
- News reports
- Books by experts
- Documentaries
- Academic papers, News reports, Books by experts, Documentaries
**Tertiary Sources**
- Encyclopedias
- Aggregated data
- Popular summaries
- Encyclopedias, Aggregated data, Popular summaries
## Source Evaluation Criteria
@@ -61,13 +55,6 @@ You are The Researcher — responsible for information gathering, source finding
| Recency | 20% |
| Reproducibility | 15% |
| Peer review | 10% |
## Quality Standards
- Every fact must be sourced
- Sources must be evaluated for credibility
- Bias must be documented
- Contradictions must be flagged
"""
@@ -91,24 +78,31 @@ class ResearcherAgent(BaseAgent):
Conduct research on: {topic}
## Research Questions
{chr(10).join(f"- {q}" for q in research_questions) if research_questions else "Find comprehensive information on the topic."}
{chr(10).join(f'- {q}' for q in research_questions) if research_questions else 'Find comprehensive information on the topic.'}
## Guidelines
Follow the Researcher methodology from your system prompt.
Document all sources with citations.
Follow the Researcher methodology. Document all sources with citations.
Provide a comprehensive research dossier.
"""
return AgentResponse(
success=True,
output={"status": "research_complete"},
metadata={"role": "Researcher", "topic": topic},
)
try:
result = await self.call_llm(
system_prompt=self.build_system_prompt(context),
user_prompt=user_prompt,
)
return AgentResponse(
success=True,
output=result,
metadata={"role": "Researcher", "topic": topic},
)
except Exception as e:
return AgentResponse(success=False, output=None, error=str(e), metadata={"role": "Researcher"})
# Analyst Agent
# ============== ANALYST AGENT ==============
ANALYST_SYSTEM_PROMPT = """## Role: The Analyst
You are The Analyst — responsible for information synthesis, pattern identification, argument construction, and insight extraction.
@@ -116,22 +110,13 @@ You are The Analyst — responsible for information synthesis, pattern identific
## Core Responsibilities
1. **Pattern Identification**
- Theme extraction
- Trend analysis
- Correlation discovery
- Anomaly detection
- Theme extraction, Trend analysis, Correlation discovery, Anomaly detection
2. **Argument Construction**
- Claim development
- Evidence selection
- Reasoning flow
- Counterargument anticipation
- Claim development, Evidence selection, Reasoning flow, Counterargument anticipation
3. **Insight Generation**
- Key takeaways
- Implications
- Connections
- Novel perspectives
- Key takeaways, Implications, Connections, Novel perspectives
## Argument Structure
@@ -141,29 +126,9 @@ You are The Analyst — responsible for information synthesis, pattern identific
- **Counterargument**: Acknowledged opposition
- **Rebuttal**: Response to opposition
## Argument Types
- **Causal**: A causes B
- **Comparative**: A is better/worse than B
- **Definition**: A means B
- **Historical**: A led to B
- **Predictive**: A will cause B
## Logical Fallacies to Avoid
- Ad hominem
- Straw man
- False dilemma
- Slippery slope
- Circular reasoning
- Hasty generalization
## Quality Standards
- All claims must be evidence-based
- Logical fallacies must be avoided
- Counterarguments must be addressed
- Implications must be explored
Ad hominem, Straw man, False dilemma, Slippery slope, Circular reasoning, Hasty generalization
"""
@@ -180,7 +145,7 @@ class AnalystAgent(BaseAgent):
async def execute(self, input_data: Any, context: dict[str, Any]) -> AgentResponse:
"""Execute analysis task."""
research_data = input_data.get("research_data", {})
research_data = input_data.get("research_data", "")
topic = input_data.get("topic", "")
user_prompt = f"""## Task
@@ -197,14 +162,23 @@ Follow the Analyst methodology. Construct clear arguments with evidence.
Address counterarguments. Generate insights.
"""
return AgentResponse(
success=True,
output={"status": "analysis_complete"},
metadata={"role": "Analyst", "topic": topic},
)
try:
result = await self.call_llm(
system_prompt=self.build_system_prompt(context),
user_prompt=user_prompt,
)
return AgentResponse(
success=True,
output=result,
metadata={"role": "Analyst", "topic": topic},
)
except Exception as e:
return AgentResponse(success=False, output=None, error=str(e), metadata={"role": "Analyst"})
# Writer Agent (Nonfiction)
# ============== WRITER AGENT ==============
NONFICTION_WRITER_SYSTEM_PROMPT = """## Role: The Writer (Nonfiction)
You are The Writer — responsible for prose generation, clear explanation, engaging narrative, and voice development.
@@ -212,22 +186,13 @@ You are The Writer — responsible for prose generation, clear explanation, enga
## Core Responsibilities
1. **Prose Generation**
- Clear explanations
- Engaging narrative
- Accessible language
- Varied structure
- Clear explanations, Engaging narrative, Accessible language, Varied structure
2. **Voice Development**
- Authoritative tone
- Expert positioning
- Reader engagement
- Credibility building
- Authoritative tone, Expert positioning, Reader engagement, Credibility building
3. **Content Structuring**
- Introduction hooks
- Body organization
- Conclusion synthesis
- Transition flow
- Introduction hooks, Body organization, Conclusion synthesis, Transition flow
## Authorial Voice Elements
@@ -236,22 +201,6 @@ You are The Writer — responsible for prose generation, clear explanation, enga
- **Clarity**: Accessible explanations
- **Engagement**: Compelling narrative
- **Credibility**: Transparent sourcing
## Tone Calibration
| Genre | Tone |
|-------|------|
| Academic | Formal, precise |
| Popular | Accessible, lively |
| Professional | Practical, direct |
| Memoir | Personal, reflective |
## Quality Standards
- Complex ideas must be accessible
- Arguments must flow logically
- Voice must be consistent
- Readers must remain engaged
"""
@@ -268,7 +217,7 @@ class NonfictionWriterAgent(BaseAgent):
async def execute(self, input_data: Any, context: dict[str, Any]) -> AgentResponse:
"""Execute nonfiction writing task."""
analysis = input_data.get("analysis", {})
analysis = input_data.get("analysis", "")
chapter_spec = input_data.get("chapter_spec", {})
user_prompt = f"""## Task
@@ -277,25 +226,38 @@ Write a nonfiction chapter based on the following analysis:
## Chapter Specification
{chapter_spec}
- Title: {chapter_spec.get('title', 'Untitled')}
- Word Count Target: {chapter_spec.get('word_count_target', 2000)}
## Analysis
## Analysis/Content
{analysis}
## Guidelines
Follow the Nonfiction Writer methodology. Maintain authoritative yet accessible tone.
Structure with clear introduction, body, and conclusion.
"""
return AgentResponse(
success=True,
output={"status": "chapter_written"},
metadata={"role": "Nonfiction Writer"},
)
try:
result = await self.call_llm(
system_prompt=self.build_system_prompt(context),
user_prompt=user_prompt,
)
word_count = len(result.split())
return AgentResponse(
success=True,
output={"content": result, "word_count": word_count},
metadata={"role": "Nonfiction Writer", "word_count": word_count},
)
except Exception as e:
return AgentResponse(success=False, output=None, error=str(e), metadata={"role": "Nonfiction Writer"})
# Fact Checker Agent
# ============== FACT CHECKER AGENT ==============
FACT_CHECKER_SYSTEM_PROMPT = """## Role: The Fact-Checker
You are The Fact-Checker — responsible for verification, citation validation, claim verification, and accuracy audit.
@@ -303,55 +265,19 @@ You are The Fact-Checker — responsible for verification, citation validation,
## Core Responsibilities
1. **Claim Verification**
- Factual accuracy checking
- Quote verification
- Data validation
- Source cross-referencing
- Factual accuracy checking, Quote verification, Data validation, Source cross-referencing
2. **Citation Validation**
- Source credibility
- Citation format
- Attribution accuracy
- Access verification
- Source credibility, Citation format, Attribution accuracy, Access verification
3. **Accuracy Audit**
- Comprehensive review
- Error identification
- Correction suggestions
- Confidence scoring
- Comprehensive review, Error identification, Correction suggestions, Confidence scoring
## Verification Protocol
**Level 1: Self-check**
- Re-read own claims
- Check math and dates
- Verify quotes
**Level 2: Source verification**
- Return to original sources
- Confirm context
- Check for misquotes
**Level 3: External review**
- Fact-checker agent review
- Expert review
- Peer review
## Quality Standards
| Category | Standard |
|----------|----------|
| Factual claims | 100% verified |
| Quotes | Exact match |
| Data | Source cited |
| Attribution | Clear ownership |
## Accuracy Metrics
- All claims must be verifiable
- Sources must be credible
- Data must be accurately represented
- Attribution must be complete
**Level 1**: Re-read claims, check math/dates, verify quotes
**Level 2**: Return to original sources, confirm context, check for misquotes
**Level 3**: External review, Expert review, Peer review
"""
@@ -377,24 +303,33 @@ Fact-check the following content:
{content}
## Sources
## Sources to Verify Against
{chr(10).join(f"- {s}" for s in sources) if sources else "Verify against available sources."}
{chr(10).join(f'- {s}' for s in sources) if sources else 'Verify factual claims against your knowledge.'}
## Guidelines
Follow the Fact-Checker methodology. Verify all claims, quotes, and data.
Provide confidence scores for each item.
Provide confidence scores and flag any issues.
"""
return AgentResponse(
success=True,
output={"status": "fact_check_complete"},
metadata={"role": "Fact-Checker"},
)
try:
result = await self.call_llm(
system_prompt=self.build_system_prompt(context),
user_prompt=user_prompt,
)
return AgentResponse(
success=True,
output=result,
metadata={"role": "Fact-Checker"},
)
except Exception as e:
return AgentResponse(success=False, output=None, error=str(e), metadata={"role": "Fact-Checker"})
# Nonfiction Editor Agent
# ============== EDITOR AGENT (NONFICTION) ==============
NONFICTION_EDITOR_SYSTEM_PROMPT = """## Role: The Editor (Nonfiction)
You are The Editor — responsible for quality control, structure assessment, clarity evaluation, and style consistency.
@@ -402,22 +337,13 @@ You are The Editor — responsible for quality control, structure assessment, cl
## Core Responsibilities
1. **Structure Assessment**
- Argument flow
- Chapter organization
- Information hierarchy
- Transitions
- Argument flow, Chapter organization, Information hierarchy, Transitions
2. **Clarity Evaluation**
- Readability
- Explanatory quality
- Jargon usage
- Complex sentence identification
- Readability, Explanatory quality, Jargon usage, Complex sentence identification
3. **Style Consistency**
- Tone uniformity
- Formatting standards
- Citation style
- Voice maintenance
- Tone uniformity, Formatting standards, Citation style, Voice maintenance
## Clarity Metrics
@@ -432,13 +358,6 @@ You are The Editor — responsible for quality control, structure assessment, cl
- Questions raised and answered
- Examples and stories included
- Visual elements used appropriately
## Quality Standards
- Structure must support arguments
- Clarity must enable comprehension
- Style must maintain credibility
- Engagement must sustain interest
"""
@@ -467,10 +386,19 @@ Perform editorial review on:
Follow the Nonfiction Editor methodology.
Assess structure, clarity, style, and engagement.
Provide specific, actionable feedback.
"""
return AgentResponse(
success=True,
output={"status": "editorial_review_complete"},
metadata={"role": "Nonfiction Editor"},
)
try:
result = await self.call_llm(
system_prompt=self.build_system_prompt(context),
user_prompt=user_prompt,
)
return AgentResponse(
success=True,
output=result,
metadata={"role": "Nonfiction Editor"},
)
except Exception as e:
return AgentResponse(success=False, output=None, error=str(e), metadata={"role": "Nonfiction Editor"})