Skip to content

Commit 211c23f

Browse files
authored
Merge pull request #1 from nisaharan/Research_agent/cli_research
Add CLI example for agent
2 parents fddf107 + 3bf5d97 commit 211c23f

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ The core of the backend is a LangGraph agent defined in `backend/src/agent/graph
7373
4. **Iterative Refinement:** If gaps are found or the information is insufficient, it generates follow-up queries and repeats the web research and reflection steps (up to a configured maximum number of loops).
7474
5. **Finalize Answer:** Once the research is deemed sufficient, the agent synthesizes the gathered information into a coherent answer, including citations from the web sources, using a Gemini model.
7575

76+
## CLI Example
77+
78+
For quick one-off questions you can execute the agent from the command line. The
79+
script `backend/examples/cli_research.py` runs the LangGraph agent and prints the
80+
final answer:
81+
82+
```bash
83+
cd backend
84+
python examples/cli_research.py "What are the latest trends in renewable energy?"
85+
```
86+
87+
7688
## Deployment
7789

7890
In production, the backend server serves the optimized static frontend build. LangGraph requires a Redis instance and a Postgres database. Redis is used as a pub-sub broker to enable streaming real time output from background runs. Postgres is used to store assistants, threads, runs, persist thread state and long term memory, and to manage the state of the background task queue with 'exactly once' semantics. For more details on how to deploy the backend server, take a look at the [LangGraph Documentation](https://langchain-ai.github.io/langgraph/concepts/deployment_options/). Below is an example of how to build a Docker image that includes the optimized frontend build and the backend server and run it via `docker-compose`.

backend/examples/cli_research.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import argparse
2+
from langchain_core.messages import HumanMessage
3+
from agent.graph import graph
4+
5+
6+
def main() -> None:
7+
"""Run the research agent from the command line."""
8+
parser = argparse.ArgumentParser(description="Run the LangGraph research agent")
9+
parser.add_argument("question", help="Research question")
10+
parser.add_argument(
11+
"--initial-queries",
12+
type=int,
13+
default=3,
14+
help="Number of initial search queries",
15+
)
16+
parser.add_argument(
17+
"--max-loops",
18+
type=int,
19+
default=2,
20+
help="Maximum number of research loops",
21+
)
22+
parser.add_argument(
23+
"--reasoning-model",
24+
default="gemini-2.5-pro-preview-05-06",
25+
help="Model for the final answer",
26+
)
27+
args = parser.parse_args()
28+
29+
state = {
30+
"messages": [HumanMessage(content=args.question)],
31+
"initial_search_query_count": args.initial_queries,
32+
"max_research_loops": args.max_loops,
33+
"reasoning_model": args.reasoning_model,
34+
}
35+
36+
result = graph.invoke(state)
37+
messages = result.get("messages", [])
38+
if messages:
39+
print(messages[-1].content)
40+
41+
42+
if __name__ == "__main__":
43+
main()

0 commit comments

Comments
 (0)