Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 31 additions & 30 deletions backend/examples/cli_research.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
import argparse
from langchain_core.messages import HumanMessage
import asyncio
import os
from dotenv import load_dotenv
from agent.graph import graph

load_dotenv()

def main() -> None:
"""Run the research agent from the command line."""
parser = argparse.ArgumentParser(description="Run the LangGraph research agent")
parser.add_argument("question", help="Research question")
async def main():
# Setup command line arguments
parser = argparse.ArgumentParser(description="Local Research CLI")
parser.add_argument("topic", help="The topic to research")
parser.add_argument(
"--initial-queries",
type=int,
default=3,
help="Number of initial search queries",
)
parser.add_argument(
"--max-loops",
type=int,
default=2,
help="Maximum number of research loops",
)
parser.add_argument(
"--reasoning-model",
default="gemini-2.5-pro-preview-05-06",
help="Model for the final answer",
"--dir",
required=True,
help="Path to the local directory containing .md files for research"
)
Comment on lines +13 to +17

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The formatting for this add_argument call is inconsistent with the others in this file and not well-aligned. For improved readability and consistency, please format it as a single line, similar to the other arguments.

    parser.add_argument("--dir", type=str, help="Directory to search in", default=None)

args = parser.parse_args()

state = {
"messages": [HumanMessage(content=args.question)],
"initial_search_query_count": args.initial_queries,
"max_research_loops": args.max_loops,
"reasoning_model": args.reasoning_model,
# Configure the graph with the local search directory
config = {
"configurable": {
"search_dir": args.dir,
"max_research_loops": 2 # Efficient looping for documentation analysis
}
}

result = graph.invoke(state)
messages = result.get("messages", [])
if messages:
print(messages[-1].content)
# Initialize the research with the user's topic
inputs = {"messages": [("user", args.topic)]}

print(f"Starting research in: {args.dir}")
print("-" * 30)

# Stream the results from the graph
async for event in graph.astream(inputs, config=config, stream_mode="values"):
message = event.get("messages")
if message:
if isinstance(message, list):
print(message[-1].content)
else:
print(message.content)

if __name__ == "__main__":
main()
asyncio.run(main())
3 changes: 1 addition & 2 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ requires-python = ">=3.11,<4.0"
dependencies = [
"langgraph>=0.2.6",
"langchain>=0.3.19",
"langchain-google-genai",
"langchain-groq",
"python-dotenv>=1.0.1",
"langgraph-sdk>=0.1.57",
"langgraph-cli",
"langgraph-api",
"fastapi",
"google-genai",
]


Expand Down
Loading