From d7c29ffe19f4d8eb2c97413a9b4ac9298632b748 Mon Sep 17 00:00:00 2001 From: vedas-dixit Date: Sat, 17 Jan 2026 17:08:22 +0530 Subject: [PATCH] improvements | added new prompt | refactoring --- agent.py | 52 +++++------------------------ prompts/research_prompt.py | 67 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 5 ++- tools/tools_wrapper.py | 38 +++++++++++++++++++++ 4 files changed, 116 insertions(+), 46 deletions(-) create mode 100644 tools/tools_wrapper.py diff --git a/agent.py b/agent.py index fe83e53..126339f 100644 --- a/agent.py +++ b/agent.py @@ -1,66 +1,32 @@ from langchain_ollama import ChatOllama from langchain.agents import create_agent from langchain_core.runnables import RunnableConfig -from tools.wiki import wiki_search -from tools.math import smart_math -from tools.getNews import asknews_search -from tools.arxiv_tool import arxiv_search -from tools.duckduckgo import duck_duck_go_search, duck_duck_go_search_results -from tools.getDate import get_current_date -from tools.save_md import save_md_locally -from tools.summarize_text import summarize_text -from tools.serpSearch import serp_search -from tools.save_md_plus import save_md_plus -from tools.SearxNG import searx_search -from tools.crossref import crossref_search -from tools.unpaywall import unpaywall_lookup -from tools.europe_pmc import europe_pmc_search -from tools.openlibrary import openlibrary_search -from retriever import add_to_db,query_db -from prompts.research_prompt import KURAMA_RESEARCH_PROMPT_GENERIC, KURAMA_RESEARCH_PROMPT_DEEPRESEARCH +from tools.tools_wrapper import tools +from prompts.research_prompt import KURAMA_RESEARCH_PROMPT_GENERIC, KURAMA_RESEARCH_PROMPT_DEEPRESEARCH,KURAMA_RESEARCH_PROMPT from dotenv import load_dotenv -import os from utils.spinner import Spinner from utils.markdown_render import render_markdown from langgraph.errors import GraphRecursionError from pyfiglet import Figlet def main(): + + load_dotenv() f = Figlet(font='standard') print(f.renderText('Kurama v 1.3')) x = input("Ask Kurama 🦊\n") - load_dotenv() - llm = ChatOllama(model="gpt-oss:120b-cloud", temperature=0.7) - recursion_limit = 100 + llm = ChatOllama(model="gpt-oss:120b-cloud", temperature=0.7,verbose=True) + recursion_limit = 50 config = RunnableConfig(tags=["debug", "local"], recursion_limit=recursion_limit) agent = create_agent( model=llm, - tools=[ - wiki_search, - smart_math, - duck_duck_go_search, - duck_duck_go_search_results, - searx_search, - add_to_db, - query_db, - asknews_search, - serp_search, - arxiv_search, - crossref_search, - unpaywall_lookup, - europe_pmc_search, - openlibrary_search, - get_current_date, - save_md_locally, - save_md_plus, - summarize_text, - ], - system_prompt=KURAMA_RESEARCH_PROMPT_GENERIC + tools=tools, + system_prompt=KURAMA_RESEARCH_PROMPT ) result = None - MAX_RECURSION_LIMIT = 1000 + MAX_RECURSION_LIMIT = 100 while True: s = Spinner("Reasoning | Choosing tools | Gathering info") s.start() diff --git a/prompts/research_prompt.py b/prompts/research_prompt.py index 1d5cf03..c175411 100644 --- a/prompts/research_prompt.py +++ b/prompts/research_prompt.py @@ -239,4 +239,71 @@ You are Kurama Research Agent in **Deep Mode**. Your purpose is to produce **multi-page, publication-grade Markdown research reports**, saving each section progressively while maintaining local, persistent knowledge across sessions. +""" + + +Tools = """ +# Role +You are **Kurama Research Agent v1.3**, an autonomous research assistant built by Vedas Dixit. + +Below are strict rules for you to follow: +Do's: +-> Internal reason before taking action +-> never process sensitive request that makes you search any negative things and abuse tool calling in terms of. "*add thinhs herr" +-> +### Tools & When to Use Them +| Tool | Primary Use | Notes | +|------|-------------|-------| +| **query_db(query: str, top_k: int = 3)** | **Always run first** to recover prior facts. | If confidence ≥ “good enough”, avoid external search. | +| **add_to_db(text: str, metadata: dict = None)** | Store only verified, source-attributed insights. | No raw dumps; store distilled facts. | +| **wiki_search(query)** | Definitions, background, stable facts. | Prefer for non-time-sensitive info. | +| **duck_duck_go_search(query: str) -> str** | General web discovery, broad coverage. | Use if you need diverse sources. | +| **duck_duck_go_search_results(query: str) -> str** | Get multiple URLs for triangulation. | Use when you need citations. | +| **serp_search(query: str) -> str** | **Targeted Google-quality lookup** for specific gaps. | **Use sparingly**: only if a precise fact is missing or verification is required and other tools failed. | +| **asknews_search(query)** | News/events within last 6–12 months. | Prefer for timely topics. | +| **arxiv_search(query: str) -> str** | Scientific/technical sources. | Use for papers, methods, benchmarks. | +| **crossref_search(query: str) -> str** | Scholarly metadata by topic/keywords. | Use to discover DOIs, titles, years, and links. | +| **unpaywall_lookup(doi_and_email: str) -> str** | Find open-access links for a DOI. | Requires email inline (email=you@x.com) or env UNPAYWALL_EMAIL. | +| **europe_pmc_search(query: str) -> str** | Biomedical and life-science literature. | Use for bio/medical topics; returns IDs and links. | +| **openlibrary_search(query: str) -> str** | Books and editions. | Use for books/authors/editions metadata. | +| **smart_math(expression: str) -> float** | Numeric/logic. | Never guess numbers. | +| **get_current_date()** | Freshness checks. | Verify year before calling something “latest”. | +| **save_md_locally(content: str, filename: str = None) -> str** | Save concise or single-phase research reports. | **Mandatory** for every research session. Called after synthesis or summarization. | +| **save_md_plus(content: str, filename: str = None) -> str** | Progressive save tool for **detailed or comprehensive research**. | Use **only if** the user explicitly requests “detailed”, “in-depth”, “long-form”, “comprehensive”, “thesis-like”, or “step-by-step” research. Append each phase iteratively to build a long Markdown document. | +| **summarize_text(text: str) -> str** | Compress long sources. | Use before saving or adding to DB. | +| **searx_search(query)** | Privacy-respecting web search via SearxNG. | Use if you need a different perspective or if other search tools are insufficient. | +--- +""" + + +KURAMA_RESEARCH_PROMPT = """ +You are Kurama Research Agent v1.3. +You behave like a disciplined research analyst. +You prioritize correctness, verification, and traceability. + +## Mandatory Decision Step +Classify the request into exactly ONE category: +MEMORY_LOOKUP | TIME_SENSITIVE | ACADEMIC | GENERAL_BACKGROUND | +NUMERIC | BOOK | NEWS | SYNTHESIS_ONLY + +Follow the strict tool routing map. +Do not skip steps. + +## Database Rules +Always call query_db first. +Assign confidence: HIGH / MEDIUM / LOW. +HIGH → no search allowed. +MEDIUM → one search tool allowed. +LOW → full routing. + +## Tool Discipline +Never guess facts or numbers. +Never use serp_search unless other tools failed. +Never store raw data. + +## Persistence +End every session with save_md_locally. +Use save_md_plus only for explicit long-form research. +Store only distilled, verified insights in add_to_db. +--- """ \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index bd74aae..02ec9d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,12 +3,10 @@ langchain-core>=0.3.0 langchain-community>=0.3.0 langchain-ollama>=0.1.0 langgraph>=0.1.0 - duckduckgo-search>=6.3.0 ddgs>=1.1.6 wikipedia>=1.4.0 requests>=2.31.0 - chromadb>=0.5.5 python-dotenv>=1.0.1 pydantic>=2.8.2 @@ -18,4 +16,5 @@ arxiv>=2.2.0 sympy>=1.12 rich>=13.7.1 pytest>=7.4.0 -pyfiglet>=1.0.4 \ No newline at end of file +pyfiglet>=1.0.4 +google-search-results \ No newline at end of file diff --git a/tools/tools_wrapper.py b/tools/tools_wrapper.py new file mode 100644 index 0000000..18608b6 --- /dev/null +++ b/tools/tools_wrapper.py @@ -0,0 +1,38 @@ +from tools.wiki import wiki_search +from tools.math import smart_math +from tools.getNews import asknews_search +from tools.arxiv_tool import arxiv_search +from tools.duckduckgo import duck_duck_go_search, duck_duck_go_search_results +from tools.getDate import get_current_date +from tools.save_md import save_md_locally +from tools.summarize_text import summarize_text +from tools.serpSearch import serp_search +from tools.save_md_plus import save_md_plus +from tools.SearxNG import searx_search +from tools.crossref import crossref_search +from tools.unpaywall import unpaywall_lookup +from tools.europe_pmc import europe_pmc_search +from tools.openlibrary import openlibrary_search +from retriever import add_to_db,query_db + + +tools=[ + wiki_search, + smart_math, + duck_duck_go_search, + duck_duck_go_search_results, + searx_search, + add_to_db, + query_db, + asknews_search, + serp_search, + arxiv_search, + crossref_search, + unpaywall_lookup, + europe_pmc_search, + openlibrary_search, + get_current_date, + save_md_locally, + save_md_plus, + summarize_text + ] \ No newline at end of file