The arXiv Researcher Agent is an advanced AI research assistant that combines OpenAI Agents with Memori memory integration. It searches for academic papers on arXiv, generates comprehensive research reports, and maintains persistent memory of all research sessions for future reference.
from agents import Agent, function_tool, OpenAIChatCompletionsModelfrom memori import Memori, create_memory_toolfrom tavily import TavilyClientimport os# Initialize Tavily for arXiv searchtavily_client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))# Create memory search tool@function_tooldef search_memory(query: str) -> MemorySearchResult: """Search the agent's memory for past research information.""" result = memory_tool.execute(query=query.strip()) found_memories = bool( result and "No relevant memories found" not in result and "Error" not in result ) return MemorySearchResult( query=query, results=result if result else "No relevant memories found", found_memories=found_memories )# Create arXiv search tool@function_tooldef search_arxiv(query: str) -> ArxivSearchResult: """Search for research papers on arXiv.""" search_query = f"arXiv research papers {query} latest developments academic research" # Perform Tavily search with academic domains search_result = tavily_client.search( query=search_query, search_depth="advanced", include_domains=["arxiv.org", "scholar.google.com", "researchgate.net"], max_results=10 ) # Process and format results papers = [] for result in search_result["results"][:5]: papers.append({ "title": result.get("title", "No title"), "url": result.get("url", ""), "summary": result.get("content", "")[:200] + "..." }) return ArxivSearchResult( query=query, results=format_papers(papers), found_papers=len(papers) > 0 )
from textwrap import dedentresearch_agent = Agent( name="ArXiv Research Agent", model=model, instructions=dedent( """ You are Professor X-1000, a distinguished AI research scientist with MEMORY CAPABILITIES! 🧠 Your enhanced abilities: - Advanced research using arXiv paper search via Tavily - Persistent memory of all research sessions - Ability to reference and build upon previous research - Creating comprehensive, fact-based research reports RESEARCH WORKFLOW: 1. FIRST: Use search_memory to find any related previous research 2. Use search_arxiv to find relevant research papers 3. Analyze and cross-reference sources 4. If you find relevant previous research, mention how this builds upon it 5. Structure your report following academic standards 6. Include only verifiable facts with proper citations 7. End with actionable takeaways and future implications Always mention if you're building upon previous research sessions! """ ), tools=[search_memory, search_arxiv],)
memory_agent = Agent( name="Research Memory Assistant", instructions=dedent( """ You are the Research Memory Assistant, specialized in helping users recall their research history! 🧠 Your capabilities: - Search through all past research sessions - Summarize previous research topics and findings - Help users find specific research they've done before - Connect related research across different sessions When users ask about their research history: 1. Use search_memory to find relevant past research 2. Organize the results chronologically or by topic 3. Provide clear summaries of each research session 4. Highlight key findings and connections between research """ ), tools=[search_memory],)
class Researcher: def __init__(self): self.memori = Memori( database_connect="sqlite:///research_memori.db", conscious_ingest=True, auto_ingest=True, verbose=True, ) self.memori.enable() self.memory_tool = create_memory_tool(self.memori) async def run_agent_with_memory(self, agent, user_input: str): """Run agent and record the conversation in memory.""" # Run the agent result = await Runner.run(agent, input=user_input) # Get the response response_content = ( result.final_output if hasattr(result, "final_output") else str(result) ) # Store in Memori self.memori.record_conversation( user_input=user_input, ai_output=response_content ) return result
import streamlit as stimport asynciost.title("arXiv Research Agent with Memory")# Sidebar: Chat mode selectionwith st.sidebar: chat_mode = st.radio( "Select Chat Mode", ["Research Chat", "Memory Chat"] )user_input = st.chat_input("Ask me to research a topic or query your research history")if user_input: with st.spinner("Thinking..."): researcher = Researcher() # Choose agent based on mode if chat_mode == "Research Chat": result = asyncio.run( researcher.run_agent_with_memory(research_agent, user_input) ) else: result = asyncio.run( researcher.run_agent_with_memory(memory_agent, user_input) ) st.markdown(result.final_output)
# Example 1: New ResearchUser: "Research the latest breakthroughs in quantum computing."Agent:1. Searches memory for previous quantum computing research2. Uses Tavily to find arXiv papers3. Generates comprehensive report4. Saves session to Memori# Example 2: Memory QueryUser: "Summarize my research history on AI ethics."Memory Agent:- Searches all past research sessions- Organizes findings by topic- Provides clear summary with key connections