parthib07 commited on
Commit
0feba2f
·
verified ·
1 Parent(s): ea5d1a3

Update src/paper.py

Browse files
Files changed (1) hide show
  1. src/paper.py +86 -82
src/paper.py CHANGED
@@ -11,21 +11,15 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(
11
 
12
  class Agent:
13
  def __init__(self, role: str, goal: str, backstory: str, personality: str = "", llm=None) -> None:
14
- """
15
- Initialize an Agent with role, goal, backstory, personality, and assigned LLM.
16
- """
17
  self.role = role
18
  self.goal = goal
19
  self.backstory = backstory
20
  self.personality = personality
21
- self.tools = []
22
  self.llm = llm
23
 
24
  class Task:
25
  def __init__(self, description: str, agent: Agent, expected_output: str, context=None) -> None:
26
- """
27
- Initialize a Task with its description, the responsible agent, expected output, and optional context.
28
- """
29
  self.description = description
30
  self.agent = agent
31
  self.expected_output = expected_output
@@ -35,136 +29,146 @@ groq_api_key = os.getenv("GROQ_API_KEY")
35
  os.environ['GROQ_API_KEY'] = groq_api_key
36
  if not groq_api_key:
37
  logging.error("GROQ_API_KEY is not set in the environment variables.")
38
- llm = ChatGroq(model="llama-3.3-70b-versatile",max_tokens = 4000)
39
 
40
  literature_research_agent = Agent(
41
  role="Literature Research Agent",
42
- goal="Research and provide a comprehensive review of existing literature on the research topic.",
43
- backstory="An experienced academic researcher specialized in literature reviews and meta-analyses.",
44
- personality="Analytical, thorough, and detail-oriented.",
45
  llm=llm,
46
  )
47
 
48
  outline_agent = Agent(
49
  role="Outline Agent",
50
- goal="Generate a structured and detailed outline for a research paper based on the research topic and literature.",
51
- backstory="A methodical academic planner who organizes research findings into coherent paper structures.",
52
- personality="Organized, systematic, and insightful.",
53
  llm=llm,
54
  )
55
 
56
  draft_writing_agent = Agent(
57
  role="Draft Writing Agent",
58
- goal="Compose a first draft of the research paper based on the literature review and outline.",
59
- backstory="A skilled academic writer capable of synthesizing research findings into well-structured drafts.",
60
- personality="Articulate, precise, and scholarly.",
61
  llm=llm,
62
  )
63
 
64
  citation_agent = Agent(
65
  role="Citation Agent",
66
- goal="Generate a list of relevant citations and references in the required format for the research paper.",
67
- backstory="A detail-oriented bibliographic expert with extensive knowledge of citation standards.",
68
- personality="Meticulous, accurate, and research-savvy.",
69
  llm=llm,
70
  )
71
 
72
  editing_agent = Agent(
73
  role="Editing Agent",
74
- goal="Revise and polish the draft for clarity, coherence, and academic tone.",
75
- backstory="An expert editor skilled in improving academic manuscripts and ensuring high-quality presentation.",
76
- personality="Critical, precise, and supportive.",
77
  llm=llm,
78
  )
79
 
80
  chatbot_agent = Agent(
81
  role="Chatbot Agent",
82
- goal="Engage in interactive conversation to answer queries related to the academic research process.",
83
- backstory="A conversational AI assistant with extensive knowledge in academia and research methodologies.",
84
- personality="Helpful, conversational, and knowledgeable.",
85
  llm=llm,
86
  )
87
 
88
  literature_research_task = Task(
89
- description="""Research academic literature on {topic} considering the keywords {keywords}.
90
-
91
- Please provide:
92
- - A summary of the current state of research,
93
- - Key trends and gaps in the literature,
94
- - Notable studies and their findings,
95
- - Relevant theoretical frameworks and methodologies.
96
- Format the response with bullet points and concise summaries.""",
 
97
  agent=literature_research_agent,
98
- expected_output="""A comprehensive literature review summary covering:
99
- 1. Summary of current research trends
100
- 2. Identification of gaps and controversies
101
- 3. Key studies with brief descriptions
102
- 4. Theoretical frameworks and methodologies used"""
 
103
  )
104
 
105
  outline_task = Task(
106
- description="""Based on the research topic {topic} and literature review findings, generate a detailed outline for a research paper.
107
-
108
- Include sections such as:
109
- - Abstract
110
- - Introduction (including research questions and objectives)
111
- - Literature Review
112
- - Methodology
113
- - Results/Findings
114
- - Discussion
115
- - Conclusion
116
- - References
117
- Format the outline in a structured manner with bullet points and subheadings.""",
 
118
  agent=outline_agent,
119
- expected_output="A structured outline for a research paper including all major sections and key points to cover in each section."
120
  )
121
 
122
  draft_writing_task = Task(
123
- description="""Using the research topic {topic}, the literature review, and the generated outline, compose a first draft of the research paper.
124
-
125
- The draft should include:
126
- - A coherent narrative flow,
127
- - Detailed sections as per the outline,
128
- - Integration of key findings from the literature review.
129
- Ensure the tone is academic and the content is well-organized.""",
 
 
 
130
  agent=draft_writing_agent,
131
- expected_output="A complete first draft of the research paper covering all sections with sufficient academic detail."
132
  )
133
 
134
  citation_task = Task(
135
- description="""Based on the literature review for {topic}, generate a list of key references and citations in APA format.
136
-
137
- Include:
138
- - Author names, publication year, title, and source,
139
- - At least 10 key references relevant to the research topic.
140
- Format the output as a numbered list of citations.""",
 
 
 
141
  agent=citation_agent,
142
- expected_output="A list of 10+ relevant citations in APA format."
143
  )
144
 
145
  editing_task = Task(
146
- description="""Review and edit the draft for clarity, coherence, and academic tone.
147
-
148
- Focus on:
149
- - Improving sentence structure,
150
- - Ensuring logical flow between sections,
151
- - Correcting grammar and stylistic issues,
152
- - Enhancing academic tone.
153
- Provide the polished version of the paper.""",
 
154
  agent=editing_agent,
155
- expected_output="A refined and polished version of the research paper draft."
156
  )
157
 
158
  chatbot_task = Task(
159
- description="Provide a conversational and detailed response to academic research-related queries.",
 
 
 
160
  agent=chatbot_agent,
161
- expected_output="A friendly, informative response addressing the query."
162
  )
163
 
164
  def run_task(task: Task, input_text: str) -> str:
165
- """
166
- Executes the given task using the associated agent's LLM and returns the response content.
167
- """
168
  try:
169
  if not isinstance(task, Task):
170
  raise ValueError(f"Expected 'task' to be an instance of Task, got {type(task)}")
@@ -193,4 +197,4 @@ def run_task(task: Task, input_text: str) -> str:
193
  return response.content
194
  except Exception as e:
195
  logging.error(f"Error in task '{task.agent.role}': {e}")
196
- return f"Error in {task.agent.role}: {e}"
 
11
 
12
  class Agent:
13
  def __init__(self, role: str, goal: str, backstory: str, personality: str = "", llm=None) -> None:
 
 
 
14
  self.role = role
15
  self.goal = goal
16
  self.backstory = backstory
17
  self.personality = personality
18
+ self.tools = []
19
  self.llm = llm
20
 
21
  class Task:
22
  def __init__(self, description: str, agent: Agent, expected_output: str, context=None) -> None:
 
 
 
23
  self.description = description
24
  self.agent = agent
25
  self.expected_output = expected_output
 
29
  os.environ['GROQ_API_KEY'] = groq_api_key
30
  if not groq_api_key:
31
  logging.error("GROQ_API_KEY is not set in the environment variables.")
32
+ llm = ChatGroq(model="llama-3.3-70b-versatile", max_tokens=4000)
33
 
34
  literature_research_agent = Agent(
35
  role="Literature Research Agent",
36
+ goal="Conduct an in-depth review of existing scholarly work relevant to a given research theme.",
37
+ backstory="A seasoned academic investigator skilled at uncovering trends and gaps in published research.",
38
+ personality="Analytical, detail-focused, methodical.",
39
  llm=llm,
40
  )
41
 
42
  outline_agent = Agent(
43
  role="Outline Agent",
44
+ goal="Design a logical, in-depth framework for organizing academic content effectively.",
45
+ backstory="An academic strategist who formulates detailed paper structures aligned with scholarly standards.",
46
+ personality="Structured, organized, and perceptive.",
47
  llm=llm,
48
  )
49
 
50
  draft_writing_agent = Agent(
51
  role="Draft Writing Agent",
52
+ goal="Generate a refined academic draft integrating conceptual and empirical elements seamlessly.",
53
+ backstory="An articulate academic writer who constructs comprehensive and original content based on guidance.",
54
+ personality="Clear, scholarly, and refined.",
55
  llm=llm,
56
  )
57
 
58
  citation_agent = Agent(
59
  role="Citation Agent",
60
+ goal="Curate precise bibliographic references aligned with formatting norms.",
61
+ backstory="A citation expert well-versed in academic documentation and referencing styles.",
62
+ personality="Exacting, thorough, and standards-oriented.",
63
  llm=llm,
64
  )
65
 
66
  editing_agent = Agent(
67
  role="Editing Agent",
68
+ goal="Enhance clarity, style, and scholarly tone while preserving originality and academic rigor.",
69
+ backstory="A language and style expert who ensures manuscripts are professional and naturally flowing.",
70
+ personality="Discerning, articulate, and attentive.",
71
  llm=llm,
72
  )
73
 
74
  chatbot_agent = Agent(
75
  role="Chatbot Agent",
76
+ goal="Answer academic inquiries and assist with research-related tasks in a conversational manner.",
77
+ backstory="A helpful academic consultant embedded in an AI system to support researchers.",
78
+ personality="Conversational, knowledgeable, and responsive.",
79
  llm=llm,
80
  )
81
 
82
  literature_research_task = Task(
83
+ description="""Conduct a contextual review of academic studies pertaining to {topic}, integrating relevant concepts, trends, and methodological approaches using the keywords {keywords}.
84
+
85
+ Avoid generic phrasing and generate a unique articulation by:
86
+ - Summarizing key themes across disciplines,
87
+ - Highlighting research voids and disputed findings,
88
+ - Referring to pivotal studies with paraphrased insights,
89
+ - Discussing theoretical models and research paradigms involved.
90
+ Use informative bullet points and neutral scholarly tone.
91
+ """,
92
  agent=literature_research_agent,
93
+ expected_output="""A well-contextualized literature summary that includes:
94
+ 1. Evolving thematic patterns
95
+ 2. Unresolved issues and gaps
96
+ 3. Specific empirical works (paraphrased)
97
+ 4. Conceptual lenses and methodologies used
98
+ """
99
  )
100
 
101
  outline_task = Task(
102
+ description="""Based on the topic {topic} and derived insights from prior literature, outline a robust research paper structure that reflects academic conventions.
103
+
104
+ Organize into:
105
+ - Concise Abstract
106
+ - Framing Introduction (with aims/questions)
107
+ - Synthesized Literature Review
108
+ - Transparent Methodology
109
+ - Expected or actual Results
110
+ - Interpretative Discussion
111
+ - Summative Conclusion
112
+ - Citations placeholder
113
+ Use bullet points and avoid repeating standard textbook language.
114
+ """,
115
  agent=outline_agent,
116
+ expected_output="A coherent research paper outline formatted with headings, subheadings, and key elements in each part."
117
  )
118
 
119
  draft_writing_task = Task(
120
+ description="""Utilizing the theme {topic}, literature review, and proposed structure, compose an initial draft of an academic paper.
121
+
122
+ Ensure:
123
+ - Flow of argumentation is natural,
124
+ - Terminology varies and mimics human phrasing,
125
+ - Integration of insights without obvious reuse of source phrasing,
126
+ - Academic tone that appears manually crafted.
127
+
128
+ Keep the prose clear but layered, avoiding repetition or formulaic transitions.
129
+ """,
130
  agent=draft_writing_agent,
131
+ expected_output="An academically styled, logically progressive draft that reads as if independently composed."
132
  )
133
 
134
  citation_task = Task(
135
+ description="""Produce APA-style references for scholarly works relating to {topic}, drawing from domain-appropriate journals and books.
136
+
137
+ Use human-like variability in citation content and structure:
138
+ - List 10 or more significant sources,
139
+ - Vary author name formats slightly,
140
+ - Paraphrase titles subtly,
141
+ - Represent realistic and domain-appropriate publishers or journals.
142
+ Output a numbered list with natural inconsistencies typical of human formatting.
143
+ """,
144
  agent=citation_agent,
145
+ expected_output="A diverse and natural-feeling list of scholarly APA references."
146
  )
147
 
148
  editing_task = Task(
149
+ description="""Perform a refined editorial pass over the draft, rewriting where necessary to make it appear distinct from LLM outputs.
150
+
151
+ Steps:
152
+ - Vary syntax and phrasing complexity,
153
+ - Insert nuanced transitions,
154
+ - Restructure paragraphs subtly,
155
+ - Remove indicators of AI authorship.
156
+ Output the fully edited and naturally flowing version.
157
+ """,
158
  agent=editing_agent,
159
+ expected_output="A polished, stylistically diverse version that avoids detectable patterns of machine-generated content."
160
  )
161
 
162
  chatbot_task = Task(
163
+ description="""Engage in research-related academic discussions or answer questions while maintaining a tone that is informal but intellectually competent.
164
+
165
+ Ensure responses sound helpful, nuanced, and naturally composed.
166
+ """,
167
  agent=chatbot_agent,
168
+ expected_output="Conversational yet knowledgeable academic assistance."
169
  )
170
 
171
  def run_task(task: Task, input_text: str) -> str:
 
 
 
172
  try:
173
  if not isinstance(task, Task):
174
  raise ValueError(f"Expected 'task' to be an instance of Task, got {type(task)}")
 
197
  return response.content
198
  except Exception as e:
199
  logging.error(f"Error in task '{task.agent.role}': {e}")
200
+ return f"Error in {task.agent.role}: {e}"