Skip to content

Commit 241405a

Browse files
committed
2 parents 654c394 + d7706f7 commit 241405a

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

api/research_api.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,16 @@ def post(self):
7272

7373
# Construct API response
7474
return {
75-
"topic": structured_response.topic, # Research topic title
76-
"summary": html_summary, # HTML-formatted content
77-
"sources": structured_response.sources, # Reference URLs
78-
"tools": structured_response.tools_used, # AI tools utilized
79-
"download_link": f"/download/{filename}", # File access endpoint
75+
"topic": structured_response.topic,
76+
# Research topic title
77+
"summary": html_summary,
78+
# HTML-formatted content
79+
"sources": structured_response.sources,
80+
# Reference URLs
81+
"tools": structured_response.tools_used,
82+
# AI tools utilized
83+
"download_link": f"/download/{filename}",
84+
# File access endpoint
8085
"processing_time": round(
8186
time.time() - start_time, 2
8287
), # Duration in seconds
@@ -87,7 +92,8 @@ def post(self):
8792
print("Error in /research:", e) # Server-side logging
8893
return {
8994
"error": str(e), # Developer-facing message
90-
"details": "Check server logs for more information", # User guidance
95+
"details": "Check server logs for more information",
96+
# User guidance
9197
}, 500 # HTTP 500 Internal Server Error
9298

9399

@@ -109,7 +115,8 @@ def get(self, filename):
109115
- Enable authentication in production
110116
"""
111117
# Configure secure download path
112-
downloads_folder = os.path.join(os.getcwd(), "outputs") # Isolate files
118+
downloads_folder = os.path.join(os.getcwd(), "outputs")
119+
# Isolate files
113120

114121
# Safe file serving with Flask's send_from_directory
115122
return send_from_directory(
@@ -122,7 +129,7 @@ def get(self, filename):
122129
"""
123130
API Security Notes:
124131
1. Authentication: Currently disabled (enable method_decorators for JWT)
125-
2. Input Validation:
132+
2. Input Validation:
126133
- Research endpoint validates query exists
127134
- Download endpoint needs filename sanitization
128135
3. File Security:

tools.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""
22
AI Research Agent - Core Tools Module
33
4-
This module implements essential research capabilities for an AI assistant system,
5-
integrating web search, Wikipedia access, and persistent storage functionality.
4+
This module implements essential research capabilities for an AI assistant
5+
system, integrating web search, Wikipedia access, and persistent storage
6+
functionality.
67
"""
78

89
# Import LangChain components for knowledge retrieval and tool integration
@@ -85,7 +86,7 @@ def save_to_txt(data: str, filename: str = "research_output.txt"):
8586
8687
Usage Flow:
8788
1. Agent uses search_tool for initial investigation
88-
2. Verifies facts with wiki_tool
89+
2. Verifies facts with wiki_tool
8990
3. Saves validated findings with save_tool
9091
4. Process repeats for iterative research
9192
"""

utils/agent_setup.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,36 @@ class ResearchResponse(BaseModel):
7373
[
7474
(
7575
"system",
76-
"""You are a research assistant that will help generate a research paper.
77-
Answer the user query and use necessary tools.
78-
Wrap the output in this format and provide no other text\n{format_instructions}""",
76+
"""You are a research assistant that will
77+
help generate a research paper. Answer the
78+
user query and use the necessary tools. Wrap
79+
the output in this format and provide no
80+
other text\n{format_instructions}""",
7981
),
80-
("placeholder", "{chat_history}"), # Conversation context storage
81-
("human", "{query}"), # User input placeholder
82-
("placeholder", "{agent_scratchpad}"), # Agent's working memory
82+
("placeholder", "{chat_history}"),
83+
# Conversation context storage
84+
("human", "{query}"),
85+
# User input placeholder
86+
("placeholder", "{agent_scratchpad}"),
87+
# Agent's working memory
8388
]
8489
).partial(format_instructions=parser.get_format_instructions())
8590

8691
# -----------------------------------------------------------------------------
8792
# Tool Configuration
8893
# -----------------------------------------------------------------------------
8994
tools = [search_tool, save_tool] # Core research tools
90-
# tools = [search_tool, wiki_tool, save_tool] # Uncomment for Wikipedia integration
95+
# tools = [search_tool, wiki_tool, save_tool]
96+
# Uncomment for Wikipedia integration
9197

9298
# -----------------------------------------------------------------------------
9399
# Agent Assembly
94100
# -----------------------------------------------------------------------------
95101
agent = create_tool_calling_agent(llm=llm, prompt=prompt, tools=tools)
96102

97103
agent_executor = AgentExecutor(
98-
agent=agent, tools=tools, verbose=True # Enable detailed execution logging
104+
agent=agent, tools=tools, verbose=True
105+
# Enable detailed execution logging
99106
)
100107

101108
"""

0 commit comments

Comments
 (0)